decidim-verifications 0.8.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +52 -1
  3. data/app/controllers/decidim/verifications/authorizations_controller.rb +6 -0
  4. data/app/controllers/decidim/verifications/id_documents/authorizations_controller.rb +1 -1
  5. data/app/services/decidim/dummy_authorization_handler.rb +36 -1
  6. data/app/views/decidim/verifications/authorizations/_granted_authorization.html.erb +27 -0
  7. data/app/views/decidim/verifications/authorizations/index.html.erb +8 -13
  8. data/app/views/decidim/verifications/authorizations/new.html.erb +1 -1
  9. data/app/views/dummy_authorization/_form.html.erb +8 -0
  10. data/config/locales/ca.yml +12 -9
  11. data/config/locales/en.yml +4 -0
  12. data/config/locales/es.yml +13 -10
  13. data/config/locales/eu.yml +4 -0
  14. data/config/locales/fi.yml +58 -54
  15. data/config/locales/fr.yml +12 -8
  16. data/config/locales/gl.yml +129 -0
  17. data/config/locales/it.yml +9 -5
  18. data/config/locales/nl.yml +16 -12
  19. data/config/locales/pl.yml +5 -0
  20. data/config/locales/pt-BR.yml +129 -0
  21. data/config/locales/pt.yml +4 -0
  22. data/config/locales/ru.yml +120 -0
  23. data/config/locales/sv.yml +129 -0
  24. data/config/locales/uk.yml +88 -4
  25. data/lib/decidim/verifications.rb +1 -0
  26. data/lib/decidim/verifications/adapter.rb +25 -10
  27. data/lib/decidim/verifications/default_action_authorizer.rb +87 -0
  28. data/lib/decidim/verifications/dummy.rb +2 -0
  29. data/lib/decidim/verifications/registry.rb +4 -0
  30. data/lib/decidim/verifications/version.rb +1 -1
  31. data/lib/decidim/verifications/workflow_manifest.rb +13 -1
  32. data/lib/decidim/verifications/workflows.rb +9 -0
  33. metadata +16 -10
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ class DefaultActionAuthorizer
6
+ #
7
+ # Initializes the DefaultActionAuthorizer class.
8
+ #
9
+ # authorization - The existing authorization record to be evaluated. Can be nil.
10
+ # options - A hash with options related only to the current authorization process.
11
+ #
12
+ def initialize(authorization, options)
13
+ @authorization = authorization
14
+ @options = options.deep_dup # options hash is cloned to allow changes applied to it without risks
15
+ end
16
+
17
+ #
18
+ # Checks the status of the given authorization.
19
+ #
20
+ # Returns:
21
+ # first value - A symbol describing the authorization status.
22
+ # ok - When everything is OK and the user is correctly authorized.
23
+ # missing - When no authorization can be found.
24
+ # expired - The validity time for the given authorization has run out, and
25
+ # needs to be re-validated.
26
+ # pending - When an authorization was found, but is not complete (eg. is
27
+ # waiting for admin manual confirmation).
28
+ # unauthorized - When an authorization was found, but the value of some of its fields
29
+ # is not the expected one (eg. the user is authorized for scope A,
30
+ # but this action is only for users in scope B).
31
+ # incomplete - An authorization was found, but lacks some required fields. User
32
+ # should re-authenticate.
33
+ # last value - A hash with information to be shown to the users.
34
+ # action - Translation key to be used in the "authorize" button. A close button will be shown is missing.
35
+ # cancel - If present and true a cancel button will be shown.
36
+ # fields - Wrong fields to be shown. It could be a list of names or a hash with names a current values.
37
+ # extra_explanation - Hash with an additional key and params to be translated and shown to the user.
38
+ #
39
+ def authorize
40
+ if !authorization
41
+ [:missing, action: :authorize]
42
+ elsif authorization_expired?
43
+ [:expired, action: :authorize]
44
+ elsif !authorization.granted?
45
+ [:pending, action: :resume]
46
+ elsif unmatched_fields.any?
47
+ [:unauthorized, fields: unmatched_fields]
48
+ elsif missing_fields.any?
49
+ [:incomplete, fields: missing_fields, action: :reauthorize, cancel: true]
50
+ else
51
+ [:ok, {}]
52
+ end
53
+ end
54
+
55
+ #
56
+ # Allow to add params to redirect URLs, to modify forms behaviour based on the authorization process options.
57
+ #
58
+ # Returns a hash with keys added to redirect URLs.
59
+ #
60
+ def redirect_params
61
+ {}
62
+ end
63
+
64
+ protected
65
+
66
+ attr_reader :authorization, :options
67
+
68
+ def unmatched_fields
69
+ @unmatched_fields ||= (options.keys & authorization.metadata.to_h.keys).each_with_object({}) do |field, unmatched|
70
+ unmatched[field] = options[field] if authorization.metadata[field] != options[field]
71
+ unmatched
72
+ end
73
+ end
74
+
75
+ def missing_fields
76
+ @missing_fields ||= options.keys.each_with_object([]) do |field, missing|
77
+ missing << field if authorization.metadata[field].blank?
78
+ missing
79
+ end
80
+ end
81
+
82
+ def authorization_expired?
83
+ authorization.expires_at.present? && authorization.expired?
84
+ end
85
+ end
86
+ end
87
+ end
@@ -2,4 +2,6 @@
2
2
 
3
3
  Decidim::Verifications.register_workflow(:dummy_authorization_handler) do |workflow|
