]> git.openstreetmap.org Git - rails.git/blob - app/controllers/notes_controller.rb
Merge remote-tracking branch 'upstream/pull/4776'
[rails.git] / app / controllers / notes_controller.rb
1 class NotesController < ApplicationController
2   include UserMethods
3
4   layout :map_layout
5
6   before_action :check_api_readable
7   before_action :authorize_web
8   before_action :require_oauth
9
10   authorize_resource
11
12   before_action :lookup_user, :only => [:index]
13   before_action :set_locale
14   around_action :web_timeout
15
16   ##
17   # Display a list of notes by a specified user
18   def index
19     @params = params.permit(:display_name)
20     @title = t ".title", :user => @user.display_name
21     @page = (params[:page] || 1).to_i
22     @page_size = 10
23     @notes = @user.notes
24     @notes = @notes.visible unless current_user&.moderator?
25     @notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author)
26
27     render :layout => "site"
28   end
29
30   def show
31     @type = "note"
32
33     if current_user&.moderator?
34       @note = Note.find(params[:id])
35       @note_comments = @note.comments.unscope(:where => :visible)
36     else
37       @note = Note.visible.find(params[:id])
38       @note_comments = @note.comments
39     end
40   rescue ActiveRecord::RecordNotFound
41     render :template => "browse/not_found", :status => :not_found
42   end
43
44   def new; end
45 end