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