egov_utils 0.1.15 → 0.1.16

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: 4fcb23ce666217bfad1650aaa7e0358540f66fb020f5536a752b4e707ccfd7e8
4
- data.tar.gz: 5939b4825eba28843b06a490df586328b6cb5a5ea5aa915cf3fd43c696c94f88
3
+ metadata.gz: f5e0d2eacc1f1255140048fa865dfe34378472030cbbd7c51bd39efd2f49c152
4
+ data.tar.gz: 62675a67d00e5dc9b3ffcdf19a833166979091b00d454ca64cbbcdd2b575b63d
5
5
  SHA512:
6
- metadata.gz: afd6dc5da66507d7ade7221bd48cc5daff0b3945172101d456f519031fab2231451cb2273a11aae24003dbad4d8c9cada1b06318215f96c08f5157b8bad8aaa0
7
- data.tar.gz: 632e86820385975db0555ae76c9d0e506b8dce49b16b8d9d1884d5451c53eb98800943415fd945867ba33bfda0ac858688ed17d1298ebe1bc97eb1068174396b
6
+ metadata.gz: 182175b3dbe8628155477389a50ed4dc10c5cb4b785115551ff34e9609dd0c14a34989aaea07f01c382137a1533a00e9a1961809c5e8c342fada11238013718d
7
+ data.tar.gz: f94cd08099878bcd8c0218f2103aa961f2152a8cd88b54cf5b8236a540d1cd1a5c67021cf6a4d0f3fb42c19f98bc5b38ee4eb91ccf506f72b74f0e8fd338d3be
@@ -18,9 +18,10 @@ window.eGovUtilities =
18
18
  }
19
19
 
20
20
 
21
- initPage: ()->
22
- eGovUtilities.initDatepickers()
23
- eGovUtilities.initSelect2()
21
+ initPage: ($container)->
22
+ $container ||= $(document)
23
+ eGovUtilities.initDatepickers($container)
24
+ eGovUtilities.initSelect2($container)
24
25
 
25
26
  initDatepickers: ($container)->
26
27
  $container ||= $(document)
@@ -64,7 +65,7 @@ window.eGovUtilities =
64
65
  setModalContent: ($modal, body, title) ->
65
66
  $modal.find('.modal-title').text(title)
66
67
  $modal.find('.modal-body').html(body)
67
- eGovUtilities.initDatepickers($modal)
68
+ eGovUtilities.initPage($modal)
68
69
 
69
70
  showModal: (body, options) ->
70
71
  options = options || {}
@@ -75,6 +76,9 @@ window.eGovUtilities =
75
76
  delete options['title']
76
77
  eGovUtilities.setModalContent($modal, body, title)
77
78
  $modal.modal(options)
79
+ window.setTimeout(()->
80
+ eGovUtilities.initPage($modal)
81
+ , 750)
78
82
  $modal
79
83
 
80
84
  $(eGovUtilities.setup)
@@ -20,7 +20,7 @@ module EgovUtils
20
20
  private
21
21
 
22
22
  def create_params
23
- params.require(:group).permit(:name, :provider, :ldap_uid)
23
+ params.require(:group).permit(:name, :provider, :ldap_uid, :external_uid)
24
24
  end
25
25
 
26
26
  end
@@ -0,0 +1,23 @@
1
+ module EgovUtils
2
+ class PeopleController < ApplicationController
3
+
4
+ load_and_authorize_resource
5
+
6
+ def index
7
+ @people_schema = PersonSchema.new
8
+ @people_schema.from_params(params)
9
+ respond_to do |format|
10
+ if params['_type'] == 'query'
11
+ format.json{ render json: {
12
+ results: @people_schema.entities.collect do |p|
13
+ {id: p.id, text: p.to_s, residence: p.residence.to_s}
14
+ end
15
+ }}
16
+ else
17
+ format.json{ render json: @people_schema }
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -3,7 +3,7 @@ module EgovUtils
3
3
 
4
4
  # before_safe :identify_address , if: :changed?
5
5
 
6
- validates :street, :city, length: 3..255
6
+ validates :street, :city, length: 2..255
7
7
  validates :postcode, numericality: { only_integer: true }
8
8
  validates :district, inclusion: { in: :district_names }
9
9
  validates :region, inclusion: { in: :region_names }
