1 # frozen_string_literal: true
3 class NotesController < ApplicationController
8 before_action :check_api_readable
9 before_action :authorize_web
10 before_action :set_locale
11 before_action :require_oauth
15 before_action :lookup_user, :only => [:index]
16 around_action :web_timeout
21 # Display a list of notes by a specified user
23 param! :page, Integer, :min => 1
25 @params = params.permit(:display_name, :status)
26 @title = t ".title", :user => @user.display_name
27 @page = (params[:page] || 1).to_i
29 @notes = @notes.visible unless current_user&.moderator?
30 @notes = @notes.where(:status => params[:status]) unless params[:status] == "all" || params[:status].blank?
31 @notes = @notes.order(:updated_at => :desc, :id => :asc).distinct.offset((@page - 1) * PAGE_SIZE).limit(PAGE_SIZE + 1).preload(:comments => :author)
33 if @notes.size > PAGE_SIZE
38 render :layout => "site"
44 if current_user&.moderator?
45 @note = Note.find(params[:id])
46 @note_comments = @note.comments.unscope(:where => :visible)
48 @note = Note.visible.find(params[:id])
49 @note_comments = @note.comments
52 @note_includes_anonymous = @note.author.nil? || @note_comments.find { |comment| comment.author.nil? }
54 @note_comments = @note_comments.drop(1) if @note_comments.first&.event == "opened"
55 rescue ActiveRecord::RecordNotFound
56 render :template => "browse/not_found", :status => :not_found
60 @anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i
61 render :action => :new_readonly if api_status != "online"