egov_utils 0.1.19 → 0.1.23

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: 32bbbdd34a0a8981f2000387b993c342e209e88237a230a85ea2262a4d515aa3
4
- data.tar.gz: 2da793eaa12459a2cde485f4f849aaf342ab0f2aa4a21a031b8859540fa3e734
3
+ metadata.gz: b4a1277bc53acada48031d6bca281ce875e4f937b8e86ad3e05588ad7c2e3201
4
+ data.tar.gz: 69e8697534f1b8398739b9578f337a294b4c07455c94e0c89505f9f511a804f6
5
5
  SHA512:
6
- metadata.gz: 95f36315e2c902ea4ff7acd9936ffaa0a04a8b8e4935ddcff4fe3ffd54c9d84e9233faa257ecf5ab0cba108d24f912f56126771502f5c930b7a364d22f6d0535
7
- data.tar.gz: f4f497a24f9024f01213dd3375fd65828a2a84e86bea6aa1c7436436eeb1feeeec9fe60eaca1a9a0d2395edd5ca4989a58bacab1e46aeb0bacfcf8b18ea3c31b
6
+ metadata.gz: d34e4b723a3c007cf2eb5c4bbd494af079f5e520c72d8fd80ddd09b5431d78b088fbcea6ee6c73a87cfee0179a4ff8d7d945a3da31eeed3a63da96c0f01377bf
7
+ data.tar.gz: 9aef7643e96b238fcee2a0d1ead31b43889c9f0e9ff261bcd69a26cf657e3ac3c6891a11b86df8fd252229e9ddec75ebe9fdf44a3a1271a65de38638bfc35e0b
@@ -21,7 +21,7 @@ module EgovUtils
21
21
  @user.mail ||= @user.login
22
22
  respond_to do |format|
23
23
  if @user.save
24
- UserMailer.confirmation_email(@user).deliver_later unless current_user.logged?
24
+ UserMailer.confirmation_email(@user).deliver_later if EgovUtils::Settings.allow_register? && !current_user.logged?
25
25
  format.html{ redirect_to main_app.root_path, notice: t('activerecord.successful.messages.created', model: User.model_name.human) }
26
26
  format.json{ render json: @user, status: :created }
27
27
  else
@@ -12,6 +12,8 @@ class Ability
12
12
  include CanCan::Ability
13
13
 
14
14
  def initialize(user)
15
+ can :create, User if EgovUtils::Settings.allow_register?
16
+
15
17
  user.all_roles.each do |role|
16
18
  role.define_abilities(self, user)
17
19
  end
@@ -1,8 +1,11 @@
1
+ require 'activeresource'
2
+
1
3
  module EgovUtils
2
- class Love < ActiveResource::Base
4
+ class Love < ::ActiveResource::Base
3
5
 
4
6
  def self.config
5
- YAML.load_file(Rails.root.join('config', 'config.yml'))
7
+ file = Rails.root.join('config', 'config.yml')
8
+ File.exists?(file) ? YAML.load_file(file) : {}
6
9
  end
7
10
 
8
11
  self.site = "#{config['love_url'] || Rails.configuration.try(:love_url)}/api/v1/"
@@ -5,7 +5,7 @@ module EgovUtils
5
5
  where(key: key).first
6
6
  end
7
7
 
8
- def self.courts(organization_keys)
8
+ def self.courts(organization_keys=nil)
9
9
  filters = {category_abbrev: ['OS','KS']}
10
10
  filters.merge!(key: organization_keys) if organization_keys.present?
11
11
  all(params: {f: filters, sort: {'0' => {path: 'category_abbrev'} }})
@@ -1,8 +1,19 @@
1
1
  class FileuidValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
3
  return if options[:allow_nil] && value.presence.nil?
4
- unless value =~ /\A\d+-\w{1,4}-\d+\/\d{4}\z/i
4
+ if value.is_a?(EgovUtils::Fileuid)
5
+ record.errors.add(attribute, (options[:message] || :fileuid_format)) if value.invalid?
6
+ elsif !match_regexp?(record, attribute, value)
5
7
  record.errors.add(attribute, (options[:message] || :fileuid_format))
6
8
  end
7
9
  end
10
+
11
+ def match_regexp?(record, attribute, value)
12
+ type = nil
13
+ if type
14
+ value =~ EgovUtils::Fileuid::TYPES[type].to_regex
15
+ else
16
+ EgovUtils::Fileuid::TYPES.values.any?{|type_def| value =~ type_def.to_regex }
17
+ end
18
+ end
8
19
  end
@@ -2,4 +2,5 @@
2
2
  = f.text_field(:username)
3
3
  = f.password_field(:password)
4
4
  = f.submit t(:label_login)