@@ -22,5 +22,9 @@ module EgovUtils
22
22
  ldap_members.detect{|mem| mem[:login] == user.login }
23
23
  end
24
24
 
25
+ def external_uid
26
+ super || auth_source.send(:get_group_dn, sid: ldap_uid)
27
+ end
28
+
25
29
  end
26
30
  end
@@ -12,5 +12,9 @@ module EgovUtils
12
12
  firstname.to_s + ' ' + lastname.to_s
13
13
  end
14
14
 
15
+ def to_s
16
+ "#{fullname} (#{I18n.t(:text_born_on_at, place: birth_place, date: I18n.l(birth_date.to_date))})"
17
+ end
18
+
15
19
  end
16
20
  end
@@ -106,7 +106,14 @@ module EgovUtils
106
106
 
107
107
  def ldap_groups
108
108
  if provider.present?
109
- EgovUtils::Group.where(provider: provider).to_a.select{|g| auth_source.member?(ldap_dn, g.ldap_uid) }
109
+ group_ids = Rails.cache.read("#{cache_key}/ldap_group_ids", expires_in: 30.minutes)
110
+ if group_ids
111
+ groups = EgovUtils::Group.where(id: group_ids).to_a
112
+ else
113
+ groups = EgovUtils::Group.where(provider: provider).to_a.select{|g| auth_source.member?(ldap_dn, g.external_uid) }
114
+ Rails.cache.write("#{cache_key}/ldap_group_ids", groups.collect(&:id), expires_in: 30.minutes)
115
+ end
116
+ groups
110
117
  end
111
118
  end
112
119
 
@@ -7,7 +7,7 @@ module EgovUtils
7
7
 
8
8
  def initialize_available_attributes
9
9
  @available_attributes ||= []
10
- @available_attributes << Fullname.new(model, 'fullname', 'string')
10
+ @available_attributes << AzaharaSchema::DerivedAttribute.new(model, 'fullname', :concat, 'firstname', 'lastname', schema: self)
11
11
  super
12
12
  end
13
13
 
@@ -7,7 +7,7 @@ module EgovUtils
7
7
 
8
8
  def initialize_available_attributes
9
9
  @available_attributes ||= []
10
- @available_attributes << Fullname.new(model, 'fullname', 'string')
10
+ @available_attributes << AzaharaSchema::DerivedAttribute.new(model, 'fullname', :concat, 'firstname', 'lastname', schema: self)
11
11
  super
12
12
  @available_attributes << AllRoleNames.new(model, 'all_role_names', 'string')
13
13
  end
@@ -53,6 +53,8 @@ cs:
53
53
  firstname: Jméno
54
54
  lastname: Příjmení
55
55
  birth_date: Datum narození
56
+ birth_place: Místo narození
57
+ residence: Bydliště
56
58
 
57
59
 
58
60
  models_errors: &my_model_errors
data/config/routes.rb CHANGED
@@ -10,6 +10,8 @@ EgovUtils::Engine.routes.draw do
10
10
  post :approve, on: :member
11
11
  end
12
12
 
13
+ resources :people
14
+
13
15
  resources :groups
14
16
  resources :roles
15
17
 
@@ -0,0 +1,5 @@
1
+ class AddExternalUidToGroups < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :egov_utils_groups, :external_uid, :string
4
+ end
5
+ end
@@ -165,33 +165,19 @@ module EgovUtils
165
165
  raise AuthSourceException.new(e.message)
166
166
  end
167
167
 
168
- def member?(user_dn, group_sid)
168
+ def member?(user_dn, group_dn)
169
169
  ldap_con = initialize_ldap_con(options['bind_dn'], options['password'])
170
- group_dn = nil
171
- Rails.logger.debug("Membership in group for #{user_dn}")
172
- ldap_con.search(base: options['base'],
173
- filter: base_group_filter & Net::LDAP::Filter.eq('objectSID', group_sid),
174
- attributes: ['dn']) do |entry|
175
- group_dn = get_attr(entry, 'dn')
176
- end
177
- if group_dn
178
- ldap_con.search(base: user_dn,
179
- filter: base_user_filter & Net::LDAP::Filter.ex('memberOf:1.2.840.113556.1.4.1941', group_dn),
180
- attributes: ['dn']) do |entry|
181
- return true
182
- end
170
+ Rails.logger.debug("Membership in group (#{group_dn}) for (#{user_dn})")
171
+ ldap_con.search(base: user_dn,
172
+ filter: base_user_filter & Net::LDAP::Filter.ex('memberOf:1.2.840.113556.1.4.1941', group_dn),
173
+ attributes: ['dn']) do |entry|
174
+ return true
183
175
  end
