[33678] Priority needs to be a require field

Priority was marked non-required for it to turn up in the
attribute form configuration.

But priority _is actually required_. This results in the frontend adding
an optional placeholder `-` value, which makes the resource unsavable.

This commit adds priority to the form, but keeps it required as it
should be.

https://community.openproject.com/wp/33678
pull/8503/head
Oliver Günther 4 years ago
parent 38e913cb00
commit 2feaec1101
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 12
      app/models/type/attributes.rb
  2. 2
      lib/api/v3/work_packages/schema/work_package_schema_representer.rb
  3. 4
      spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb

@ -111,12 +111,20 @@ module Type::Attributes
# * directly in other envs, e.g. test
definitions = representable_config.key?(:definitions) ? representable_config[:definitions] : representable_config
skip = %w[_type _dependencies attribute_groups links parent_id parent description schedule_manually]
definitions.keys
.reject { |key| skip.include?(key) || definitions[key][:required] }
.reject { |key| skipped_attribute?(key, definitions[key]) }
.map { |key| [key, JSON::parse(definitions[key].to_json)] }.to_h
end
def skipped_attribute?(key, definition)
# We always want to include the priority even if its required
return false if key == 'priority'
skip = %w[_type _dependencies attribute_groups links parent_id parent description schedule_manually]
skip.include?(key) || definition[:required]
end
def merge_date_for_form_attributes(attributes)
attributes['date'] = { required: false, has_default: false }
attributes.delete 'due_date'

@ -253,7 +253,7 @@ module API
title: priority.name
}
},
required: false,
required: true,
has_default: true
def attribute_groups

@ -745,7 +745,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
let(:path) { 'priority' }
let(:type) { 'Priority' }
let(:name) { I18n.t('activerecord.attributes.work_package.priority') }
let(:required) { false }
let(:required) { true }
let(:writable) { true }
let(:has_default) { true }
end
@ -765,7 +765,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
let(:path) { 'priority' }
let(:type) { 'Priority' }
let(:name) { I18n.t('activerecord.attributes.work_package.priority') }
let(:required) { false }
let(:required) { true }
let(:writable) { false }
let(:has_default) { true }
end

Loading…
Cancel
Save