5
- = link_to t('label_signup'), new_user_path, class: 'btn btn-secondary'
5
+ - if EgovUtils::Settings.allow_register?
6
+ = link_to t('label_signup'), new_user_path, class: 'btn btn-secondary'
@@ -6,6 +6,7 @@ module BootstrapForm
6
6
  def fileuid_field(method, options={})
7
7
  form_group_builder(method, options) do
8
8
  prepend_and_append_input(options) do
9
+ binding.pry
9
10
  @template.fileuid_field(@object_name, method, objectify_options(options))
10
11
  end
11
12
  end
data/lib/egov_utils.rb CHANGED
@@ -4,6 +4,8 @@ require 'bootstrap'
4
4
  require 'bootstrap_form'
5
5
  require 'momentjs-rails'
6
6
 
7
+ require 'egov_utils/fileuid'
8
+
7
9
  require "egov_utils/engine"
8
10
 
9
11
  module EgovUtils
@@ -23,6 +23,10 @@ module EgovUtils
23
23
  end
24
24
  end
25
25
 
26
+ initializer 'egov_utils.initialize_settings' do
27
+ require 'egov_utils/settings'
28
+ end
29
+
26
30
  initializer 'egov_utils.set_locales' do
27
31
  config.middleware.use I18n::JS::Middleware
28
32
  end
@@ -0,0 +1,159 @@
1
+ module EgovUtils
2
+ class Fileuid
3
+
4
+ Snippet = Struct.new(:name, :type, :length, :mandatory) do
5
+
6
+ def mandatory?
7
+ mandatory.nil? ? true : mandatory
8
+ end
9
+
10
+ def static?
11
+ type == :static
12
+ end
13
+
14
+ def type_to_regex_part
15
+ case type
16
+ when String
17
+ type
18
+ when :integer
19
+ "\\d"
20
+ when :word
21
+ "\\w"
22
+ when :static
23
+ name
24
+ else
25
+ raise "Unsuported fileuid snippet type #{type}"
26
+ end
27
+ end
28
+
29
+ def length_to_regex_part
30
+ case length
31
+ when 1, nil
32
+ ''
33
+ when :any
34
+ mandatory? ? "+" : "*"
35
+ when Array
36
+ "{#{length[0]},#{length[1]}}"
37
+ when Numeric
38
+ "{#{length}}"
39
+ else
40
+ length
41
+ end
42
+ end
43
+
44
+ def to_regex_s
45
+ type_to_regex_part + length_to_regex_part
46
+ end
47
+ end
48
+
49
+ class Type
50
+ attr_reader :snippets
51
+
52
+ def initialize(*attrs)
53
+ @snippets = attrs
54
+ end
55
+
56
+ def snippet_names
57
+ snippets.select{|s| !s.static? }.collect{|s| s.name}
58
+ end
59
+
60
+ def validate!
61
+ raise "Snippet names for file uid type has to be uniq!" unless snippet_names.length == snippet_names.uniq.length
62
+ end
63
+
64
+ def to_regex_s
65
+ snippets.collect{|s| (s.type == :static ? s.to_regex_s : "(#{s.to_regex_s})") }.join()
66
+ end
67
+
68
+ def to_regex
69
+ /\A#{to_regex_s}\z/
70
+ end
71
+
72
+ def file_uid_to_s(fileuid)
73
+ snippets.collect{|snippet| snippet.static? ? snippet.name : fileuid.public_send(snippet.name) }.join
74
+ end
75
+
76
+ end
77
+
78
+ DASH_SNIPPET = Snippet.new('-', :static)
79
+ SLASH_SNIPPET = Snippet.new('/', :static)
80
+ BC_SNIPPET = Snippet.new('bc', :integer, :any)
81
+ YEAR_SNIPPET = Snippet.new('year', :integer, 4)
82
+ REGISTER_SNIPPET = Snippet.new('agenda', '[-a-zA-Z]', [1,10])
83
+ COURT_AGEND_SNIPPET = Snippet.new('agenda', :word, [1,4])
84
+ COURT_SENAT_SNIPPET = Snippet.new('senat', :integer, :any)
85
+
86
+ TYPES = {
87
+ 'court' => Type.new(BC_SNIPPET, DASH_SNIPPET, COURT_AGEND_SNIPPET, DASH_SNIPPET, COURT_SENAT_SNIPPET, SLASH_SNIPPET, YEAR_SNIPPET),
88
+ 'msp' => Type.new(BC_SNIPPET, SLASH_SNIPPET, YEAR_SNIPPET, DASH_SNIPPET, REGISTER_SNIPPET)
89
+ }
90
+
91
+ # Used for `serialize` method in ActiveRecord
92
+ class << self
93
+ def dump(fileuid)
94
+ unless obj.is_a?(self)
95
+ raise ::ActiveRecord::SerializationTypeMismatch,
96
+ "Attribute was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}"
97
+ end
98
+ fileuid.invalid? ? nil : to_s
99
+ end
100
+
101
+ def load(source)
102
+ Fileuid.new(source)
103
+ end
104
+ end
105
+
106
+ attr_accessor :bc, :agenda, :senat, :year, :document_number
107
+
108
+
109
+ def type
110
+ @type ||= @options['type']
111
+ end
112
+
113
+ def type_definition
114
+ TYPES[type]
115
+ end
116
+
117
+ def invalid?
118
+ @invalid
119
+ end
120
+
121
+ def initialize(str_val, **options)
122
+ @options = options.stringify_keys
123
+ parse_str!(str_val) if str_val.is_a?(String)
124
+ end
125
+
126
+ def parse_str!(str_val, type=self.type)
127
+ type ||= determine_type(str_val)
128
+ @type = type
129
+ @invalid = true unless type
130
+ return if invalid?
131
+ match_data = str_val.match(type_definition.to_regex)
132
+ if match_data
133
+ type_definition.snippet_names.each_with_index{|s_name, idx| self.send(s_name+'=', match_data[idx+1]) }
134
+ else
135
+ @invalid = true
136
+ end
137
+ end
138
+
139
+ def determine_type(str_val)
140
+ TYPES.each do |k, type|
141
+ return k if str_val =~ type.to_regex
142
+ end
143
+ @invalid = true
144
+ end
145
+
146
+ def as_json(**options)
147
+ invalid? ? nil : to_s
148
+ end
149
+
150
+ def to_s
151
+ if invalid?
152
+ ''
153
+ else
154
+ type_definition.file_uid_to_s(self)
155
+ end
156
+ end
157
+
158
+ end
159
+ end
@@ -0,0 +1,22 @@
1
+ require 'settingslogic'
2
+
3
+ module EgovUtils
4
+
5
+ def self.config_file
6
+ ENV.fetch('EGOVUTILS_CONFIG') { Rails.root.join('config', 'config.yml') }
7
+ end
8
+
9
+ class Settings < ::Settingslogic
10
+ source (File.exists?(EgovUtils.config_file) ? EgovUtils.config_file : {})
11
+
12
+ # namespace Rails.env
13
+
14
+ def allow_register?
15
+ allow_register
16
+ end
17
+
18
+ end
19
+
20
+ Settings['allow_register'] ||= false
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.1.19'
2
+ VERSION = '0.1.23'
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.19
4
+ version: 0.1.23
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-12-05 00:00:00.000000000 Z
11
+ date: 2017-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '2.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: settingslogic
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: activeresource
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '5.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '5.0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: jquery-rails
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -254,28 +282,28 @@ dependencies:
254
282
  requirements:
