Skip to content

Commit

Permalink
Fix: users edition and login_as with the @ symbol in there usernames (
Browse files Browse the repository at this point in the history
#857)

* fix username with the `@` in the usernames

* make the user edit as login as work
  • Loading branch information
syphax-bouazzouni authored Nov 21, 2024
1 parent f5dbf31 commit 9429305
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@ def authorize_and_redirect
end

def authorize_admin
admin = session[:user] && session[:user].admin?
redirect_to_home unless admin
redirect_to_home unless current_user_admin?
end

def current_user_admin?
session[:user] && session[:user].admin?
session[:user]&.admin? || current_login_as_admin?
end

def current_login_as_admin?
session[:admin_user]&.admin?
end

def ontology_restricted?(acronym)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def unescape_id

def verify_owner
return if current_user_admin?

if session[:user].nil? || (!session[:user].id.eql?(params[:id]) && !session[:user].username.eql?(params[:id]))
redirect_to controller: 'login', action: 'index', redirect: "/accounts/#{params[:id]}"
end
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

resources :projects, constraints: { id: /[^\/]+/ }

resources :users, path: :accounts, constraints: { id: /[\d\w\.\-\%\+ ]+/ }
resources :users, path: :accounts, constraints: { id: /[\d\w\.\@\-\%\+ ]+/ }

get '/users/subscribe/:username', to: 'users#subscribe'
get '/users/un-subscribe/:email', to: 'users#un_subscribe'
Expand Down Expand Up @@ -204,7 +204,7 @@
get '/lost_pass_success' => 'login#lost_password_success'
get '/reset_password' => 'login#reset_password'
post '/accounts/:id/custom_ontologies' => 'users#custom_ontologies', :as => :custom_ontologies
get '/login_as/:login_as' => 'login#login_as', constraints: { login_as: /[\d\w\.\-\%\+ ]+/ }
get '/login_as/:login_as' => 'login#login_as', constraints: { login_as: /[\d\w\.\@\-\%\+ ]+/ }
post '/login/send_pass', to: 'login#send_pass'

get '/groups' => 'taxonomy#index'
Expand Down

0 comments on commit 9429305

Please sign in to comment.