4
4
  workflow.form = "Decidim::DummyAuthorizationHandler"
5
+ workflow.action_authorizer = "Decidim::DummyAuthorizationHandler::ActionAuthorizer"
6
+ workflow.expires_in = 1.hour
5
7
  end
@@ -14,6 +14,10 @@ module Decidim
14
14
  add_workflow(manifest)
15
15
  end
16
16
 
17
+ def unregister_workflow(manifest)
18
+ workflow_collection.delete(manifest)
19
+ end
20
+
17
21
  def add_workflow(manifest)
18
22
  manifest.validate!
19
23
  workflow_collection.add(manifest)
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-verifications version.
5
5
  module Verifications
6
6
  def self.version
7
- "0.8.4"
7
+ "0.9.0"
8
8
  end
9
9
  end
10
10
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Decidim
4
4
  module Verifications
5
+ autoload :DefaultActionAuthorizer, "decidim/verifications/default_action_authorizer"
6
+
5
7
  #
6
8
  # This class serves as a DSL to declaratively specify a verification method.
7
9
  #
@@ -28,6 +30,8 @@ module Decidim
28
30
  attribute :engine, Rails::Engine
29
31
  attribute :admin_engine, Rails::Engine
30
32
  attribute :form, String
33
+ attribute :expires_in, ActiveSupport::Duration, default: 0.minutes
34
+ attribute :action_authorizer, String
31
35
 
32
36
  validate :engine_or_form
33
37
 
@@ -45,12 +49,20 @@ module Decidim
45
49
  alias key name
46
50
 
47
51
  def fullname
48
- I18n.t("#{key}.name", scope: "decidim.authorization_handlers")
52
+ I18n.t("#{key}.name", scope: "decidim.authorization_handlers", default: name.humanize)
49
53
  end
50
54
 
51
55
  def description
52
56
  "#{fullname} (#{I18n.t(type, scope: "decidim.authorization_handlers")})"
53
57
  end
58
+
59
+ def action_authorizer_class
60
+ if @action_authorizer.present?
61
+ @action_authorizer.constantize
62
+ else
63
+ DefaultActionAuthorizer
64
+ end
65
+ end
54
66
  end
55
67
  end
56
68
  end
@@ -27,6 +27,15 @@ module Decidim
27
27
  registry.register_workflow(name, &block)
28
28
  end
29
29
 
30
+ #
31
+ # Registers a verification workflow using the workflow manifest API
32
+ #
33
+ def unregister_workflow(name)
34
+ manifest = find_workflow_manifest(name)
35
+
36
+ registry.unregister_workflow(manifest)
37
+ end
38
+
30
39
  #
31
40
  # Finds a verification workflow by name
32
41
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-verifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rodriguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-16 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-core
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.4
19
+ version: 0.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.4
26
+ version: 0.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: decidim-admin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.4
33
+ version: 0.9.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.8.4
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: decidim-dev
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.8.4
47
+ version: 0.9.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.8.4
54
+ version: 0.9.0
55
55
  description: Several verification methods for your decidim instance
56
56
  email:
57
57
  - deivid.rodriguez@riseup.net
@@ -84,6 +84,7 @@ files:
84
84
  - app/services/decidim/authorization_handler.rb
85
85
  - app/services/decidim/dummy_authorization_handler.rb
86
86
  - app/uploaders/decidim/verifications/attachment_uploader.rb
87
+ - app/views/decidim/verifications/authorizations/_granted_authorization.html.erb
87
88
  - app/views/decidim/verifications/authorizations/first_login.html.erb
88
89
  - app/views/decidim/verifications/authorizations/index.html.erb
89
90
  - app/views/decidim/verifications/authorizations/new.html.erb
@@ -94,21 +95,26 @@ files:
94
95
  - app/views/decidim/verifications/postal_letter/admin/pending_authorizations/index.html.erb
95
96
  - app/views/decidim/verifications/postal_letter/authorizations/edit.html.erb
96
97
  - app/views/decidim/verifications/postal_letter/authorizations/new.html.erb
98
+ - app/views/dummy_authorization/_form.html.erb
97
99
  - config/locales/ca.yml
98
100
  - config/locales/en.yml
99
101
  - config/locales/es.yml
100
102
  - config/locales/eu.yml
101
103
  - config/locales/fi.yml
102
104
  - config/locales/fr.yml
105
+ - config/locales/gl.yml
103
106
  - config/locales/it.yml
104
107
  - config/locales/nl.yml
105
108
  - config/locales/pl.yml
109
+ - config/locales/pt-BR.yml
106
110
  - config/locales/pt.yml
107
111
  - config/locales/ru.yml
112
+ - config/locales/sv.yml
108
113
  - config/locales/uk.yml
109
114
  - db/migrate/20171030133426_move_authorizations_to_new_api.rb
110
115
  - lib/decidim/verifications.rb
111
116
  - lib/decidim/verifications/adapter.rb
117
+ - lib/decidim/verifications/default_action_authorizer.rb
112
118
  - lib/decidim/verifications/dummy.rb
113
119
  - lib/decidim/verifications/engine.rb
114
120
  - lib/decidim/verifications/id_documents.rb
@@ -145,8 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
151
  version: '0'
146
152
  requirements: []
147
153
  rubyforge_project:
148
- rubygems_version: 2.6.13
154
+ rubygems_version: 2.7.3
149
155
  signing_key:
150
156
  specification_version: 4
151
- summary: Verifications plugin for decidim
157
+ summary: Decidim verifications module
152
158
  test_files: []