egov_utils 0.4.15 → 0.5.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: 7113a82c08ac9b1557d68155cfbfc8e7e330d389c573c26929cf017e50a77e8c
4
- data.tar.gz: 0171105c96722ee7f05e88572a5129811ffc8c9a817a8f8fe804e764b9a047fd
3
+ metadata.gz: c74899e7d3af97ca0fe77218374a54990add7d743513151d81f9f32c750f58bf
4
+ data.tar.gz: 1ab92137208fdd57c215f9dc73423da363d066def3ec34304fb4171a34bd97a1
5
5
  SHA512:
6
- metadata.gz: 51255a8ae5635e28cb07e3b7a469daf88dcfd04eb05bf0b7f4bab2f7171aaf6d02641e9a411d522239dcad233295634daeb3fbb035ec8f6d0f6d84f56e0190b9
7
- data.tar.gz: 763bceddd07de03e6fa19117d341cf8f9d14d2df48a661b6f1d709438682c33656509a7da775d5dbe114a19bf9284b441183bcf93511533cd4adb6ab554e12b9
6
+ metadata.gz: 473113746d4b1d0d7654e1c505eb8f71628d5fc38818727dc32535d3430851a75956c2ded3196a5af366a73655425ecb768d5c5d6ec16c2e54fc3115e08fdde9
7
+ data.tar.gz: 987e4cc48915df7e45ac4367ed797bb42b379fbe5fe439354555cb205142ea7a1568c155982a11de4ce1a3f2527789ace2d501c8bb1e074434098b819bb21e93
data/Rakefile CHANGED
@@ -4,15 +4,15 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'EgovUtils'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
7
+ #require 'rdoc/task'
8
+
9
+ # RDoc::Task.new(:rdoc) do |rdoc|
10
+ # rdoc.rdoc_dir = 'rdoc'
11
+ # rdoc.title = 'EgovUtils'
12
+ # rdoc.options << '--line-numbers'
13
+ # rdoc.rdoc_files.include('README.md')
14
+ # rdoc.rdoc_files.include('lib/**/*.rb')
15
+ # end
16
16
 
17
17
  APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
18
18
  load 'rails/tasks/engine.rake'
@@ -1,9 +1,9 @@
1
1
  ActiveSupport::Reloader.to_prepare do
2
2
  begin
3
- require_dependency "#{Rails.application.class.parent_name.underscore}/roles"
3
+ require_dependency "#{Rails.application.class.module_parent_name.underscore}/roles"
4
4
  rescue LoadError => e
5
5
  Rails.logger.warn "!! You have not defined roles."
6
- Rails.logger.warn "!! Please define it in lib/#{Rails.application.class.parent_name.underscore}/roles."
6
+ Rails.logger.warn "!! Please define it in lib/#{Rails.application.class.module_arent_name.underscore}/roles."
7
7
  Rails.logger.warn "!! EgovUtils roles management will not work without it."
8
8
  end
9
9
  end
@@ -3,6 +3,7 @@ require 'request_store_rails'
3
3
 
4
4
  module EgovUtils
5
5
  class User < Principal
6
+ DEFAULT_ROLE = nil
6
7
 
7
8
  has_and_belongs_to_many :groups
8
9
 
@@ -35,9 +36,6 @@ module EgovUtils
35
36
  not_in_group(group).where(provider: nil)
36
37
  }
37
38
 
38
- cattr_accessor :default_role
39
- self.default_role = nil
40
-
41
39
  attribute :generate_password, :boolean, default: false
42
40
 
43
41
  def self.authenticate(login, password, active_only=true)
@@ -129,7 +127,7 @@ module EgovUtils
129
127
  @all_role_names ||= Rails.cache.fetch("#{cache_key}/all_role_names", expires_in: 1.hours) do
130
128
  groups.collect{|g| g.roles}.reduce([], :concat) + roles
131
129
  end
