Added universal redirect on the index action

- Only controllers with show actions will redirect on the index action
- Parameter checking is individualized per controller for the redirect check
This commit is contained in:
BrokenEagle
2020-01-25 20:28:08 +00:00
parent c1f2cd8d9d
commit 75ac11166c
5 changed files with 58 additions and 20 deletions

View File

@@ -32,11 +32,7 @@ class UsersController < ApplicationController
end
@users = User.paginated_search(params)
if params[:redirect].to_s.truthy? && @users.one? && User.normalize_name(@users.first.name) == User.normalize_name(params[:search][:name_matches])
redirect_to @users.first
else
respond_with @users
end
respond_with(@users)
end
def search
@@ -98,6 +94,14 @@ class UsersController < ApplicationController
private
def item_matches_params(user)
if params[:search][:name_matches]
User.normalize_name(user.name) == User.normalize_name(params[:search][:name_matches])
else
true
end
end
def check_privilege(user)
raise User::PrivilegeError unless user.id == CurrentUser.id || CurrentUser.is_admin?
end