fix bogus errors in contracts

- AR tried to read properties that are undefined on the contract (:error_read_only)
- now that we actually use Contract properties the copy-validations stuff started to do things, however:
    - we already went another path to simultaneously validate contract + model
    - validation was apparently broken, e.g. though the subject was not empty, there were subject :blank errors
pull/3166/head
Jan Sandbrink 9 years ago
parent c586a9cc8c
commit 3e87d10980
  1. 11
      lib/api/contracts/model_contract.rb
  2. 3
      lib/api/v3/work_packages/base_contract.rb

@ -52,6 +52,17 @@ module API
end
end
# we want to add a validation error whenever someone sets a property that we don't know.
# However AR will cleverly try to resolve the value for errorneous properties. Thus we need
# to hook into this method and return nil for unknown properties to avoid NoMethod errors...
def read_attribute_for_validation(attribute)
if respond_to? attribute
send attribute
end
nil
end
def writable_attributes
collect_ancestor_attributes(:writable_attributes)
end

@ -97,9 +97,6 @@ module API
@can = WorkPackagePolicy.new(user)
end
extend Reform::Form::ActiveModel::ModelValidations
copy_validations_from WorkPackage
private
def validate_people_visible(attribute, id_attribute, list)

Loading…
Cancel
Save