]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/changeset_comments/visibilities_controller.rb
Create api changeset comment visibility resource
[rails.git] / app / controllers / api / changeset_comments / visibilities_controller.rb
1 module Api
2   module ChangesetComments
3     class VisibilitiesController < ApiController
4       before_action :check_api_writable
5       before_action :authorize
6
7       authorize_resource :class => :changeset_comment_visibility
8
9       before_action :set_request_formats
10
11       ##
12       # Sets visible flag on comment to true
13       def create
14         # Check the arguments are sane
15         raise OSM::APIBadUserInput, "No id was given" unless params[:changeset_comment_id]
16
17         # Extract the arguments
18         changeset_comment_id = params[:changeset_comment_id].to_i
19
20         # Find the changeset
21         comment = ChangesetComment.find(changeset_comment_id)
22
23         # Unhide the comment
24         comment.update(:visible => true)
25
26         # Return a copy of the updated changeset
27         @changeset = comment.changeset
28
29         respond_to do |format|
30           format.xml
31           format.json
32         end
33       end
34
35       ##
36       # Sets visible flag on comment to false
37       def destroy
38         # Check the arguments are sane
39         raise OSM::APIBadUserInput, "No id was given" unless params[:changeset_comment_id]
40
41         # Extract the arguments
42         changeset_comment_id = params[:changeset_comment_id].to_i
43
44         # Find the changeset
45         comment = ChangesetComment.find(changeset_comment_id)
46
47         # Hide the comment
48         comment.update(:visible => false)
49
50         # Return a copy of the updated changeset
51         @changeset = comment.changeset
52
53         respond_to do |format|
54           format.xml
55           format.json
56         end
57       end
58     end
59   end
60 end