]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/changeset_subscriptions_controller.rb
Merge remote-tracking branch 'upstream/pull/5805'
[rails.git] / app / controllers / api / changeset_subscriptions_controller.rb
1 module Api
2   class ChangesetSubscriptionsController < ApiController
3     before_action :check_api_writable
4     before_action :authorize
5
6     authorize_resource
7
8     before_action :require_public_data
9     before_action :set_request_formats
10
11     ##
12     # Adds a subscriber to the changeset
13     def create
14       # Check the arguments are sane
15       raise OSM::APIBadUserInput, "No id was given" unless params[:changeset_id]
16
17       # Extract the arguments
18       changeset_id = params[:changeset_id].to_i
19
20       # Find the changeset and check it is valid
21       @changeset = Changeset.find(changeset_id)
22       raise OSM::APIChangesetAlreadySubscribedError, @changeset if @changeset.subscribers.include?(current_user)
23
24       # Add the subscriber
25       @changeset.subscribers << current_user
26
27       respond_to do |format|
28         format.xml
29         format.json
30       end
31     end
32
33     ##
34     # Removes a subscriber from the changeset
35     def destroy
36       # Check the arguments are sane
37       raise OSM::APIBadUserInput, "No id was given" unless params[:changeset_id]
38
39       # Extract the arguments
40       changeset_id = params[:changeset_id].to_i
41
42       # Find the changeset and check it is valid
43       @changeset = Changeset.find(changeset_id)
44       raise OSM::APIChangesetNotSubscribedError, @changeset unless @changeset.subscribers.include?(current_user)
45
46       # Remove the subscriber
47       @changeset.subscribers.delete(current_user)
48
49       respond_to do |format|
50         format.xml
51         format.json
52       end
53     end
54   end
55 end