1 class NotesController < ApplicationController
 
   6   before_action :check_api_readable
 
   7   before_action :authorize_web
 
   8   before_action :set_locale
 
   9   before_action :require_oauth
 
  13   before_action :lookup_user, :only => [:index]
 
  14   around_action :web_timeout
 
  17   # Display a list of notes by a specified user
 
  19     param! :page, Integer, :min => 1
 
  21     @params = params.permit(:display_name, :status)
 
  22     @title = t ".title", :user => @user.display_name
 
  23     @page = (params[:page] || 1).to_i
 
  26     @notes = @notes.visible unless current_user&.moderator?
 
  27     @notes = @notes.where(:status => params[:status]) unless params[:status] == "all" || params[:status].blank?
 
  28     @notes = @notes.order("updated_at DESC, id").distinct.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author)
 
  30     render :layout => "site"
 
  36     if current_user&.moderator?
 
  37       @note = Note.find(params[:id])
 
  38       @note_comments = @note.comments.unscope(:where => :visible)
 
  40       @note = Note.visible.find(params[:id])
 
  41       @note_comments = @note.comments
 
  44     @note_includes_anonymous = @note.author.nil? || @note_comments.find { |comment| comment.author.nil? }
 
  46     @note_comments = @note_comments.drop(1) if @note_comments.first&.event == "opened"
 
  47   rescue ActiveRecord::RecordNotFound
 
  48     render :template => "browse/not_found", :status => :not_found
 
  52     @anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i
 
  53     render :action => :new_readonly if api_status != "online"