184
176
  return false
185
177
  end
186
178
 
187
- def group_members(group_sid)
179
+ def group_members(group_dn)
188
180
  ldap_con = initialize_ldap_con(options['bind_dn'], options['password'])
189
- group_dn = nil
190
- ldap_con.search(base: options['base'],
191
- filter: base_group_filter & Net::LDAP::Filter.eq('objectSID', group_sid),
192
- attributes: ['dn']) do |entry|
193
- group_dn = get_attr(entry, 'dn')
194
- end
195
181
  results = []
196
182
  if group_dn
197
183
  ldap_con.search(base: options['base'],
@@ -254,7 +240,8 @@ module EgovUtils
254
240
  :dn => entry.dn,
255
241
  :name => get_attr(entry, 'cn'),
256
242
  :provider => provider,
257
- :ldap_uid => get_sid_string( get_attr(entry, 'objectSID') )
243
+ :ldap_uid => get_sid_string( get_attr(entry, 'objectSID') ),
244
+ :external_uid => entry.dn
258
245
  }
259
246
  end
260
247
 
@@ -297,6 +284,15 @@ module EgovUtils
297
284
  attrs
298
285
  end
299
286
 
287
+ def get_group_dn(**options)
288
+ ldap_con = initialize_ldap_con(options['bind_dn'], options['password'])
289
+ ldap_con.search(base: options['base'],
290
+ filter: base_group_filter & ( options[:sid] ? Net::LDAP::Filter.eq('objectSID', options[:sid]) : group_search_filters(options[:name]) ),
291
+ attributes: ['dn']) do |entry|
292
+ return get_attr(entry, 'dn')
293
+ end
294
+ end
295
+
300
296
  def search_user_dn(login, password=nil)
301
297
  ldap_con = nil
302
298
  if options['bind_dn'].include?("$login")
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.1.15'
2
+ VERSION = '0.1.16'
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.1.15
4
+ version: 0.1.16
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: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -287,11 +287,11 @@ files:
287
287
  - app/attributes/egov_utils/all_role_names.rb
288
288
  - app/attributes/egov_utils/district.rb
289
289
  - app/attributes/egov_utils/full_address.rb
290
- - app/attributes/egov_utils/fullname.rb
291
290
  - app/attributes/egov_utils/region.rb
292
291
  - app/controllers/egov_utils/addresses_controller.rb
293
292
  - app/controllers/egov_utils/application_controller.rb
294
293
  - app/controllers/egov_utils/groups_controller.rb
294
+ - app/controllers/egov_utils/people_controller.rb
295
295
  - app/controllers/egov_utils/roles_controller.rb
296
296
  - app/controllers/egov_utils/sessions_controller.rb
297
297
  - app/controllers/egov_utils/users_controller.rb
@@ -344,6 +344,7 @@ files:
344
344
  - db/migrate/20170809150646_create_egov_utils_people.rb
345
345
  - db/migrate/20170824111701_create_egov_utils_groups.rb
346
346
  - db/migrate/20171103141234_add_birth_place_and_residence_to_people.rb
347
+ - db/migrate/20171109172909_add_external_uid_to_groups.rb
347
348
  - lib/bootstrap_form/datetimepicker.rb
348
349
  - lib/bootstrap_form/fileuid.rb
349
350
  - lib/bootstrap_form/helpers/bootstrap4.rb
@@ -1,15 +0,0 @@
1
- module EgovUtils
2
- class Fullname < AzaharaSchema::Attribute
3
-
4
- def arel_field
5
- Arel::Nodes::NamedFunction.new 'CONCAT', [EgovUtils::Person.arel_table[:lastname], Arel::Nodes::SqlLiteral.new('\' \'') , EgovUtils::Person.arel_table[:firstname]]
6
- end
7
-
8
- def build_json_options!(options)
9
- options[:methods] ||= []
10
- options[:methods] << 'fullname'
11
- options
12
- end
13
-
14
- end
15
- end