2 class ChangesetCommentsController < ApplicationController
3 skip_before_action :verify_authenticity_token
4 before_action :authorize
5 before_action :api_deny_access_handler
9 before_action :require_public_data, :only => [:create]
10 before_action :check_api_writable
11 before_action :check_api_readable, :except => [:create]
12 around_action :api_call_handle_error
13 around_action :api_call_timeout
16 # Add a comment to a changeset
18 # Check the arguments are sane
19 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
20 raise OSM::APIBadUserInput, "No text was given" if params[:text].blank?
22 # Extract the arguments
26 # Find the changeset and check it is valid
27 changeset = Changeset.find(id)
28 raise OSM::APIChangesetNotYetClosedError, changeset if changeset.is_open?
30 # Add a comment to the changeset
31 comment = changeset.comments.create(:changeset => changeset,
33 :author => current_user)
35 # Notify current subscribers of the new comment
36 changeset.subscribers.visible.each do |user|
37 Notifier.changeset_comment_notification(comment, user).deliver_later if current_user != user
40 # Add the commenter to the subscribers if necessary
41 changeset.subscribers << current_user unless changeset.subscribers.exists?(current_user.id)
43 # Return a copy of the updated changeset
44 render :xml => changeset.to_xml.to_s
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 render :xml => comment.changeset.to_xml.to_s
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 render :xml => comment.changeset.to_xml.to_s