2 class ChangesetCommentsController < ApiController
3 before_action :authorize
7 before_action :require_public_data, :only => [:create]
8 before_action :check_api_writable
9 before_action :check_api_readable, :except => [:create]
10 around_action :api_call_handle_error
11 around_action :api_call_timeout
14 # Add a comment to a changeset
16 # Check the arguments are sane
17 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
18 raise OSM::APIBadUserInput, "No text was given" if params[:text].blank?
20 # Extract the arguments
24 # Find the changeset and check it is valid
25 changeset = Changeset.find(id)
26 raise OSM::APIChangesetNotYetClosedError, changeset if changeset.is_open?
28 # Add a comment to the changeset
29 comment = changeset.comments.create(:changeset => changeset,
31 :author => current_user)
33 # Notify current subscribers of the new comment
34 changeset.subscribers.visible.each do |user|
35 UserMailer.changeset_comment_notification(comment, user).deliver_later if current_user != user
38 # Add the commenter to the subscribers if necessary
39 changeset.subscribers << current_user unless changeset.subscribers.exists?(current_user.id)
41 # Return a copy of the updated changeset
42 @changeset = changeset
43 render "api/changesets/changeset"
47 # Sets visible flag on comment to false
49 # Check the arguments are sane
50 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
52 # Extract the arguments
56 comment = ChangesetComment.find(id)
59 comment.update(:visible => false)
61 # Return a copy of the updated changeset
62 @changeset = comment.changeset
63 render "api/changesets/changeset"
67 # Sets visible flag on comment to true
69 # Check the arguments are sane
70 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
72 # Extract the arguments
76 comment = ChangesetComment.find(id)
79 comment.update(:visible => true)
81 # Return a copy of the updated changeset
82 @changeset = comment.changeset
83 render "api/changesets/changeset"