2 class ChangesetCommentsController < ApiController
3 before_action :authorize
4 before_action :api_deny_access_handler
8 before_action :require_public_data, :only => [:create]
9 before_action :check_api_writable
10 before_action :check_api_readable, :except => [:create]
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.is_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 Notifier.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"
48 # Sets visible flag on comment to false
50 # Check the arguments are sane
51 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
53 # Extract the arguments
57 comment = ChangesetComment.find(id)
60 comment.update(:visible => false)
62 # Return a copy of the updated changeset
63 @changeset = comment.changeset
64 render "api/changesets/changeset"
68 # Sets visible flag on comment to true
70 # Check the arguments are sane
71 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
73 # Extract the arguments
77 comment = ChangesetComment.find(id)
80 comment.update(:visible => true)
82 # Return a copy of the updated changeset
83 @changeset = comment.changeset
84 render "api/changesets/changeset"