Hack around dubious error usage

pull/2598/head
Alexander Bach 10 years ago
parent e6370cc0a1
commit 0805e94b37
  1. 2
      config/locales/de.yml
  2. 4
      config/locales/en.yml
  3. 2
      lib/api/errors/error_base.rb
  4. 13
      lib/api/errors/unwritable_property.rb
  5. 19
      lib/api/v3/work_packages/work_package_contract.rb
  6. 4
      spec/requests/api/v3/work_package_resource_spec.rb

@ -1700,6 +1700,6 @@ de:
invalid_user_assigned_to_work_package:
"Der gewählte Nutzer darf dem Arbeitspaket nicht als '%{property}' zugewiesen werden."
estimated_hours: "Der geschätzte Aufwand kann für Eltern-Arbeitspakete nicht gesetzt werden."
done_ratio: "Der Fortschritt von Eltern-Arbeitspaketen kann nicht gesetzt werden."
done_ratio: "Der Fortschritt kann nicht gesetzt werden falls es sich um ein Eltern-Arbeitspaket handelt, er durch den Status definiert wird oder wenn er komplett deaktiviert wurde."
resources:
schema: 'Schema'

@ -1690,8 +1690,6 @@ en:
invalid_user_assigned_to_work_package:
"The chosen user is not allowed to be '%{property}' for this work package."
estimated_hours: "Estimated hours cannot be set on parent work packages."
done_ratio_readonly_parent: "Done ratio cannot be set on parent work packages."
done_ratio_readonly_status: "Done ratio cannot be set when it is inferred by status."
done_ratio_disabled: "Done ratio cannot be set when it is disabled."
done_ratio: "Done ratio cannot be set on parent work packages, when it is inferred by status or when it is disabled."
resources:
schema: 'Schema'

@ -43,7 +43,7 @@ module API
when :error_conflict
return ::API::Errors::Conflict
when :error_readonly
return ::API::Errors::UnwritableProperty.new(errors[key])
return ::API::Errors::UnwritableProperty.new(errors[key].flatten)
end
end
end

@ -36,7 +36,14 @@ module API
fail ArgumentError, 'UnwritableProperty error must contain at least one invalid attribute!' if attributes.empty?
if attributes.length == 1
message = I18n.t('api_v3.errors.writing_read_only_attributes')
message = case attributes.first
when 'estimated_hours'
I18n.t('api_v3.errors.validation.estimated_hours')
when 'done_ratio'
I18n.t('api_v3.errors.validation.done_ratio')
else
I18n.t('api_v3.errors.writing_read_only_attributes')
end
else
message = I18n.t('api_v3.errors.multiple_errors')
end
@ -48,8 +55,8 @@ module API
def evaluate_attributes(attributes, invalid_attributes)
if attributes.length > 1
invalid_attributes.each do |error|
@errors << UnwritableProperty.new(error)
invalid_attributes.each do |attribute|
@errors << UnwritableProperty.new(attribute)
end
else
@details = { attribute: attributes[0].to_s.camelize(:lower) }

@ -102,9 +102,7 @@ module API
def readonly_attributes_unchanged
changed_attributes = model.changed - self.class.writable_attributes
changed_attributes.each do |attribute|
errors.add attribute.to_sym, I18n.t('api_v3.errors.writing_read_only_attributes')
end unless changed_attributes.empty?
errors.add :error_readonly, changed_attributes unless changed_attributes.empty?
end
def assignee_visible
@ -117,20 +115,19 @@ module API
def estimated_hours_valid
if !model.leaf? && model.changed.include?('estimated_hours')
errors.add :estimated_time, I18n.t('api_v3.errors.validation.estimated_hours')
errors.add :error_readonly, 'estimated_hours'
end
end
def done_ratio_valid
if model.changed.include?('done_ratio')
# TODO Allow multiple errors as soon as they have separate messages
if !model.leaf?
errors.add :done_ratio, I18n.t('api_v3.errors.validation.done_ratio_readonly_parent')
end
if Setting.work_package_done_ratio == 'status'
errors.add :done_ratio, I18n.t('api_v3.errors.validation.done_ratio_readonly_status')
end
if Setting.work_package_done_ratio == 'disabled'
errors.add :done_ratio, I18n.t('api_v3.errors.validation.done_ratio_disabled')
errors.add :error_readonly, 'done_ratio'
elsif Setting.work_package_done_ratio == 'status'
errors.add :error_readonly, 'done_ratio'
elsif Setting.work_package_done_ratio == 'disabled'
errors.add :error_readonly, 'done_ratio'
end
end
end

@ -763,7 +763,7 @@ h4. things we like
it_behaves_like 'multiple errors', 422
it_behaves_like 'multiple errors of the same type', 2, 'PropertyIsReadOnly'
it_behaves_like 'multiple errors of the same type', 2, 'PropertyConstraintViolation'
it_behaves_like 'multiple errors of the same type with messages' do
let(:message) { ['Subject can\'t be blank.', 'Parent does not exist.'] }
@ -811,7 +811,7 @@ h4. things we like
it_behaves_like 'multiple errors', 422, 'Multiple fields violated their constraints.'
it_behaves_like 'multiple errors of the same type', 2, 'PropertyIsReadOnly'
it_behaves_like 'multiple errors of the same type', 2, 'PropertyConstraintViolation'
it_behaves_like 'multiple errors of the same type with messages' do
let(:message) {

Loading…
Cancel
Save