class ChangesetsController < ApiController
include QueryMethods
- before_action :check_api_writable, :only => [:create, :update, :upload, :subscribe, :unsubscribe]
+ before_action :check_api_writable, :only => [:create, :update]
before_action :setup_user_auth, :only => [:show]
- before_action :authorize, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe]
+ before_action :authorize, :only => [:create, :update]
authorize_resource
- before_action :require_public_data, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe]
- before_action :set_request_formats, :except => [:create, :close, :upload]
-
- skip_around_action :api_call_timeout, :only => [:upload]
+ before_action :require_public_data, :only => [:create, :update]
+ before_action :set_request_formats, :except => [:create]
# Helper methods for checking consistency
include ConsistencyValidations
cs.save_with_tags!
# Subscribe user to changeset comments
- cs.subscribe(current_user)
+ cs.subscribers << current_user
render :plain => cs.id.to_s
end
- ##
- # marks a changeset as closed. this may be called multiple times
- # on the same changeset, so is idempotent.
- def close
- changeset = Changeset.find(params[:id])
- check_changeset_consistency(changeset, current_user)
-
- # to close the changeset, we'll just set its closed_at time to
- # now. this might not be enough if there are concurrency issues,
- # but we'll have to wait and see.
- changeset.set_closed_time_now
-
- changeset.save!
- head :ok
- end
-
- ##
- # Upload a diff in a single transaction.
- #
- # This means that each change within the diff must succeed, i.e: that
- # each version number mentioned is still current. Otherwise the entire
- # transaction *must* be rolled back.
- #
- # Furthermore, each element in the diff can only reference the current
- # changeset.
- #
- # Returns: a diffResult document, as described in
- # http://wiki.openstreetmap.org/wiki/OSM_Protocol_Version_0.6
- def upload
- changeset = Changeset.find(params[:id])
- check_changeset_consistency(changeset, current_user)
-
- diff_reader = DiffReader.new(request.raw_post, changeset)
- Changeset.transaction do
- result = diff_reader.commit
- # the number of changes in this changeset has already been
- # updated and is visible in this transaction so we don't need
- # to allow for any more when checking the limit
- check_rate_limit(0)
- render :xml => result.to_s
- end
- end
-
##
# updates a changeset's tags. none of the changeset's attributes are
# user-modifiable, so they will be ignored.
end
end
- ##
- # Adds a subscriber to the changeset
- def subscribe
- # Check the arguments are sane
- raise OSM::APIBadUserInput, "No id was given" unless params[:id]
-
- # Extract the arguments
- id = params[:id].to_i
-
- # Find the changeset and check it is valid
- changeset = Changeset.find(id)
- raise OSM::APIChangesetAlreadySubscribedError, changeset if changeset.subscribed?(current_user)
-
- # Add the subscriber
- changeset.subscribe(current_user)
-
- # Return a copy of the updated changeset
- @changeset = changeset
- render "show"
-
- respond_to do |format|
- format.xml
- format.json
- end
- end
-
- ##
- # Removes a subscriber from the changeset
- def unsubscribe
- # Check the arguments are sane
- raise OSM::APIBadUserInput, "No id was given" unless params[:id]
-
- # Extract the arguments
- id = params[:id].to_i
-
- # Find the changeset and check it is valid
- changeset = Changeset.find(id)
- raise OSM::APIChangesetNotSubscribedError, changeset unless changeset.subscribed?(current_user)
-
- # Remove the subscriber
- changeset.unsubscribe(current_user)
-
- # Return a copy of the updated changeset
- @changeset = changeset
- render "show"
-
- respond_to do |format|
- format.xml
- format.json
- end
- end
-
private
#------------------------------------------------------------