egov_utils 0.7.3 → 1.0.0

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: 5ee23718009c2715bfb29f6fc3737dcf1eae0c3d4b2957a0436c252df3b5ab98
4
- data.tar.gz: fc0bfece5036f56e4aaeab1116a9e3ea576b7f9a73a0760d2d7effdb9379cb50
3
+ metadata.gz: 364918936845de99fd8aedf7dbf6121dbf33276e91c6ffd7a4f91dde07d80e7b
4
+ data.tar.gz: cfefd77e3f788be67a03ebe4bfddb46418fdeff608aae35c6844adae70859f73
5
5
  SHA512:
6
- metadata.gz: 41a183c8a95d667942678cc015be6ba81f6c9fc0b318cb8fcee15656a94abde52a7b989544e047cb12dab5970a933359bc25a0f8ffa6c684ebb11f9e0658b811
7
- data.tar.gz: e5b83a89879abd30ff198892b7c6422fb6952dbb55802d6fa5a8e03d61feb8c508f78fb4f8cb98e1a8bfe3f37a6883bb857cad569d3a1376f2c111d6e5bf1159
6
+ metadata.gz: 0de59c3058922aeb88c0d8267edccf5e104f7bc485c64eea968d7445234816a8f0594ecd1e21bd7c18eacafbc02682380ceda2f3d0693f9cb28c52de1a3f80d5
7
+ data.tar.gz: 7f90602a7b4418c3d5fcc4f746c4821a19df5a5a595421c56a9ca47be74c08283e10785f70a1787464c9d7691cf1aa2fcc84dafde496507d80e090b8f685ced9
@@ -9,7 +9,7 @@ module EgovUtils
9
9
  respond_to do |format|
10
10
  if params['_type'] == 'query'
11
11
  format.json{ render json: {
12
- results: @people_schema.entities.collect do |p|
12
+ results: @people_schema.entities.includes(:residence).collect do |p|
13
13
  {id: p.id, text: p.to_s, residence: p.residence.to_s}
14
14
  end
15
15
  }}
@@ -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: 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.3'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-05 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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