Skip to content

Commit

Permalink
added method for permitted params for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
alihadimazeh committed Nov 25, 2024
1 parent 509ee97 commit d033678
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,7 @@ def create_user_params
end

def update_user_params
is_admin = PermissionsChecker.new(current_user:, permission_names: 'ManageUsers', current_provider:).call

@update_user_params ||= if external_auth? && is_admin
params.require(:user).permit(:name)
elsif external_auth?
params.require(:user).permit(:password, :avatar, :language, :role_id, :invite_token)
else
params.require(:user).permit(:name, :password, :avatar, :language, :role_id, :invite_token)
end
@update_user_params ||= params.require(:user).permit(permitted_params)
end

def change_password_params
Expand All @@ -202,6 +194,14 @@ def valid_domain?
end
false
end

def permitted_params
is_admin = PermissionsChecker.new(current_user:, permission_names: 'ManageUsers', current_provider:).call

return %i[password avatar language role_id invite_token] if external_auth? && !is_admin

%i[name password avatar language role_id invite_token]
end
end
end
end

0 comments on commit d033678

Please sign in to comment.