Skip to content

Commit 8882f4c

Browse files
Remove hardcoded admin functionality
1 parent c19ffdf commit 8882f4c

21 files changed

Lines changed: 39 additions & 231 deletions

app/controllers/proxy_borrower_admin_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def init_form!; end
109109

110110
# You shall not pass....unless you're an admin
111111
def require_admin!
112-
@user_is_admin = current_user.any_role?(Role.proxyborrow_admin)
112+
@user_is_admin = current_user.any_role?(Role.proxyborrow_admin, :framework_admin)
113113
redirect_to proxy_borrower_forms_path unless @user_is_admin
114114
end
115115

app/controllers/proxy_borrower_forms_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def index
99
# I think I want to get the users role now... if they're in the DB
1010
# then I'll want to pass that info so they have the
1111
# admin link...otherwise, NO admin link!
12-
@user_is_admin = current_user.any_role?(Role.proxyborrow_admin)
12+
@user_is_admin = current_user.any_role?(Role.proxyborrow_admin, :framework_admin)
1313
end
1414

1515
def dsp_form

app/controllers/reference_card_forms_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def validate_recaptcha!
8585

8686
def require_admin!
8787
authenticate!
88-
@user_is_admin = current_user.role?(Role.stackpass_admin)
88+
@user_is_admin = current_user.any_role?(Role.stackpass_admin, :framework_admin)
8989
raise Error::ForbiddenError unless @user_is_admin
9090
end
9191
end

app/controllers/stack_pass_admin_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def init_form!; end
5151

5252
# You shall not pass....unless you're an admin
5353
def require_admin!
54-
@user_is_admin = current_user.any_role?(Role.stackpass_admin)
54+
@user_is_admin = current_user.any_role?(Role.stackpass_admin, :framework_admin)
5555
redirect_to stack_pass_forms_path unless @user_is_admin
5656
end
5757

app/controllers/stack_pass_forms_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ def validate_recaptcha!
8686
end
8787

8888
def require_admin!
89-
@user_is_admin = authenticate_with_role!(Role.stackpass_admin)
89+
@user_is_admin = authenticate_with_role!(Role.stackpass_admin, :framework_admin)
9090
end
9191
end

app/controllers/stack_requests_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class StackRequestsController < ApplicationController
88
def forbidden; end
99

1010
def index
11-
@user_is_admin = current_user.role?(Role.stackpass_admin)
11+
@user_is_admin = current_user.any_role?(Role.stackpass_admin, :framework_admin)
1212
end
1313

1414
end

app/helpers/field_builder.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require 'action_view/helpers/tag_helper'
22

3-
# rubocop:disable Rails/HelperInstanceVariable
43
class FieldBuilder
54
attr_reader :tag_helper
65
attr_reader :builder
@@ -109,4 +108,3 @@ def error_feedback_tag
109108
content_tag(:div, first_error, class: 'invalid-feedback')
110109
end
111110
end
112-
# rubocop:enable Rails/HelperInstanceVariable

app/models/framework_users.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,4 @@ class FrameworkUsers < ActiveRecord::Base
2121
validates :role,
2222
presence: true
2323

24-
class << self
25-
# Hardcoded admins - so if for some reason all of the
26-
# admins in the DB are deleted, we still have a way of
27-
# getting in and managing things!
28-
HARDCODED_ADMIN_UIDS = [
29-
'7165', # Lisa Weber
30-
'1707532' # Steve Sullivan
31-
].freeze
32-
33-
def hardcoded_admin?(uid)
34-
HARDCODED_ADMIN_UIDS.include?(uid.to_s)
35-
end
36-
end
37-
3824
end

app/models/user.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,8 @@ def primary_patron_record
7272
@primary_patron_record ||= find_primary_record
7373
end
7474

75-
# TODO: Unify this, faculty/staff checks, framework/alma admin checks
76-
# (and improve the design)
7775
def role?(role)
78-
role_value =
79-
if role.respond_to?(:role)
80-
role.role
81-
elsif role.respond_to?(:name)
82-
role.name
83-
else
84-
role
85-
end
86-
87-
role_name = role_value.to_sym
76+
role_name = role_name_for(role)
8877

8978
case role_name
9079
when :framework_admin
@@ -93,9 +82,6 @@ def role?(role)
9382
return true if alma_admin?
9483
end
9584

96-
# TODO: Remove this hackery!!!
97-
return true if FrameworkUsers.hardcoded_admin?(uid)
98-
9985
user = FrameworkUsers.find_by(lcasid: uid)
10086
return false unless user
10187

@@ -124,4 +110,17 @@ def uid_patron_record
124110
def find_primary_record
125111
uid_patron_record
126112
end
113+
114+
def role_name_for(role)
115+
role_value =
116+
if role.respond_to?(:role)
117+
role.role
118+
elsif role.respond_to?(:name)
119+
role.name
120+
else
121+
role
122+
end
123+
124+
role_value.to_sym
125+
end
127126
end

spec/calnet_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require 'alma_helper'
33

44
module CalnetHelper
5-
# Lisa Weber's UID, hard-coded in FrameworkUsers
6-
STACK_REQUEST_ADMIN_UID = '7165'.freeze
5+
# UID used for test authentication
6+
TEST_UID = '7165'.freeze
77

88
# Mocks a calnet login as the specified patron, and stubs the corresponding
99
# Millennium patron dump file. Suitable for calling from a before() block.
@@ -31,7 +31,7 @@ def with_patron_login(patron_id)
3131
user = login_as_patron(patron_id)
3232
yield user
3333
rescue StandardError => e
34-
puts "#{e}\n\t#{e.backtrace.join("\n\t")}" # rubocop:disable Rails/Output
34+
puts "#{e}\n\t#{e.backtrace.join("\n\t")}"
3535
raise
3636
ensure
3737
logout!

0 commit comments

Comments
 (0)