ucb_rails_user 4.1.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/ucb_rails_user/concerns/impersonations_controller.rb +1 -1
- data/app/controllers/ucb_rails_user/concerns/users_controller.rb +6 -6
- data/app/models/{concerns → ucb_rails_user/concerns}/user_concerns.rb +3 -12
- data/app/models/ucb_rails_user/concerns/user_roles_concerns.rb +12 -0
- data/app/models/ucb_rails_user/ldap_person/entry.rb +17 -12
- data/app/models/{user.rb → ucb_rails_user/user.rb} +2 -2
- data/app/models/ucb_rails_user/user_ldap_service.rb +4 -4
- data/app/models/ucb_rails_user/user_search.rb +3 -3
- data/app/models/ucb_rails_user/user_session_manager/base.rb +2 -2
- data/app/models/ucb_rails_user/user_session_manager/in_people_ou_add_to_users_table.rb +9 -0
- data/app/models/ucb_rails_user/user_uc_path_service.rb +2 -2
- data/lib/ucb_rails_user/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a006bac12edd8a40970366888880a897fe1e93a0c05a3c00eb749cc6059305f1
|
4
|
+
data.tar.gz: 9c64c70d6ed4c4c8d107b981db50c5a93333624e226b4905c798ea402c2e9058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7b0b2239c2b26223a1c129392d78173133c88754bfff7d3d30505dcf22edce4e4e360a7a2328d9fbe2c3843b271f3a9e0e3881ceff1d5a6654b4d4c5925d032
|
7
|
+
data.tar.gz: a703d4ff5e5242dc5aada67526da8c544743e74c612354fc443cb2eafcb71f9433a51e17e2b2a0ce597fdbf794022650580937627b5583cf0bca12e54333c2b9
|
@@ -10,7 +10,7 @@ module UcbRailsUser::Concerns::ImpersonationsController
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def create
|
13
|
-
target = User.find_by(id: params[:ucb_rails_user_impersonation][:target_id])
|
13
|
+
target = UcbRailsUser::User.find_by(id: params[:ucb_rails_user_impersonation][:target_id])
|
14
14
|
if logged_in_user.impersonate!(target)
|
15
15
|
flash[:info] = "You are now impersonating #{target.full_name}"
|
16
16
|
return redirect_to "/"
|
@@ -8,9 +8,9 @@ module UcbRailsUser::Concerns::UsersController
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def index
|
11
|
-
@users = User.all
|
11
|
+
@users = UcbRailsUser::User.all
|
12
12
|
respond_to do |format|
|
13
|
-
format.html { @users = User.all }
|
13
|
+
format.html { @users = UcbRailsUser::User.all }
|
14
14
|
format.json { render json: UcbRails::UsersDatatable.new(view_context).as_json }
|
15
15
|
end
|
16
16
|
end
|
@@ -40,7 +40,7 @@ module UcbRailsUser::Concerns::UsersController
|
|
40
40
|
def create
|
41
41
|
uid = params.fetch(:ldap_uid)
|
42
42
|
user = nil
|
43
|
-
if user = User.find_by_ldap_uid(uid)
|
43
|
+
if user = UcbRailsUser::User.find_by_ldap_uid(uid)
|
44
44
|
flash[:warning] = "User already exists"
|
45
45
|
else
|
46
46
|
begin
|
@@ -91,7 +91,7 @@ module UcbRailsUser::Concerns::UsersController
|
|
91
91
|
:sort => :last_first_downcase
|
92
92
|
)
|
93
93
|
uid_strings = @lps_entries.map { |entry| entry.uid&.to_s }.compact
|
94
|
-
@lps_existing_uids = User.where(ldap_uid: uid_strings).pluck(:uid)
|
94
|
+
@lps_existing_uids = UcbRailsUser::User.where(ldap_uid: uid_strings).pluck(:uid)
|
95
95
|
render 'ucb_rails_user/lps/search'
|
96
96
|
end
|
97
97
|
|
@@ -115,7 +115,7 @@ module UcbRailsUser::Concerns::UsersController
|
|
115
115
|
private
|
116
116
|
|
117
117
|
def user_params(extra_params = [])
|
118
|
-
params.require(:
|
118
|
+
params.require(:ucb_rails_user_user).permit([
|
119
119
|
:superuser_flag,
|
120
120
|
:inactive_flag,
|
121
121
|
:first_name,
|
@@ -131,7 +131,7 @@ module UcbRailsUser::Concerns::UsersController
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def find_user
|
134
|
-
@user ||= User.find(params.fetch(:id))
|
134
|
+
@user ||= UcbRailsUser::User.find(params.fetch(:id))
|
135
135
|
end
|
136
136
|
|
137
137
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module UserConcerns
|
1
|
+
module UcbRailsUser::Concerns::UserConcerns
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
@@ -6,15 +6,6 @@ module UserConcerns
|
|
6
6
|
has_many :targets, class_name: "::UcbRailsUser::Impersonation", dependent: :delete_all
|
7
7
|
end
|
8
8
|
|
9
|
-
# Overridden by application
|
10
|
-
def roles
|
11
|
-
[]
|
12
|
-
end
|
13
|
-
|
14
|
-
def has_role?(role)
|
15
|
-
superuser? || roles.include?(role)
|
16
|
-
end
|
17
|
-
|
18
9
|
def active?
|
19
10
|
!inactive?
|
20
11
|
end
|
@@ -55,7 +46,7 @@ module UserConcerns
|
|
55
46
|
if target.respond_to?(:id)
|
56
47
|
target.id
|
57
48
|
else
|
58
|
-
User.find_by(id: target)&.id
|
49
|
+
UcbRailsUser::User.find_by(id: target)&.id
|
59
50
|
end
|
60
51
|
return false unless impersonation_is_valid?(target_id)
|
61
52
|
@current_impersonation = create_impersonation(target_id)
|
@@ -64,7 +55,7 @@ module UserConcerns
|
|
64
55
|
|
65
56
|
def current_impersonation
|
66
57
|
return @current_impersonation if defined?(@current_impersonation)
|
67
|
-
@current_impersonation = UcbRailsUser::Impersonation.
|
58
|
+
@current_impersonation = UcbRailsUser::Impersonation.where(user_id: self.id, active: true).includes([:target]).take
|
68
59
|
end
|
69
60
|
|
70
61
|
def impersonation_target
|
@@ -14,6 +14,7 @@ module UcbRailsUser::LdapPerson
|
|
14
14
|
attribute :first_name
|
15
15
|
attribute :last_name
|
16
16
|
attribute :email
|
17
|
+
attribute :alternate_email
|
17
18
|
attribute :phone
|
18
19
|
attribute :departments
|
19
20
|
attribute :affiliations
|
@@ -40,19 +41,23 @@ module UcbRailsUser::LdapPerson
|
|
40
41
|
class << self
|
41
42
|
|
42
43
|
def new_from_ldap_entry(ldap_entry)
|
44
|
+
# the to_s calls are because the underlying LDAP library sometimes returns strings as instances
|
45
|
+
# of Net::BER::BerIdentifiedString rather than String, and the Oracle DB library doesn't play
|
46
|
+
# nicely with those (postgres and sqlite work fine)
|
43
47
|
new(
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
48
|
+
uid: ldap_entry.uid&.to_s,
|
49
|
+
calnet_id: ldap_entry.berkeleyedukerberosprincipalstring.first&.to_s,
|
50
|
+
employee_id: ldap_entry.attributes[:berkeleyeduucpathid]&.first&.to_s,
|
51
|
+
student_id: ldap_entry.berkeleyedustuid&.to_s,
|
52
|
+
first_name: ldap_entry.givenname.first&.to_s,
|
53
|
+
last_name: ldap_entry.sn.first&.to_s,
|
54
|
+
email: ldap_entry.mail.first&.to_s,
|
55
|
+
alternate_email: ldap_entry.attributes[:berkeleyeduofficialemail]&.first&.to_s,
|
56
|
+
phone: ldap_entry.phone&.to_s,
|
57
|
+
departments: ldap_entry.berkeleyeduunithrdeptname&.to_s,
|
58
|
+
affiliations: ldap_entry.berkeleyeduaffiliations&.map(&:to_s),
|
59
|
+
affiliate_id: ldap_entry.berkeleyeduaffid.first&.to_s,
|
60
|
+
inactive: ldap_entry.expired? || false
|
56
61
|
)
|
57
62
|
end
|
58
63
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
include UserConcerns
|
1
|
+
class UcbRailsUser::User < ActiveRecord::Base
|
2
|
+
include UcbRailsUser::Concerns::UserConcerns
|
3
3
|
|
4
4
|
# Don't add anything more here - any logic for the User class should go into
|
5
5
|
# UserConcerns. This will make it much easier for host apps to customize
|
@@ -12,7 +12,7 @@ class UcbRailsUser::UserLdapService
|
|
12
12
|
def create_user_from_ldap_entry(ldap_entry)
|
13
13
|
UcbRailsUser.logger.debug "create_user_from_ldap_entry #{ldap_entry.uid}"
|
14
14
|
|
15
|
-
User.create! do |u|
|
15
|
+
UcbRailsUser::User.create! do |u|
|
16
16
|
u.ldap_uid = ldap_entry.uid
|
17
17
|
u.employee_id = ldap_entry.employee_id
|
18
18
|
u.affiliate_id = ldap_entry.affiliate_id
|
@@ -34,7 +34,7 @@ class UcbRailsUser::UserLdapService
|
|
34
34
|
def update_user_from_ldap_entry(ldap_entry)
|
35
35
|
UcbRailsUser.logger.debug "update_user_from_ldap_entry #{ldap_entry.uid}"
|
36
36
|
|
37
|
-
User.find_by_ldap_uid!(ldap_entry.uid).tap do |user|
|
37
|
+
UcbRailsUser::User.find_by_ldap_uid!(ldap_entry.uid).tap do |user|
|
38
38
|
user.employee_id = ldap_entry.employee_id if user.respond_to?(:employee_id=)
|
39
39
|
user.affiliate_id = ldap_entry.affiliate_id
|
40
40
|
user.student_id = ldap_entry.student_id
|
@@ -47,7 +47,7 @@ class UcbRailsUser::UserLdapService
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def create_or_update_user(uid)
|
50
|
-
if user = User.find_by_ldap_uid(uid)
|
50
|
+
if user = UcbRailsUser::User.find_by_ldap_uid(uid)
|
51
51
|
update_user_from_uid(uid)
|
52
52
|
else
|
53
53
|
create_user_from_uid(uid)
|
@@ -58,7 +58,7 @@ class UcbRailsUser::UserLdapService
|
|
58
58
|
# LDAP returns some values as Net::BER::BerIdentifiedString instances, and not
|
59
59
|
# all DBs seem to handle that well (e.g. Oracle) - we might want to fix LDAP library
|
60
60
|
# to smooth this over?
|
61
|
-
if user = User.find_by_ldap_uid(entry.uid.to_s)
|
61
|
+
if user = UcbRailsUser::User.find_by_ldap_uid(entry.uid.to_s)
|
62
62
|
update_user_from_ldap_entry(entry)
|
63
63
|
else
|
64
64
|
create_user_from_ldap_entry(entry)
|
@@ -10,10 +10,10 @@ module UcbRailsUser::UserSearch
|
|
10
10
|
.map { |n| "#{n}%" }
|
11
11
|
query =
|
12
12
|
if name1.present? && name2.present?
|
13
|
-
User.where("LOWER(first_name) LIKE ? AND LOWER(last_name) LIKE ?", name1, name2)
|
14
|
-
.or(User.where("LOWER(last_name) LIKE ? AND LOWER(first_name) LIKE ?", name1, name2))
|
13
|
+
UcbRailsUser::User.where("LOWER(first_name) LIKE ? AND LOWER(last_name) LIKE ?", name1, name2)
|
14
|
+
.or(UcbRailsUser::User.where("LOWER(last_name) LIKE ? AND LOWER(first_name) LIKE ?", name1, name2))
|
15
15
|
else
|
16
|
-
User.where("LOWER(first_name) LIKE ? OR LOWER(last_name) LIKE ?", name1, name1)
|
16
|
+
UcbRailsUser::User.where("LOWER(first_name) LIKE ? OR LOWER(last_name) LIKE ?", name1, name1)
|
17
17
|
end
|
18
18
|
query.order(:last_name, :first_name)
|
19
19
|
end
|
@@ -31,11 +31,11 @@ class UcbRailsUser::UserSessionManager::Base
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def active_user
|
34
|
-
@active_user ||= User.active.find_by_ldap_uid(uid)
|
34
|
+
@active_user ||= UcbRailsUser::User.active.find_by_ldap_uid(uid)
|
35
35
|
end
|
36
36
|
|
37
37
|
def active_admin_user
|
38
|
-
@active_user ||= User.active.superuser.find_by_ldap_uid(uid)
|
38
|
+
@active_user ||= UcbRailsUser::User.active.superuser.find_by_ldap_uid(uid)
|
39
39
|
end
|
40
40
|
|
41
41
|
def ldap_person_user_wrapper(ldap_person_entry)
|
@@ -8,6 +8,9 @@ module UcbRailsUser
|
|
8
8
|
|
9
9
|
if people_ou_entry.present?
|
10
10
|
UcbRailsUser::UserLdapService.create_or_update_user_from_entry(people_ou_entry).tap do |user|
|
11
|
+
if missing_or_invalid_email?(user)
|
12
|
+
user.update(email: people_ou_entry.alternate_email) if people_ou_entry.alternate_email.present?
|
13
|
+
end
|
11
14
|
user.touch(:last_login_at)
|
12
15
|
end
|
13
16
|
else
|
@@ -15,6 +18,12 @@ module UcbRailsUser
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
21
|
+
private
|
22
|
+
|
23
|
+
def missing_or_invalid_email?(user)
|
24
|
+
user&.email.blank? || (user.email =~ URI::MailTo::EMAIL_REGEXP).nil?
|
25
|
+
end
|
26
|
+
|
18
27
|
end
|
19
28
|
|
20
29
|
end
|
@@ -7,14 +7,14 @@ class UcbRailsUser::UserUcPathService
|
|
7
7
|
def create_or_update_user_from_employee_id(employee_id)
|
8
8
|
ucpath_entry = ucpath_client.fetch_employee_data_with_employee_id(employee_id)
|
9
9
|
return nil unless ucpath_entry.present?
|
10
|
-
user = User.find_or_initialize_by(employee_id: employee_id)
|
10
|
+
user = UcbRailsUser::User.find_or_initialize_by(employee_id: employee_id)
|
11
11
|
update_user_record_from_ucpath_entry!(user, ucpath_entry)
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_or_update_user_from_ldap_uid(ldap_uid)
|
15
15
|
ucpath_entry = ucpath_client.fetch_employee_data_with_ldap_uid(ldap_uid)
|
16
16
|
return nil unless ucpath_entry.present?
|
17
|
-
user = User.find_or_initialize_by(ldap_uid: ldap_uid)
|
17
|
+
user = UcbRailsUser::User.find_or_initialize_by(ldap_uid: ldap_uid)
|
18
18
|
update_user_record_from_ucpath_entry!(user, ucpath_entry)
|
19
19
|
end
|
20
20
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucb_rails_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Downey
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -324,8 +324,9 @@ files:
|
|
324
324
|
- app/controllers/ucb_rails_user/users_controller.rb
|
325
325
|
- app/helpers/ucb_rails_user/users_helper.rb
|
326
326
|
- app/helpers/ucb_rails_user_helper.rb
|
327
|
-
- app/models/concerns/user_concerns.rb
|
328
327
|
- app/models/ucb_rails_user/concerns/impersonation_concerns.rb
|
328
|
+
- app/models/ucb_rails_user/concerns/user_concerns.rb
|
329
|
+
- app/models/ucb_rails_user/concerns/user_roles_concerns.rb
|
329
330
|
- app/models/ucb_rails_user/configuration/cas.rb
|
330
331
|
- app/models/ucb_rails_user/configuration/configuration.rb
|
331
332
|
- app/models/ucb_rails_user/configuration/email.rb
|
@@ -335,6 +336,7 @@ files:
|
|
335
336
|
- app/models/ucb_rails_user/ldap_person/entry.rb
|
336
337
|
- app/models/ucb_rails_user/ldap_person/finder.rb
|
337
338
|
- app/models/ucb_rails_user/ldap_person/test_finder.rb
|
339
|
+
- app/models/ucb_rails_user/user.rb
|
338
340
|
- app/models/ucb_rails_user/user_ldap_service.rb
|
339
341
|
- app/models/ucb_rails_user/user_search.rb
|
340
342
|
- app/models/ucb_rails_user/user_session_manager/active_in_user_table.rb
|
@@ -346,7 +348,6 @@ files:
|
|
346
348
|
- app/models/ucb_rails_user/user_session_manager/ldap_person_user_wrapper.rb
|
347
349
|
- app/models/ucb_rails_user/user_session_manager/test_session_manager.rb
|
348
350
|
- app/models/ucb_rails_user/user_uc_path_service.rb
|
349
|
-
- app/models/user.rb
|
350
351
|
- app/views/ucb_rails_user/home/logged_in.html.haml
|
351
352
|
- app/views/ucb_rails_user/home/not_logged_in.html.haml
|
352
353
|
- app/views/ucb_rails_user/impersonations/index.html.haml
|