X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/783528830ad1b0d5f07c8e758747841a0b4e5cc6..fddf6fb5299285b55aa7357c7e3052d591d462b2:/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