132
- @all_role_names << self.class.default_role if self.class.default_role && !@all_role_names.any?
130
+ @all_role_names << DEFAULT_ROLE if DEFAULT_ROLE && !@all_role_names.any?
133
131
  @all_role_names
134
132
  end
135
133
 
@@ -17,6 +17,32 @@ end
17
17
 
18
18
 
19
19
  module EgovUtils
20
+ class LoveMock < OpenStruct
21
+ def self.all
22
+ raise NotImplemented # you need to provide .all for your mock class
23
+ end
24
+
25
+ def self.where(clauses = {})
26
+ all.select do |l|
27
+ clauses.all? do |(k, filter)|
28
+ case filter
29
+ when Array
30
+ filter = filter.collect(&:to_s)
31
+ value = l.send(k)
32
+ pp k, filter, value
33
+ if value.is_a?(Array)
34
+ !(value.collect(&:to_s) & filter).empty?
35
+ else
36
+ filter.include?(value.to_s)
37
+ end
38
+ else
39
+ l.send(k) == filter
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
20
46
  class Love < ::ActiveResource::Base
21
47
 
22
48
  def self.config
@@ -32,5 +58,33 @@ module EgovUtils
32
58
  raise ArgumentError, "expected a clauses Hash, got #{clauses.inspect}" unless clauses.is_a? Hash
33
59
  find(:all, params: {f: clauses})
34
60
  end
61
+
62
+
63
+ # mocking
64
+
65
+ def self.inherited(subclass)
66
+ mock_subclass(subclass) if @mocking
67
+ end
68
+
69
+ def self.mocked_classes
70
+ @mocked_classes ||= {}
71
+ end
72
+
73
+ def self.mock!
74
+ @mocking = true
75
+ EgovUtils::Love.subclasses.each do |cls|
76
+ mock_subclass(cls)
77
+ end
78
+ end
79
+
80
+ def self.mock_subclass(subclass)
81
+ mock_cls = "#{subclass.name}Mock".safe_constantize
82
+ return unless mock_cls
83
+ mocked_classes[subclass.name] = subclass
84
+ namespaces = subclass.name.split('::')
85
+ namespace = (namespaces[0..-2].join('::').presence || 'Object').safe_constantize
86
+ namespace.send(:remove_const, namespaces[-1])
87
+ namespace.const_set(namespaces[-1], mock_cls)
88
+ end
35
89
  end
36
90
  end
@@ -1,4 +1,33 @@
1
1
  module EgovUtils
2
+ class OrganizationMock < LoveMock
3
+ def self.all(*attrs)
4
+ [
5
+ new(id: 1, name: 'Městský soud 1', key: '104000', category_abbrev: 'MS' ),
6
+ new(id: 2, name: 'Krajský soud 1', key: '204000', category_abbrev: 'KS' ),
7
+ new(id: 3, name: 'Krajský soud 2', key: '205000', category_abbrev: 'KS' ),
8
+ new(id: 13, name: 'Okresní soud 1', key: '204001', category_abbrev: 'OS' ),
9
+ new(id: 14, name: 'Okresní soud v Chomutově', key: '205030', category_abbrev: 'OS' )
10
+ ]
11
+ end
12
+
13
+ def self.find_by_key(key)
14
+ all.detect{ |o| o.key == key }
15
+ end
16
+
17
+ def self.courts(organization_keys=nil)
18
+ all.select do |o|
19
+ %w{OS KS MS}.include?(o.category_abbrev) &&
20
+ (organization_keys.nil? || organization_keys.include?(o.key))
21
+ end
22
+ end
23
+
24
+ def self.region_courts(branches=false)
25
+ all.select{ |o| %w{KS MS}.include?(o.category_abbrev) }
26
+ end
27
+
28
+ def branch_of_id; end
29
+ end
30
+
2
31
  class Organization < Love
3
32
 
4
33
  def self.find_by_key(key)
@@ -8,7 +8,7 @@ module EgovUtils
8
8
  class AuthSource
9
9
 
