From 4ceebefefaac05e3770ad232a6bc1839637962d3 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 21 Aug 2023 01:11:49 +0300 Subject: [PATCH 1/1] Move user lookup and error render to concerns --- app/controllers/application_controller.rb | 18 ------------------ app/controllers/changesets_controller.rb | 2 ++ app/controllers/concerns/user_methods.rb | 20 ++++++++++++++++++++ app/controllers/confirmations_controller.rb | 1 + app/controllers/diary_entries_controller.rb | 2 ++ app/controllers/friendships_controller.rb | 2 ++ app/controllers/messages_controller.rb | 2 ++ app/controllers/notes_controller.rb | 2 ++ app/controllers/traces_controller.rb | 2 ++ app/controllers/user_blocks_controller.rb | 2 ++ app/controllers/user_roles_controller.rb | 2 ++ 11 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5dcfee07c..a30816a8e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -215,24 +215,6 @@ class ApplicationController < ActionController::Base render :action => "timeout" end - ## - # ensure that there is a "user" instance variable - def lookup_user - render_unknown_user params[:display_name] unless @user = User.active.find_by(:display_name => params[:display_name]) - end - - ## - # render a "no such user" page - def render_unknown_user(name) - @title = t "users.no_such_user.title" - @not_found_user = name - - respond_to do |format| - format.html { render :template => "users/no_such_user", :status => :not_found } - format.all { head :not_found } - end - end - ## # Unfortunately if a PUT or POST request that has a body fails to # read it then Apache will sometimes fail to return the response it diff --git a/app/controllers/changesets_controller.rb b/app/controllers/changesets_controller.rb index 7796dfeb2..22d3356b7 100644 --- a/app/controllers/changesets_controller.rb +++ b/app/controllers/changesets_controller.rb @@ -1,6 +1,8 @@ # The ChangesetController is the RESTful interface to Changeset objects class ChangesetsController < ApplicationController + include UserMethods + layout "site" require "xml/libxml" diff --git a/app/controllers/concerns/user_methods.rb b/app/controllers/concerns/user_methods.rb index 81e9f0064..6d92aac79 100644 --- a/app/controllers/concerns/user_methods.rb +++ b/app/controllers/concerns/user_methods.rb @@ -3,6 +3,26 @@ module UserMethods private + ## + # ensure that there is a "user" instance variable + def lookup_user + @user = User.active.find_by!(:display_name => params[:display_name]) + rescue ActiveRecord::RecordNotFound + render_unknown_user params[:display_name] + end + + ## + # render a "no such user" page + def render_unknown_user(name) + @title = t "users.no_such_user.title" + @not_found_user = name + + respond_to do |format| + format.html { render :template => "users/no_such_user", :status => :not_found } + format.all { head :not_found } + end + end + ## # update a user's details def update_user(user, params) diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index a482bc96d..65f560571 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -1,5 +1,6 @@ class ConfirmationsController < ApplicationController include SessionMethods + include UserMethods layout "site" diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index 6981ed797..ea6d1d276 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -1,4 +1,6 @@ class DiaryEntriesController < ApplicationController + include UserMethods + layout "site", :except => :rss before_action :authorize_web diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index 4d1161147..731dda453 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -1,4 +1,6 @@ class FriendshipsController < ApplicationController + include UserMethods + layout "site" before_action :authorize_web diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 22d0c88ba..e0b5b05d3 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -1,4 +1,6 @@ class MessagesController < ApplicationController + include UserMethods + layout "site" before_action :authorize_web diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 440a620e8..6b2a3a86b 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,4 +1,6 @@ class NotesController < ApplicationController + include UserMethods + layout :map_layout before_action :check_api_readable diff --git a/app/controllers/traces_controller.rb b/app/controllers/traces_controller.rb index 0b7dbc94a..90ab34a48 100644 --- a/app/controllers/traces_controller.rb +++ b/app/controllers/traces_controller.rb @@ -1,4 +1,6 @@ class TracesController < ApplicationController + include UserMethods + layout "site", :except => :georss before_action :authorize_web diff --git a/app/controllers/user_blocks_controller.rb b/app/controllers/user_blocks_controller.rb index 63ebdad71..546c8233c 100644 --- a/app/controllers/user_blocks_controller.rb +++ b/app/controllers/user_blocks_controller.rb @@ -1,4 +1,6 @@ class UserBlocksController < ApplicationController + include UserMethods + layout "site" before_action :authorize_web diff --git a/app/controllers/user_roles_controller.rb b/app/controllers/user_roles_controller.rb index cf5b4de9e..b54cd0bd7 100644 --- a/app/controllers/user_roles_controller.rb +++ b/app/controllers/user_roles_controller.rb @@ -1,4 +1,6 @@ class UserRolesController < ApplicationController + include UserMethods + layout "site" before_action :authorize_web -- 2.39.5