egov_utils 0.7.4 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77ce0843ebb4bc70b8389b530dd43dd45c232cea4c741ec014995c77cb259e61
4
- data.tar.gz: 954dbe830452f604e681b87a6d33b8cefea419bcf141fbd5cebd088b3316e7c9
3
+ metadata.gz: 46866bd8cd323b73b2c99ad7f027e7b3ae9042f871d93b9b5ca0f45677fe643e
4
+ data.tar.gz: b233828c37f7dc42a4093aaee39ec5339f28e11ddd539910004803ba035be4eb
5
5
  SHA512:
6
- metadata.gz: b7394626c5d9f1771c679de090479739c1d78f212d9cada20f4dafbc6eebfcbedc336348c7b2b34192f6ce6b20165136cbc9d3750090f5b06318001038d56675
7
- data.tar.gz: 1f3f2e7c890eac9696bcf862d856758cee4280fe49e9ff5bc20d98af8884ee020d2ebff85e4fbe644f3050ddc0365ef1972d093a334f38d212ea331116028415
6
+ metadata.gz: 5b165226cc59161621b0645957accb50a58e153c4f139aaf6a22b19772a22900f75b7a99b4ab84899a732820d25e43c14bea28546ac7b648e8205f64a6a476c5
7
+ data.tar.gz: e25fd828cad3f7116847a65471415624493ccf04011987f5584a96bfb67598e3cff944ddc300947226b24232946bf696fa07b5b80d6c4e636ed9815dbf53fadd
@@ -133,9 +133,7 @@ module EgovUtils
133
133
  end
134
134
 
135
135
  def all_role_names
136
- @all_role_names ||= Rails.cache.fetch("#{cache_key}/all_role_names", expires_in: 1.hours) do
137
- groups.collect{|g| g.roles}.reduce([], :concat) + roles
138
- end
136
+ @all_role_names ||= groups.map(&:roles).flatten + roles
139
137
  @all_role_names << DEFAULT_ROLE if DEFAULT_ROLE && !@all_role_names.any?
140
138
  @all_role_names
141
139
  end
@@ -144,25 +142,8 @@ module EgovUtils
144
142
  all_role_names.map{|rn| EgovUtils::UserUtils::Role.find(rn) }.compact.collect{|cls| cls.new }
145
143
  end
146
144
 
147
- def groups
148
- super.to_a.concat( Array.wrap(ldap_groups) )
149
- end
150
-
151
- def ldap_dn
152
- @ldap_dn ||= ( dn = auth_source.send(:get_user_dn, login) ) && dn[:dn]
153
- end
154
-
155
145
  def ldap_groups
156
- if provider.present?
157
- group_ids = persisted? && Rails.cache.read("#{cache_key}/ldap_group_ids", expires_in: 30.minutes)
158
- if group_ids
159
- groups = EgovUtils::Group.where(id: group_ids).to_a
160
- else
161
- groups = EgovUtils::Group.where(provider: provider).to_a.select{|g| auth_source.member?(ldap_dn, g.external_uid) }
162
- Rails.cache.write("#{cache_key}/ldap_group_ids", groups.collect(&:id), expires_in: 30.minutes) if persisted?
163
- end
164
- groups
165
- end
146
+ groups.where.not(ldap_uid: nil)
166
147
  end
167
148
 
168
149
  def must_change_password?
@@ -0,0 +1,39 @@
1
+ module EgovUtils
2
+ class RefreshUserGroups
3
+
4
+ def initialize(user)
5
+ @user = user
6
+ end
7
+
8
+ def call
9
+ group_ids = (current_non_ldap_group + ldap_groups).compact.map(&:id)
10
+ user.group_ids = group_ids
11
+ user
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :user
17
+
18
+ def ldap_dn
19
+ @ldap_dn ||= begin
20
+ dn = user.auth_source.send(:get_user_dn, user.login)
21
+ dn[:dn] if dn
22
+ end
23
+ end
24
+
25
+ def ldap_groups
26
+ return [] if user.provider.blank?
27
+
28
+ @ldap_groups ||= begin
29
+ EgovUtils::Group.where(provider: user.provider).to_a.select do |g|
30
+ user.auth_source.member?(ldap_dn, g.external_uid)
31
+ end
32
+ end
33
+ end
34
+
35
+ def current_non_ldap_group
36
+ @current_non_ldap_groups ||= user.groups.where(ldap_uid: nil)
37
+ end
38
+ end
39
+ end
@@ -7,7 +7,7 @@
7
7
  %th= EgovUtils::User.human_attribute_name('groups')
8
8
  %th= t('label_actions')
9
9
  %tbody
10
- - users.entities.each do |user|
10
+ - users.entities.includes(:groups).each do |user|
11
11
  %tr
12
12
  %td{title: user.login}= user.fullname
13
13
  %td= user.provider
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.7.4'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
@@ -549,6 +549,7 @@ files:
549
549
  - app/schemas/egov_utils/natural_person_schema.rb
550
550
  - app/schemas/egov_utils/person_schema.rb
551
551
  - app/schemas/egov_utils/user_schema.rb
552
+ - app/services/egov_utils/refresh_user_groups.rb
552
553
  - app/validators/birthday_validator.rb
553
554
  - app/validators/email_validator.rb
554
555
  - app/validators/fileuid_validator.rb