1 class ChangesetCommentsController < ApplicationController
2 skip_before_action :verify_authenticity_token, :except => [:index]
3 before_action :authorize_web, :only => [:index]
4 before_action :set_locale, :only => [:index]
5 before_action :authorize, :only => [:create, :destroy, :restore]
6 before_action :api_deny_access_handler, :only => [:create, :destroy, :restore]
10 before_action :require_public_data, :only => [:create]
11 before_action :check_api_writable, :only => [:create, :destroy, :restore]
12 before_action :check_api_readable, :except => [:create, :index]
13 before_action(:only => [:index]) { |c| c.check_database_readable(true) }
14 around_action :api_call_handle_error, :except => [:index]
15 around_action :api_call_timeout, :except => [:index]
16 around_action :web_timeout, :only => [:index]
19 # Add a comment to a changeset
21 # Check the arguments are sane
22 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
23 raise OSM::APIBadUserInput, "No text was given" if params[:text].blank?
25 # Extract the arguments
29 # Find the changeset and check it is valid
30 changeset = Changeset.find(id)
31 raise OSM::APIChangesetNotYetClosedError, changeset if changeset.is_open?
33 # Add a comment to the changeset
34 comment = changeset.comments.create(:changeset => changeset,
36 :author => current_user)
38 # Notify current subscribers of the new comment
39 changeset.subscribers.visible.each do |user|
40 Notifier.changeset_comment_notification(comment, user).deliver_later if current_user != user
43 # Add the commenter to the subscribers if necessary
44 changeset.subscribers << current_user unless changeset.subscribers.exists?(current_user.id)
46 # Return a copy of the updated changeset
47 render :xml => changeset.to_xml.to_s
51 # Sets visible flag on comment to false
53 # Check the arguments are sane
54 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
56 # Extract the arguments
60 comment = ChangesetComment.find(id)
63 comment.update(:visible => false)
65 # Return a copy of the updated changeset
66 render :xml => comment.changeset.to_xml.to_s
70 # Sets visible flag on comment to true
72 # Check the arguments are sane
73 raise OSM::APIBadUserInput, "No id was given" unless params[:id]
75 # Extract the arguments
79 comment = ChangesetComment.find(id)
82 comment.update(:visible => true)
84 # Return a copy of the updated changeset
85 render :xml => comment.changeset.to_xml.to_s
89 # Get a feed of recent changeset comments
92 # Extract the arguments
96 changeset = Changeset.find(id)
98 # Return comments for this changeset only
99 @comments = changeset.comments.includes(:author, :changeset).limit(comments_limit)
102 @comments = ChangesetComment.includes(:author, :changeset).where(:visible => true).order("created_at DESC").limit(comments_limit).preload(:changeset)
106 respond_to do |format|
109 rescue OSM::APIBadUserInput
116 # Get the maximum number of comments to return
119 if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
122 raise OSM::APIBadUserInput, "Comments limit must be between 1 and 10000"