From c0559ea98db215bdc191512d1f85e54da4d1ddb6 Mon Sep 17 00:00:00 2001 From: ArtOfCode- Date: Mon, 21 Oct 2024 01:41:52 +0100 Subject: [PATCH 1/2] Add support for 'me' as a user ID Closes #1439 --- app/controllers/flags_controller.rb | 2 +- app/controllers/users_controller.rb | 7 ++++++- app/helpers/users_helper.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/controllers/flags_controller.rb b/app/controllers/flags_controller.rb index a83947d37..f505f08fc 100644 --- a/app/controllers/flags_controller.rb +++ b/app/controllers/flags_controller.rb @@ -41,7 +41,7 @@ def new end def history - @user = User.find(params[:id]) + @user = helpers.user_with_me params[:id] unless @user == current_user || (current_user.is_admin || current_user.is_moderator) not_found return diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 62d2c93d2..c9d695566 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -632,7 +632,12 @@ def filter_params end def set_user - @user = user_scope.find_by(id: params[:id]) + user_id = if params[:id] == 'me' && user_signed_in? + current_user.id + else + params[:id] + end + @user = user_scope.find_by(id: user_id) not_found if @user.nil? end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 79ae8ac3d..a689060d0 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -79,4 +79,17 @@ def sso_sign_in_enabled? def devise_sign_in_enabled? SiteSetting['MixedSignIn'] || !sso_sign_in_enabled? end + + ## + # Returns a user corresponding to the ID provided, with the caveat that if +user_id+ is 'me' and there is a user + # signed in, the signed in user will be returned. Use for /users/me links. + # @param [String] user_id The user ID to find, from +params+ + # @return [User] The User object + def user_with_me(user_id) + if user_id == 'me' && user_signed_in? + current_user + else + User.find(user_id) + end + end end From 1faf2d9590623dc7f8f7eb44e518c82ea6b1b179 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Sun, 27 Oct 2024 01:54:08 +0300 Subject: [PATCH 2/2] fixed missing my_network route definition --- app/controllers/users_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c9d695566..973a8eb59 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -201,6 +201,10 @@ def posts end end + def my_network + redirect_to network_path(current_user) + end + def network @communities = Community.all render layout: 'without_sidebar'