255
283
  - - "~>"
256
284
  - !ruby/object:Gem::Version
257
- version: 0.1.0
285
+ version: '0.1'
258
286
  type: :runtime
259
287
  prerelease: false
260
288
  version_requirements: !ruby/object:Gem::Requirement
261
289
  requirements:
262
290
  - - "~>"
263
291
  - !ruby/object:Gem::Version
264
- version: 0.1.0
292
+ version: '0.1'
265
293
  - !ruby/object:Gem::Dependency
266
294
  name: egon_gate
267
295
  requirement: !ruby/object:Gem::Requirement
268
296
  requirements:
269
297
  - - "~>"
270
298
  - !ruby/object:Gem::Version
271
- version: 0.1.0
299
+ version: '0.1'
272
300
  type: :runtime
273
301
  prerelease: false
274
302
  version_requirements: !ruby/object:Gem::Requirement
275
303
  requirements:
276
304
  - - "~>"
277
305
  - !ruby/object:Gem::Version
278
- version: 0.1.0
306
+ version: '0.1'
279
307
  - !ruby/object:Gem::Dependency
280
308
  name: sqlite3
281
309
  requirement: !ruby/object:Gem::Requirement
@@ -391,9 +419,11 @@ files:
391
419
  - lib/egov_utils.rb
392
420
  - lib/egov_utils/auth_source.rb
393
421
  - lib/egov_utils/engine.rb
422
+ - lib/egov_utils/fileuid.rb
394
423
  - lib/egov_utils/has_audit_trail.rb
395
424
  - lib/egov_utils/helpers/form_helper.rb
396
425
  - lib/egov_utils/helpers/tags/fileuid_field.rb
426
+ - lib/egov_utils/settings.rb
397
427
  - lib/egov_utils/test_utils/controller_helpers.rb
398
428
  - lib/egov_utils/user_utils/application_controller_patch.rb
399
429
  - lib/egov_utils/user_utils/role.rb