2 class ChangesetCommentsController < ApiController
3 before_action :check_api_writable
4 before_action :check_api_readable, :except => [:create]
5 before_action :authorize
9 before_action :require_public_data, :only => [:create]
10 before_action :set_request_formats
11 around_action :api_call_handle_error
12 around_action :api_call_timeout
15 # Add a comment to a changeset
17 # Check the arguments are sane
18 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
19 raise OSM::APIBadUserInput, "No text was given" if params[:text].blank?
21 # Extract the arguments
25 # Find the changeset and check it is valid
26 changeset = Changeset.find(id)
27 raise OSM::APIChangesetNotYetClosedError, changeset if changeset.open?
29 # Add a comment to the changeset
30 comment = changeset.comments.create(:changeset => changeset,
32 :author => current_user)
34 # Notify current subscribers of the new comment
35 changeset.subscribers.visible.each do |user|
36 UserMailer.changeset_comment_notification(comment, user).deliver_later if current_user != user
39 # Add the commenter to the subscribers if necessary
40 changeset.subscribers << current_user unless changeset.subscribers.exists?(current_user.id)
42 # Return a copy of the updated changeset
43 @changeset = changeset
44 render "api/changesets/changeset"
46 respond_to do |format|
53 # Sets visible flag on comment to false
55 # Check the arguments are sane
56 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
58 # Extract the arguments
62 comment = ChangesetComment.find(id)
65 comment.update(:visible => false)
67 # Return a copy of the updated changeset
68 @changeset = comment.changeset
69 render "api/changesets/changeset"
71 respond_to do |format|
78 # Sets visible flag on comment to true
80 # Check the arguments are sane
81 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
83 # Extract the arguments
87 comment = ChangesetComment.find(id)
90 comment.update(:visible => true)
92 # Return a copy of the updated changeset
93 @changeset = comment.changeset
94 render "api/changesets/changeset"
96 respond_to do |format|