X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/783528830ad1b0d5f07c8e758747841a0b4e5cc6..c54471ee33f79b7119eb284b03a845813a058876:/lib/consistency_validations.rb diff --git a/lib/consistency_validations.rb b/lib/consistency_validations.rb index 46fb3c06e..4f3881542 100644 --- a/lib/consistency_validations.rb +++ b/lib/consistency_validations.rb @@ -27,4 +27,19 @@ module ConsistencyValidations raise OSM::APIChangesetAlreadyClosedError.new(new.changeset) end end + + ## + # subset of consistency checks which should be applied to almost + # all the changeset controller's writable methods. + def check_changeset_consistency(changeset, user) + # check user credentials - only the user who opened a changeset + # may alter it. + if changeset.nil? + raise OSM::APIChangesetMissingError.new + elsif user.id != changeset.user_id + raise OSM::APIUserChangesetMismatchError.new + elsif not changeset.is_open? + raise OSM::APIChangesetAlreadyClosedError.new(changeset) + end + end end