Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 'me' as a user ID #1441

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/flags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -632,7 +636,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

Expand Down
13 changes: 13 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading