decidim-verifications 0.10.1 → 0.11.0.pre1

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: 6a777c1d628a37d090f6b14dfb8a82131d9b13da467becba8ca6bfcf0286fda5
4
- data.tar.gz: 1700efb415b236ec0dd711960a9dec088ea6a94af9a3b77fea5a55871f39b570
3
+ metadata.gz: 916479beee76ee479c05f1660f025e0bc933d484799b0f6049de9227c7733cd5
4
+ data.tar.gz: 0246bf40ca64fdd09069b696ae5115e8a0d4ca8580ed8ec35a235f62be8dd4d5
5
5
  SHA512:
6
- metadata.gz: b9045849b1e4ab203bd3d923f7a0c04e3f9ca26c97f17632516616fd3c4d0281fc99fb164cd4a9eee93528509e5db3086d9396c094cb2fd777527ada4ad6c502
7
- data.tar.gz: 14952692f3b960ac7beda6673bc7e498066268c2d821fda29cea93d8855f85ed8c7dc5bae3fe7a241a0c3c16399232716ea02cae4eb027b84106c098353ff948
6
+ metadata.gz: db7fd1c693a97d658f586e4adc3cb416d7cb6887e0ad6154e674a3918384e1fea729ae6a28674d201a50a626df1bb2b759d19cde07c67f0738f55ea28935a30d
7
+ data.tar.gz: 3b7c4d7946c1e1dc8f96700bbcdba50792398cdda7b960b4e3c2b9c5ed2cc48dec63954c0a051c6325b88f11d9548b6449ac0369fe71b9b84f50245d753e94d3
data/README.md CHANGED
@@ -77,10 +77,10 @@ Decidim implements two type of authorization methods:
77
77
 
78
78
  ## Custom action authorizers
79
79
 
80
- Custom action authorizers are an advanced feature that can be used in both types of
80
+ Custom action authorizers are an advanced component that can be used in both types of
81
81
  authorization methods to customize some parts of the authorization process.
82
82
  These are particulary useful when used within verification options, which are
83
- set in the admin zone related to a feature action. As a result, a verification
83
+ set in the admin zone related to a component action. As a result, a verification
84
84
  method will be allowed to change the authorization logic and the appearance based
85
85
  on the context where the authorization is being performed.
86
86
 
@@ -18,44 +18,16 @@ module Decidim
18
18
  #
19
19
  # Returns nothing.
20
20
  def call
21
- return broadcast(:invalid) unless handler.valid? && unique?
21
+ return broadcast(:invalid) unless handler.valid?
22
+
23
+ Authorization.create_or_update_from(handler)
22
24
 
23
- create_authorization
24
25
  broadcast(:ok)
25
26
  end
26
27
 
27
28
  private
28
29
 
29
30
  attr_reader :handler
30
-
31
- def create_authorization
32
- authorization = Authorization.find_or_initialize_by(
33
- user: handler.user,
34
- name: handler.handler_name
35
- )
36
-
37
- authorization.attributes = {
38
- unique_id: handler.unique_id,
39
- metadata: handler.metadata
40
- }
41
-
42
- authorization.grant!
43
- end
44
-
45
- def unique?
46
- return true if handler.unique_id.nil?
47
-
48
- duplicates = Authorization.where(
49
- user: User.where.not(id: handler.user.id).where(organization: handler.user.organization.id),
50
- name: handler.handler_name,
51
- unique_id: handler.unique_id
52
- )
53
-
54
- return true unless duplicates.any?
55
-
56
- handler.errors.add(:base, I18n.t("decidim.authorization_handlers.errors.duplicate_authorization"))
57
- false
58
- end
59
31
  end
60
32
  end
61
33
  end
@@ -20,6 +20,8 @@ module Decidim
20
20
  # infer the class name of the authorization handler.
21
21
  attribute :handler_name, String
22
22
 
23
+ validate :uniqueness
24
+
23
25
  # A unique ID to be implemented by the authorization handler that ensures
24
26
  # no duplicates are created. This uniqueness check will be skipped if
25
27
  # unique_id returns nil.
@@ -108,5 +110,23 @@ module Decidim
108
110
 
109
111
  manifest.form.constantize.from_params(params || {})
110
112
  end
113
+
114
+ private
115
+
116
+ def duplicates
117
+ Authorization.where(
118
+ user: User.where.not(id: user.id).where(organization: user.organization),
119
+ name: handler_name,
120
+ unique_id: unique_id
121
+ )
122
+ end
123
+
124
+ def uniqueness
125
+ return true if unique_id.nil? || duplicates.none?
126
+
127
+ errors.add(:base, I18n.t("decidim.authorization_handlers.errors.duplicate_authorization"))
128
+
129
+ false
130
+ end
111
131
  end
112
132
  end
@@ -17,10 +17,11 @@
17
17
  <%= render partial: handler.to_partial_path, locals: { handler: handler, form: form } %>
18
18
  <% else %>
19
19
  <%= form.all_fields %>
20
- <div class="actions">
21
- <%= form.submit t(".authorize"), class: "button expanded" %>
22
- </div>
23
20
  <% end %>
21
+
22
+ <div class="actions">
23
+ <%= form.submit t(".authorize"), class: "button expanded" %>
24
+ </div>
24
25
  <% end %>
25
26
  <p class="text-center skip">
26
27
  <%= t("decidim.verifications.authorizations.skip_verification", link: link_to(t("decidim.verifications.authorizations.start_exploring"), cta_button_path).html_safe).html_safe %>.
@@ -1,6 +1,6 @@
1
1
  <div class="wrapper">
2
2
  <div class="row column">
3
- <div class="callout announcement <%= authorization.rejected? ? 'alert' : 'secondary' %>">
3
+ <div class="callout announcement <%= authorization.rejected? ? "alert" : "secondary" %>">
4
4
  <div class="row">
5
5
  <div class="columns medium-8 large-9">
6
6
  <% if authorization.rejected? %>
@@ -1,8 +1,8 @@
1
1
  <% if request["postal_codes"]
2
- postal_codes = request["postal_codes"].split("-")%>
2
+ postal_codes = request["postal_codes"].split("-") %>
3
3
  <p><%= t("extra_explanation", scope: "decidim.verifications.dummy_authorization", postal_codes: postal_codes.join(", "), count: postal_codes.count) %></p>
4
4
  <% end %>
5
- <%= form.all_fields %>
6
- <div class="actions partial-demo">
7
- <%= form.submit t("decidim.verifications.authorizations.new.authorize"), class: "button expanded" %>
8
- </div>
5
+
6
+ <div class="partial-demo">
7
+ <%= form.all_fields %>
8
+ </div>
@@ -8,7 +8,7 @@ fr:
8
8
  document_number: Numéro de document (avec lettre)
9
9
  document_type: Type de votre document
10
10
  user: Utilisateur
11
- verification_attachment: Copie scannée de votre document
11
+ verification_attachment: Copie scannée du document
12
12
  postal_letter_address:
13
13
  full_address: Adresse complète
14
14
  postal_letter_confirmation:
@@ -35,7 +35,7 @@ fr:
35
35
  - Vous marquez la lettre comme envoyée.
36
36
  - Une fois que vous avez coché la lettre, l'utilisateur sera en mesure de présenter le code et d'être vérifié.
37
37
  direct: Direct
38
- help: Aidez-moi
38
+ help: Texte d'aide
39
39
  id_documents:
40
40
  explanation: Téléchargez vos documents d'identité afin que nous puissions vérifier votre identité
41
41
  name: Documents d'identité
@@ -12,10 +12,10 @@ nl:
12
12
  postal_letter_address:
13
13
  full_address: Volledig adres
14
14
  postal_letter_confirmation:
15
- verification_code: Verificatie code
15
+ verification_code: Verificatiecode
16
16
  postal_letter_postage:
17
17
  full_address: Volledig adres
18
- verification_code: Verificatie code
18
+ verification_code: Verificatiecode
19
19
  decidim:
20
20
  admin:
21
21
  menu:
@@ -64,7 +64,7 @@ nl:
64
64
  start_exploring: begin met verkennen
65
65
  dummy_authorization:
66
66
  extra_explanation:
67
- one: Deelname is beperkt tot gebruikers met de postcode %{postal_codes}.
67
+ one: Deelname is beperkt tot gebruikers met postcode %{postal_codes}.
68
68
  other: 'Deelname is beperkt tot gebruikers met een van de volgende postcodes: %{postal_codes}.'
69
69
  id_documents:
70
70
  admin:
@@ -22,8 +22,8 @@ class MoveAuthorizationsToNewApi < ActiveRecord::Migration[5.1]
22
22
  self.table_name = :decidim_organizations
23
23
  end
24
24
 
25
- class Feature < ApplicationRecord
26
- self.table_name = :decidim_features
25
+ class Component < ApplicationRecord
26
+ self.table_name = :decidim_components
27
27
  end
28
28
 
29
29
  def up
@@ -35,10 +35,10 @@ class MoveAuthorizationsToNewApi < ActiveRecord::Migration[5.1]
35
35
  organization.update!(available_authorizations: migrated_authorizations)
36
36
  end
37
37
 
38
- Feature.find_each do |feature|
39
- next if feature.permissions.nil?
38
+ Component.find_each do |component|
39
+ next if component.permissions.nil?
40
40
 
41
- feature.permissions.transform_values! do |value|
41
+ component.permissions.transform_values! do |value|
42
42
  next if value.nil?
43
43
 
44
44
  {
@@ -47,7 +47,7 @@ class MoveAuthorizationsToNewApi < ActiveRecord::Migration[5.1]
47
47
  }
48
48
  end
49
49
 
50
- feature.save!
50
+ component.save!
51
51
  end
52
52
  end
53
53
 
@@ -60,14 +60,14 @@ class MoveAuthorizationsToNewApi < ActiveRecord::Migration[5.1]
60
60
  organization.update!(available_authorizations: migrated_authorizations)
61
61
  end
62
62
 
63
- Feature.find_each do |feature|
64
- feature.permissions.transform_values! do |value|
63
+ Component.find_each do |component|
64
+ component.permissions.transform_values! do |value|
65
65
  workflow = Decidim::Verifications.find_workflow_manifest(value)
66
66
 
67
67
  workflow.form.underscore
68
68
  end
69
69
 
70
- feature.save!
70
+ component.save!
71
71
  end
72
72
  end
73
73
  end
@@ -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.10.1"
7
+ "0.11.0.pre1"
8
8
  end
9
9
  end
10
10
  end
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.10.1
4
+ version: 0.11.0.pre1
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-04-17 00:00:00.000000000 Z
11
+ date: 2018-04-26 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.10.1
19
+ version: 0.11.0.pre1
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.10.1
26
+ version: 0.11.0.pre1
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.10.1
33
+ version: 0.11.0.pre1
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.10.1
40
+ version: 0.11.0.pre1
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.10.1
47
+ version: 0.11.0.pre1
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.10.1
54
+ version: 0.11.0.pre1
55
55
  description: Several verification methods for your decidim instance
56
56
  email:
57
57
  - deivid.rodriguez@riseup.net
@@ -146,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - ">="
149
+ - - ">"
150
150
  - !ruby/object:Gem::Version
151
- version: '0'
151
+ version: 1.3.1
152
152
  requirements: []
153
153
  rubyforge_project:
154
154
  rubygems_version: 2.7.3