10
10
  NETWORK_EXCEPTIONS = [
11
- Net::LDAP::LdapError,
11
+ Net::LDAP::Error,
12
12
  Errno::ECONNABORTED, Errno::ECONNREFUSED, Errno::ECONNRESET,
13
13
  Errno::EHOSTDOWN, Errno::EHOSTUNREACH,
14
14
  SocketError
@@ -25,7 +25,7 @@ module EgovUtils
25
25
 
26
26
  config.generators do |g|
27
27
  g.test_framework :rspec
28
- g.fixture_replacement :factory_girl, :dir => 'spec/factories'
28
+ g.fixture_replacement :factory_bot, :dir => 'spec/factories'
29
29
  end
30
30
 
31
31
  initializer :append_migrations do |app|
@@ -131,5 +131,11 @@ module EgovUtils
131
131
  FactoryBot.definition_file_paths << EgovUtils::Engine.root.join('spec', 'factories')
132
132
  end
133
133
  end
134
+
135
+ initializer 'egov_utils.mock_resources' do
136
+ if EgovUtils::Settings.mock_resources?
137
+ EgovUtils::Love.mock!
138
+ end
139
+ end
134
140
  end
135
141
  end
@@ -23,6 +23,10 @@ module EgovUtils
23
23
  allow_internal_accounts? && allow_password_reset
24
24
  end
25
25
 
26
+ def mock_resources?
27
+ mock_resources
28
+ end
29
+
26
30
  end
27
31
 
28
32
  Settings['allow_register'] ||= false
@@ -31,4 +35,6 @@ module EgovUtils
31
35
  Settings['redmine'] ||= Settingslogic.new({})
32
36
  Settings['redmine']['enabled'] ||= false
33
37
 
38
+ Settings['mock_resources'] ||= !Rails.env.production?
39
+
34
40
  end
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.4.15'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,4 +1,42 @@
1
1
  # desc "Explaining what the task does"
2
- # task :egov_utils do
3
- # # Task goes here
4
- # end
2
+ namespace :egov_utils do
3
+
4
+ task create_admin: :environment do
5
+ pwd = SecureRandom.hex(8)
6
+ u = EgovUtils::User.new(login: 'admin', mail: 'admin@admin.cz', password: pwd, password_confirmation: pwd, active: true, roles: ['admin'])
7
+ if u.save
8
+ puts "User 'admin' created with password '#{pwd}'"
9
+ else
10
+ u.errors.full_messages.each{ |m| puts m }
11
+ end
12
+ end
13
+
14
+ task :require_factory_bot do
15
+ require 'factory_bot'
16
+ end
17
+
18
+ task cleanup_db: :environment do
19
+ require 'database_cleaner'
20
+
21
+ raise "This is very dangerous method and is not meant to be run in production" if Rails.env.production?
22
+
23
+ admins = EgovUtils::User.where(login: 'admin').collect do |u|
24
+ u.attributes.except('id', 'created_at', 'updated_at')
25
+ .merge('password' => 'abcdefgh', 'password_confirmation' => 'abcdefgh')
26
+ end
27
+ users = EgovUtils::User.where.not(provider: nil).collect{|u| u.attributes.except('id', 'created_at', 'updated_at') }
28
+ groups = EgovUtils::Group.where.not(provider: nil).collect{|u| u.attributes.except('id', 'created_at', 'updated_at') }
29
+ DatabaseCleaner.clean_with :truncation
30
+ EgovUtils::User.create(users)
31
+ EgovUtils::Group.create(groups)
32
+ EgovUtils::User.create(admins).each do |admin|
33
+ attrs = admins.detect{ |a| a['login'] == admin.login }
34
+ admin.update_columns(password_digest: attrs['password_digest'])
35
+ end
36
+ end
37
+
38
+ task load_staging_data: [:require_factory_bot, :cleanup_db] do
39
+ FactoryBot.find_definitions if Rails.env.staging?
40
+ require Rails.root.join('db', 'staging.rb')
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ FactoryBot.define do
2
+ factory :egov_utils_address, class: 'EgovUtils::Address' do
3
+ street { 'Vysoka' }
4
+ house_number { '156' }
5
+ orientation_number { '6a' }
6
+ city { 'Palermo' }
7
+ postcode { 42000 }
8
+ district { 'Hlavní město Praha' }
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :egov_utils_group, class: 'EgovUtils::Group' do
3
+ name { 'EgovUsers' }
4
+ provider { 'main' }
5
+ ldap_uid { 'S-1-5-21-1698188384-1693678267-1543859470-6637' }
6
+ external_uid { 'DN=Linux,OU=Users,DC=test,DC=justice,DC=cz' }
7
+ end
8
+ end
@@ -0,0 +1,29 @@
1
+ FactoryBot.define do
2
+ factory :egov_utils_person, class: 'EgovUtils::Person' do
3
+ transient do
4
+ natural_attributes { Hash.new }
5
+ end
6
+ association :residence, factory: :egov_utils_address
7
+ joid { SecureRandom.uuid }
8
+ person_type { nil }
9
+ natural_person { nil }
10
+ legal_person { nil }
11
+
12
+ trait :natural do
13
+ person_type { 'natural' }
14
+ after(:build) do |person, evaluator|
15
+ evaluator.natural_person = FactoryBot.build(:egov_utils_natural_person, evaluator.natural_attributes.merge(person: person))
16
+ end
17
+ end
18
+
19
+ factory :natural_person, traits: [:natural]
20
+ end
21
+
22
+ factory :egov_utils_natural_person, class: 'EgovUtils::NaturalPerson' do
23
+ firstname { 'John' }
24
+ sequence(:lastname){|n| "Doe-#{n}"}
25
+ birth_date { Date.today - (Random.new.rand(50)+18).years }
26
+ association :person, factory: :egov_utils_person
27
+ end
28
+
29
+ end
@@ -0,0 +1,12 @@
1
+ FactoryBot.define do
2
+ factory :egov_utils_user, class: 'EgovUtils::User' do
3
+ firstname { 'John' }
4
+ lastname { 'Doe' }
5
+ login { mail }
6
+ sequence(:mail) {|n| "user#{n}@example.com"}
7
+ password { 'abcdef123456' }
8
+ password_confirmation { 'abcdef123456' }
9
+ active { true }
10
+ roles { [] }
11
+ end
12
+ end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.15
4
+ version: 0.5.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: 2018-09-19 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: bcrypt
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +50,14 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '5.0'
53
+ version: '5.1'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '5.0'
60
+ version: '5.1'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: haml
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +78,14 @@ dependencies:
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '5.0'
81
+ version: '6.0'
76
82
  type: :runtime
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '5.0'
88
+ version: '6.0'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: i18n-js
85
91
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +162,14 @@ dependencies:
156
162
  requirements:
157
163
  - - "~>"
158
164
  - !ruby/object:Gem::Version
159
- version: '2.0'
165
+ version: '3.0'
160
166
  type: :runtime
161
167
  prerelease: false
162
168
  version_requirements: !ruby/object:Gem::Requirement
163
169
  requirements:
164
170
  - - "~>"
165
171
  - !ruby/object:Gem::Version
166
- version: '2.0'
172
+ version: '3.0'
167
173
  - !ruby/object:Gem::Dependency
168
174
  name: money
169
175
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +184,20 @@ dependencies:
178
184
  - - "~>"
179
185
  - !ruby/object:Gem::Version
180
186
  version: '6.11'
187
+ - !ruby/object:Gem::Dependency
188
+ name: therubyracer
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ type: :runtime
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
181
201
  - !ruby/object:Gem::Dependency
182
202
  name: request_store_rails
183
203
  requirement: !ruby/object:Gem::Requirement
@@ -352,14 +372,14 @@ dependencies:
352
372
  requirements:
353
373
  - - "~>"
354
374
  - !ruby/object:Gem::Version
355
- version: '0.3'
375
+ version: '0.4'
356
376
  type: :runtime
357
377
  prerelease: false
358
378
  version_requirements: !ruby/object:Gem::Requirement
359
379
  requirements:
360
380
  - - "~>"
361
381
  - !ruby/object:Gem::Version
362
- version: '0.3'
382
+ version: '0.4'
363
383
  - !ruby/object:Gem::Dependency
364
384
  name: egon_gate
365
385
  requirement: !ruby/object:Gem::Requirement
@@ -388,6 +408,62 @@ dependencies:
388
408
  - - "~>"
389
409
  - !ruby/object:Gem::Version
390
410
  version: '1.6'
411
+ - !ruby/object:Gem::Dependency
412
+ name: database_cleaner-active_record
413
+ requirement: !ruby/object:Gem::Requirement
414
+ requirements:
415
+ - - ">="
416
+ - !ruby/object:Gem::Version
417
+ version: '0'
418
+ type: :development
419
+ prerelease: false
420
+ version_requirements: !ruby/object:Gem::Requirement
421
+ requirements:
422
+ - - ">="
423
+ - !ruby/object:Gem::Version
424
+ version: '0'
425
+ - !ruby/object:Gem::Dependency
426
+ name: factory_bot_rails
427
+ requirement: !ruby/object:Gem::Requirement
428
+ requirements:
429
+ - - "~>"
430
+ - !ruby/object:Gem::Version
431
+ version: '4.0'
432
+ type: :development
433
+ prerelease: false
434
+ version_requirements: !ruby/object:Gem::Requirement
435
+ requirements:
436
+ - - "~>"
437
+ - !ruby/object:Gem::Version
438
+ version: '4.0'
439
+ - !ruby/object:Gem::Dependency
440
+ name: rspec-rails
441
+ requirement: !ruby/object:Gem::Requirement
442
+ requirements:
443
+ - - ">="
444
+ - !ruby/object:Gem::Version
445
+ version: '0'
446
+ type: :development
447
+ prerelease: false
448
+ version_requirements: !ruby/object:Gem::Requirement
449
+ requirements:
450
+ - - ">="
451
+ - !ruby/object:Gem::Version
452
+ version: '0'
453
+ - !ruby/object:Gem::Dependency
454
+ name: pry-rails
455
+ requirement: !ruby/object:Gem::Requirement
456
+ requirements:
457
+ - - ">="
458
+ - !ruby/object:Gem::Version
459
+ version: '0'
460
+ type: :development
461
+ prerelease: false
462
+ version_requirements: !ruby/object:Gem::Requirement
463
+ requirements:
464
+ - - ">="
465
+ - !ruby/object:Gem::Version
466
+ version: '0'
391
467
  - !ruby/object:Gem::Dependency
392
468
  name: sqlite3
393
469
  requirement: !ruby/object:Gem::Requirement
@@ -567,6 +643,10 @@ files:
567
643
  - lib/egov_utils/version.rb
568
644
  - lib/grid/shield_grid.rb
569
645
  - lib/tasks/egov_utils_tasks.rake
646
+ - spec/factories/egov_utils_addresses.rb
647
+ - spec/factories/egov_utils_groups.rb
648
+ - spec/factories/egov_utils_people.rb
649
+ - spec/factories/egov_utils_users.rb
570
650
  - vendor/assets/fonts/Linotype.eot
571
651
  - vendor/assets/fonts/Linotype.ttf
572
652
  - vendor/assets/images/shieldui/editor.png
@@ -689,8 +769,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
689
769
  - !ruby/object:Gem::Version
690
770
  version: '0'
691
771
  requirements: []
692
- rubyforge_project:
693
- rubygems_version: 2.7.7
772
+ rubygems_version: 3.1.6
694
773
  signing_key:
695
774
  specification_version: 4
696
775
  summary: The eGoverment utilities is set of functionalities to support basic eGoverment