]> git.openstreetmap.org Git - rails.git/blob - app/controllers/changeset_comments_controller.rb
Merge remote-tracking branch 'upstream/pull/2248'
[rails.git] / app / controllers / changeset_comments_controller.rb
1 class ChangesetCommentsController < ApplicationController
2   before_action :authorize_web
3   before_action :set_locale
4
5   authorize_resource
6
7   before_action -> { check_database_readable(true) }
8   around_action :web_timeout
9
10   ##
11   # Get a feed of recent changeset comments
12   def index
13     if params[:id]
14       # Extract the arguments
15       id = params[:id].to_i
16
17       # Find the changeset
18       changeset = Changeset.find(id)
19
20       # Return comments for this changeset only
21       @comments = changeset.comments.includes(:author, :changeset).limit(comments_limit)
22     else
23       # Return comments
24       @comments = ChangesetComment.includes(:author, :changeset).where(:visible => true).order("created_at DESC").limit(comments_limit).preload(:changeset)
25     end
26
27     # Render the result
28     respond_to do |format|
29       format.rss
30     end
31   rescue OSM::APIBadUserInput
32     head :bad_request
33   end
34
35   private
36
37   ##
38   # Get the maximum number of comments to return
39   def comments_limit
40     if params[:limit]
41       if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
42         params[:limit].to_i
43       else
44         raise OSM::APIBadUserInput, "Comments limit must be between 1 and 10000"
45       end
46     else
47       100
48     end
49   end
50 end