decidim-verifications 0.27.9 → 0.28.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -26
- data/app/cells/decidim/verifications/revocations/show.erb +18 -16
- data/app/commands/decidim/verifications/authorize_user.rb +24 -3
- data/app/commands/decidim/verifications/confirm_user_authorization.rb +1 -1
- data/app/commands/decidim/verifications/csv_census/admin/create_census_data.rb +1 -1
- data/app/commands/decidim/verifications/id_documents/admin/confirm_user_offline_authorization.rb +1 -1
- data/app/commands/decidim/verifications/perform_authorization_step.rb +1 -1
- data/app/commands/decidim/verifications/revoke_all_authorizations.rb +2 -2
- data/app/commands/decidim/verifications/revoke_by_condition_authorizations.rb +3 -3
- data/app/controllers/concerns/decidim/verifications/renewable.rb +2 -2
- data/app/controllers/decidim/verifications/application_controller.rb +3 -0
- data/app/controllers/decidim/verifications/authorizations_controller.rb +20 -4
- data/app/controllers/decidim/verifications/id_documents/authorizations_controller.rb +6 -6
- data/app/controllers/decidim/verifications/sms/authorizations_controller.rb +7 -11
- data/app/events/decidim/verifications/managed_user_error_event.rb +3 -8
- data/app/forms/decidim/verifications/id_documents/information_form.rb +4 -8
- data/app/forms/decidim/verifications/postal_letter/postage_form.rb +1 -1
- data/app/forms/decidim/verifications/sms/mobile_phone_form.rb +7 -3
- data/app/helpers/decidim/verifications/application_helper.rb +91 -0
- data/app/jobs/decidim/verifications/csv_census/application_job.rb +1 -1
- data/app/jobs/decidim/verifications/csv_census/remove_duplicates_job.rb +1 -1
- data/app/models/decidim/verifications/csv_census/data.rb +1 -1
- data/app/models/decidim/verifications/csv_datum.rb +3 -3
- data/app/packs/entrypoints/decidim_verifications.js +2 -0
- data/app/packs/stylesheets/verifications.scss +58 -0
- data/app/presenters/decidim/verifications/postal_letter/authorization_presenter.rb +1 -1
- data/app/queries/decidim/verifications/authorizations.rb +2 -2
- data/app/services/decidim/authorization_handler.rb +45 -13
- data/app/views/decidim/verifications/authorizations/_item.html.erb +31 -0
- data/app/views/decidim/verifications/authorizations/first_login.html.erb +20 -21
- data/app/views/decidim/verifications/authorizations/index.html.erb +28 -73
- data/app/views/decidim/verifications/authorizations/new.html.erb +27 -29
- data/app/views/decidim/verifications/authorizations/renew_modal.html.erb +23 -30
- data/app/views/decidim/verifications/csv_census/admin/census/index.html.erb +54 -39
- data/app/views/decidim/verifications/csv_census/admin/census/instructions.html.erb +3 -2
- data/app/views/decidim/verifications/id_documents/admin/config/edit.html.erb +30 -21
- data/app/views/decidim/verifications/id_documents/admin/confirmations/new.html.erb +38 -22
- data/app/views/decidim/verifications/id_documents/admin/offline_confirmations/new.html.erb +39 -21
- data/app/views/decidim/verifications/id_documents/admin/pending_authorizations/index.html.erb +4 -4
- data/app/views/decidim/verifications/id_documents/authorizations/_form.html.erb +4 -10
- data/app/views/decidim/verifications/id_documents/authorizations/choose.html.erb +10 -19
- data/app/views/decidim/verifications/id_documents/authorizations/edit.html.erb +32 -41
- data/app/views/decidim/verifications/id_documents/authorizations/new.html.erb +19 -25
- data/app/views/decidim/verifications/postal_letter/admin/pending_authorizations/index.html.erb +53 -48
- data/app/views/decidim/verifications/postal_letter/authorizations/edit.html.erb +32 -34
- data/app/views/decidim/verifications/postal_letter/authorizations/new.html.erb +20 -25
- data/app/views/decidim/verifications/sms/authorizations/edit.html.erb +25 -34
- data/app/views/decidim/verifications/sms/authorizations/new.html.erb +20 -25
- data/app/views/dummy_authorization/_form.html.erb +6 -16
- data/app/views/layouts/decidim/authorizations.html.erb +8 -0
- data/config/assets.rb +8 -0
- data/config/locales/ar.yml +3 -50
- data/config/locales/bg.yml +4 -266
- data/config/locales/ca.yml +46 -39
- data/config/locales/cs.yml +48 -41
- data/config/locales/de.yml +44 -37
- data/config/locales/el.yml +3 -59
- data/config/locales/en.yml +52 -45
- data/config/locales/es-MX.yml +47 -40
- data/config/locales/es-PY.yml +47 -40
- data/config/locales/es.yml +46 -39
- data/config/locales/eu.yml +51 -44
- data/config/locales/fi-plain.yml +48 -41
- data/config/locales/fi.yml +48 -41
- data/config/locales/fr-CA.yml +50 -43
- data/config/locales/fr.yml +50 -43
- data/config/locales/ga-IE.yml +2 -1
- data/config/locales/gl.yml +3 -59
- data/config/locales/hu.yml +48 -43
- data/config/locales/id-ID.yml +3 -50
- data/config/locales/is-IS.yml +3 -22
- data/config/locales/it.yml +3 -59
- data/config/locales/ja.yml +50 -43
- data/config/locales/lt.yml +43 -35
- data/config/locales/lv.yml +1 -58
- data/config/locales/nl.yml +3 -59
- data/config/locales/no.yml +3 -59
- data/config/locales/pl.yml +3 -80
- data/config/locales/pt-BR.yml +3 -66
- data/config/locales/pt.yml +3 -59
- data/config/locales/ro-RO.yml +7 -59
- data/config/locales/ru.yml +3 -28
- data/config/locales/sk.yml +3 -58
- data/config/locales/sv.yml +7 -62
- data/config/locales/tr-TR.yml +3 -60
- data/config/locales/uk.yml +3 -28
- data/config/locales/zh-CN.yml +3 -59
- data/config/locales/zh-TW.yml +33 -25
- data/lib/decidim/verifications/adapter.rb +7 -7
- data/lib/decidim/verifications/csv_census/workflow.rb +1 -0
- data/lib/decidim/verifications/id_documents/workflow.rb +1 -0
- data/lib/decidim/verifications/postal_letter/workflow.rb +1 -0
- data/lib/decidim/verifications/sms/engine.rb +2 -1
- data/lib/decidim/verifications/sms/example_gateway.rb +3 -2
- data/lib/decidim/verifications/test/factories.rb +2 -8
- data/lib/decidim/verifications/version.rb +1 -1
- data/lib/decidim/verifications/workflow_manifest.rb +2 -1
- data/lib/decidim/verifications/workflows.rb +2 -2
- data/lib/decidim/verifications.rb +0 -7
- metadata +26 -18
- data/app/views/decidim/verifications/authorizations/_granted_authorization.html.erb +0 -32
- data/config/locales/he-IL.yml +0 -1
- data/decidim-verifications.gemspec +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d574f40b14986769c25f347b3bc46bfc7e19a06577a3dac59384349e5a380f55
|
4
|
+
data.tar.gz: 65b590670019b724db73d1038831c96c476317c0c0b482de99167f006eaa5940
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf792deee667c252694c6e8295ea9765ccb45b6d6e37dae1446d4379e6b578c6e0fd7a7ce71877c0588022b603841d0e56ab45642baf688770caf9dcfda1fa8
|
7
|
+
data.tar.gz: fe4351968ccadc6d40d81f74b5de6eb5fd489436f8dd018dca8637aa822f52a6e3917551094741e1b08a5e963bc535d094ec4473f18a3a5cc5baafa8b333217b
|
data/README.md
CHANGED
@@ -47,7 +47,7 @@ Decidim implements two type of authorization methods:
|
|
47
47
|
to implement it. "Simple" here means that the authorization can be granted
|
48
48
|
with the submission of a single form. For example, to validate a user against
|
49
49
|
a census API you will need a form with some fields that your users will use to
|
50
|
-
authenticate against a census (for example, an ID and a Postal Code). You
|
50
|
+
authenticate against a census (for example, an ID and a Postal Code). You will
|
51
51
|
implement this with a form class. See the documentation for the [parent
|
52
52
|
class][authorization handler base class] or have a look at some live examples,
|
53
53
|
such as:
|
@@ -98,7 +98,7 @@ Decidim implements two type of authorization methods:
|
|
98
98
|
authorization process.
|
99
99
|
|
100
100
|
* _Renewable authorizations_.
|
101
|
-
By default a participant
|
101
|
+
By default a participant cannot renew its authorization, but this can be enabled when registering the workflow, the time between renewals can be configured (one day by default).
|
102
102
|
|
103
103
|
Optionally to change the renew modal content part of the data stored, you can set a new value for the cell used to render the metadata.
|
104
104
|
|
@@ -113,28 +113,6 @@ Decidim implements two type of authorization methods:
|
|
113
113
|
end
|
114
114
|
```
|
115
115
|
|
116
|
-
### Identification numbers
|
117
|
-
|
118
|
-
For the verification of the participants' data in Verifications, you can configure which type of documents a participant can have. By default these documents are `identification_number` and `passport`, but in some countries you may need to adapt these to your region or governmental specific needs. For instance, in Spain there are `dni`, `nie` and `passport`.
|
119
|
-
|
120
|
-
For configuring these you can do so with the Environment Variable `VERIFICATIONS_DOCUMENT_TYPES`.
|
121
|
-
|
122
|
-
```env
|
123
|
-
VERIFICATIONS_DOCUMENT_TYPES="dni,nie,passport"
|
124
|
-
```
|
125
|
-
|
126
|
-
You need to also add the following keys in your i18n files (i.e. `config/locales/en.yml`). By default in the verifications, `indentification_number` is currently being used as a universal example. Below are examples of adding `dni`, `nie` and `passport` locally used in Spain.
|
127
|
-
|
128
|
-
```yaml
|
129
|
-
en:
|
130
|
-
decidim:
|
131
|
-
verifications:
|
132
|
-
id_documents:
|
133
|
-
dni: DNI
|
134
|
-
nie: NIE
|
135
|
-
passport: Passport
|
136
|
-
```
|
137
|
-
|
138
116
|
### SMS verification
|
139
117
|
|
140
118
|
Decidim comes with a verification workflow designed to verify users by sending
|
@@ -148,7 +126,7 @@ In order to setup Decidim with SMS verification you need to:
|
|
148
126
|
1. Create a class that accepts two parameters when initializing it (mobile phone and code) and a method named `deliver_code` that will send an SMS and return a truthy or falsey value if the delivery was OK or not.
|
149
127
|
1. Set the `sms_gateway_service` configuration variable to the name of the class that you just created (use a String, not the actual class) at `config/initializers/decidim.rb`.
|
150
128
|
|
151
|
-
Keep in mind that Decidim
|
129
|
+
Keep in mind that Decidim will not store a free text version of the mobile phone, only a hashed
|
152
130
|
version so we can avoid duplicates and guarantee the users' privacy.
|
153
131
|
|
154
132
|
You can find an example [here][example SMS gateway].
|
@@ -233,7 +211,7 @@ for additional technical details.
|
|
233
211
|
## How Handlers work
|
234
212
|
|
235
213
|
For a workflow to be visible in the user's profile, the organization must have
|
236
|
-
it in it
|
214
|
+
it in it is `available_authorizations` and the given handler must exist.
|
237
215
|
The name of the handler must match the authorization name plus the "Hander"
|
238
216
|
suffix. It also has to be in the `Decidim::Verifications` namespace.
|
239
217
|
|
@@ -8,25 +8,27 @@
|
|
8
8
|
<div class="revoke_all_box">
|
9
9
|
<p><%= t("decidim.admin.menu.authorization_revocation.info", count: model.count ) %></p>
|
10
10
|
<%= link_to t("decidim.admin.menu.authorization_revocation.button"),
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
decidim_verifications.admin_verifications_destroy_all_path,
|
12
|
+
method: :delete,
|
13
|
+
class: "button button__sm md:button__lg button__secondary",
|
14
|
+
data: { confirm: t("decidim.admin.menu.authorization_revocation.destroy.confirm_all") } %>
|
15
15
|
</div>
|
16
16
|
<br>
|
17
17
|
<div class="revoke_before_date_box">
|
18
|
-
<%= decidim_form_for(@form, url: decidim_verifications.admin_verifications_destroy_before_date_path, html: { class: "form" } ) do |form| %>
|
19
|
-
<div class="
|
20
|
-
<div class="card
|
21
|
-
<div class="
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
<%= decidim_form_for(@form, url: decidim_verifications.admin_verifications_destroy_before_date_path, html: { class: "form form-defaults" } ) do |form| %>
|
19
|
+
<div class="form__wrapper">
|
20
|
+
<div class="card">
|
21
|
+
<div class="card-section">
|
22
|
+
<div class="row column">
|
23
|
+
<%= form.check_box :impersonated_only %>
|
24
|
+
</div>
|
25
|
+
<div class="row column">
|
26
|
+
<%= form.date_field :before_date, value: Time.zone.today.prev_month, autocomplete: "off" %>
|
27
|
+
<%= label_tag(:before_date_info, t("decidim.admin.menu.authorization_revocation.before_date_info")) %>
|
28
|
+
</div>
|
29
|
+
<div class="form__wrapper-block flex-col-reverse md:flex-row justify-between">
|
30
|
+
<%= form.submit t("decidim.admin.menu.authorization_revocation.button_before"), data: { confirm: t("decidim.admin.menu.authorization_revocation.destroy.confirm") }, class: "button button__sm md:button__lg button__secondary" %>
|
31
|
+
</div>
|
30
32
|
</div>
|
31
33
|
</div>
|
32
34
|
</div>
|
@@ -15,13 +15,14 @@ module Decidim
|
|
15
15
|
# Executes the command. Broadcasts these events:
|
16
16
|
#
|
17
17
|
# - :ok when everything is valid.
|
18
|
-
# - :invalid if the handler
|
18
|
+
# - :invalid if the handler was not valid and we could not proceed.
|
19
19
|
#
|
20
20
|
# Returns nothing.
|
21
21
|
def call
|
22
|
+
return transfer_authorization if !handler.unique? && handler.transferrable?
|
23
|
+
|
22
24
|
if handler.invalid?
|
23
|
-
|
24
|
-
notify_admins(conflict) if conflict.present?
|
25
|
+
register_conflict
|
25
26
|
|
26
27
|
return broadcast(:invalid)
|
27
28
|
end
|
@@ -35,6 +36,26 @@ module Decidim
|
|
35
36
|
|
36
37
|
attr_reader :handler
|
37
38
|
|
39
|
+
def transfer_authorization
|
40
|
+
authorization = handler.duplicate
|
41
|
+
transfer = authorization.transfer!(handler)
|
42
|
+
|
43
|
+
if transfer
|
44
|
+
broadcast(:transferred, transfer)
|
45
|
+
else
|
46
|
+
broadcast(:invalid)
|
47
|
+
end
|
48
|
+
rescue Decidim::AuthorizationTransfer::DisabledError
|
49
|
+
register_conflict
|
50
|
+
|
51
|
+
broadcast(:invalid)
|
52
|
+
end
|
53
|
+
|
54
|
+
def register_conflict
|
55
|
+
conflict = create_verification_conflict
|
56
|
+
notify_admins(conflict) if conflict.present?
|
57
|
+
end
|
58
|
+
|
38
59
|
def notify_admins(conflict)
|
39
60
|
Decidim::EventsManager.publish(
|
40
61
|
event: "decidim.events.verifications.managed_user_error_event",
|
@@ -20,7 +20,7 @@ module Decidim
|
|
20
20
|
# Executes the command. Broadcasts these events:
|
21
21
|
#
|
22
22
|
# - :ok when everything is valid.
|
23
|
-
# - :invalid if the handler
|
23
|
+
# - :invalid if the handler was not valid and we could not proceed.
|
24
24
|
#
|
25
25
|
# Returns nothing.
|
26
26
|
def call
|
@@ -14,7 +14,7 @@ module Decidim
|
|
14
14
|
|
15
15
|
# Executes the command. Broadcast this events:
|
16
16
|
# - :ok when everything is valid
|
17
|
-
# - :invalid when the form
|
17
|
+
# - :invalid when the form was not valid and could not proceed-
|
18
18
|
#
|
19
19
|
# Returns nothing.
|
20
20
|
def call
|
data/app/commands/decidim/verifications/id_documents/admin/confirm_user_offline_authorization.rb
CHANGED
@@ -16,7 +16,7 @@ module Decidim
|
|
16
16
|
# Executes the command. Broadcasts these events:
|
17
17
|
#
|
18
18
|
# - :ok when everything is valid.
|
19
|
-
# - :invalid if the handler
|
19
|
+
# - :invalid if the handler was not valid and we could not proceed.
|
20
20
|
#
|
21
21
|
# Returns nothing.
|
22
22
|
def call
|
@@ -16,7 +16,7 @@ module Decidim
|
|
16
16
|
# Executes the command. Broadcasts these events:
|
17
17
|
#
|
18
18
|
# - :ok when everything is valid.
|
19
|
-
# - :invalid if the handler
|
19
|
+
# - :invalid if the handler was not valid and we could not proceed.
|
20
20
|
#
|
21
21
|
# Returns nothing.
|
22
22
|
def call
|
@@ -16,14 +16,14 @@ module Decidim
|
|
16
16
|
# Executes the command. Broadcasts these events:
|
17
17
|
#
|
18
18
|
# - :ok when everything is valid.
|
19
|
-
# - :invalid if the handler
|
19
|
+
# - :invalid if the handler was not valid and we could not proceed.
|
20
20
|
#
|
21
21
|
# Returns nothing.
|
22
22
|
def call
|
23
23
|
return broadcast(:invalid) unless @organization
|
24
24
|
|
25
25
|
auths = Decidim::Verifications::Authorizations.new(
|
26
|
-
organization
|
26
|
+
organization:,
|
27
27
|
granted: true
|
28
28
|
).query
|
29
29
|
|
@@ -18,7 +18,7 @@ module Decidim
|
|
18
18
|
# Executes the command. Broadcasts these events:
|
19
19
|
#
|
20
20
|
# - :ok when everything is valid.
|
21
|
-
# - :invalid if the handler
|
21
|
+
# - :invalid if the handler was not valid and we could not proceed.
|
22
22
|
#
|
23
23
|
# Returns nothing.
|
24
24
|
def call
|
@@ -29,14 +29,14 @@ module Decidim
|
|
29
29
|
if @form.before_date.present?
|
30
30
|
authorizations_to_revoke = if @form.impersonated_only?
|
31
31
|
Decidim::Verifications::AuthorizationsBeforeDate.new(
|
32
|
-
organization
|
32
|
+
organization:,
|
33
33
|
date: @form.before_date,
|
34
34
|
granted: true,
|
35
35
|
impersonated_only: @form.impersonated_only
|
36
36
|
)
|
37
37
|
else
|
38
38
|
Decidim::Verifications::AuthorizationsBeforeDate.new(
|
39
|
-
organization
|
39
|
+
organization:,
|
40
40
|
date: @form.before_date,
|
41
41
|
granted: true
|
42
42
|
)
|
@@ -9,7 +9,7 @@ module Decidim
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
included do
|
11
11
|
def renew
|
12
|
-
enforce_permission_to
|
12
|
+
enforce_permission_to(:renew, :authorization, authorization:)
|
13
13
|
|
14
14
|
DestroyUserAuthorization.call(authorization) do
|
15
15
|
on(:ok, authorization) do
|
@@ -25,7 +25,7 @@ module Decidim
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def renew_modal
|
28
|
-
enforce_permission_to
|
28
|
+
enforce_permission_to(:renew, :authorization, authorization:)
|
29
29
|
|
30
30
|
respond_to do |format|
|
31
31
|
format.html { render layout: nil }
|
@@ -4,6 +4,9 @@ module Decidim
|
|
4
4
|
module Verifications
|
5
5
|
class ApplicationController < Decidim::ApplicationController
|
6
6
|
include NeedsPermission
|
7
|
+
include HasAccountBreadcrumb
|
8
|
+
|
9
|
+
layout "layouts/decidim/authorizations"
|
7
10
|
|
8
11
|
before_action :confirmed_user, only: [:new, :create, :renew]
|
9
12
|
|
@@ -3,19 +3,20 @@
|
|
3
3
|
module Decidim
|
4
4
|
module Verifications
|
5
5
|
# This controller allows users to create and destroy their authorizations. It
|
6
|
-
#
|
6
|
+
# should not be necessary to expand it to add new authorization schemes.
|
7
7
|
class AuthorizationsController < Verifications::ApplicationController
|
8
8
|
helper_method :handler, :unauthorized_methods, :authorization_method, :authorization
|
9
9
|
before_action :valid_handler, only: [:new, :create]
|
10
10
|
|
11
11
|
include Decidim::UserProfile
|
12
|
+
include Decidim::HtmlSafeFlash
|
12
13
|
include Decidim::Verifications::Renewable
|
13
14
|
helper Decidim::DecidimFormHelper
|
14
15
|
helper Decidim::CtaButtonHelper
|
15
16
|
helper Decidim::AuthorizationFormHelper
|
16
17
|
helper Decidim::TranslationsHelper
|
17
18
|
|
18
|
-
layout "layouts/decidim/
|
19
|
+
layout "layouts/decidim/authorizations", except: :index
|
19
20
|
|
20
21
|
def new; end
|
21
22
|
|
@@ -41,6 +42,21 @@ module Decidim
|
|
41
42
|
redirect_to redirect_url || authorizations_path
|
42
43
|
end
|
43
44
|
|
45
|
+
on(:transferred) do |transfer|
|
46
|
+
message = t("authorizations.create.success", scope: "decidim.verifications")
|
47
|
+
if transfer.records.any?
|
48
|
+
flash[:html_safe] = true
|
49
|
+
message = <<~HTML
|
50
|
+
<p>#{CGI.escapeHTML(message)}</p>
|
51
|
+
<p>#{CGI.escapeHTML(t("authorizations.create.transferred", scope: "decidim.verifications"))}</p>
|
52
|
+
#{transfer.presenter.records_list_html}
|
53
|
+
HTML
|
54
|
+
end
|
55
|
+
|
56
|
+
flash[:notice] = message
|
57
|
+
redirect_to redirect_url || authorizations_path
|
58
|
+
end
|
59
|
+
|
44
60
|
on(:invalid) do
|
45
61
|
flash[:alert] = t("authorizations.create.error", scope: "decidim.verifications")
|
46
62
|
render action: :new
|
@@ -72,8 +88,8 @@ module Decidim
|
|
72
88
|
return true if handler
|
73
89
|
|
74
90
|
msg = <<-MSG
|
75
|
-
Invalid authorization handler given: #{handler_name}
|
76
|
-
exist or you
|
91
|
+
Invalid authorization handler given: #{handler_name} does not
|
92
|
+
exist or you have not added it to `Decidim.authorization_handlers.
|
77
93
|
|
78
94
|
Make sure this name matches with your registrations:\n\n
|
79
95
|
Decidim::Verifications.register_workflow(:#{handler_name}) do
|
@@ -24,13 +24,13 @@ module Decidim
|
|
24
24
|
|
25
25
|
enforce_permission_to :create, :authorization, authorization: @authorization
|
26
26
|
|
27
|
-
@form = UploadForm.from_params(id_document_upload: { verification_type:
|
27
|
+
@form = UploadForm.from_params(id_document_upload: { verification_type: })
|
28
28
|
end
|
29
29
|
|
30
30
|
def create
|
31
31
|
enforce_permission_to :create, :authorization, authorization: @authorization
|
32
32
|
|
33
|
-
@form = UploadForm.from_params(params.merge(user: current_user)).with_context(current_organization:
|
33
|
+
@form = UploadForm.from_params(params.merge(user: current_user)).with_context(current_organization:)
|
34
34
|
|
35
35
|
PerformAuthorizationStep.call(@authorization, @form) do
|
36
36
|
on(:ok) do
|
@@ -39,7 +39,7 @@ module Decidim
|
|
39
39
|
end
|
40
40
|
|
41
41
|
on(:invalid) do
|
42
|
-
flash[:alert] = t("authorizations.create.error", scope: "decidim.verifications.id_documents")
|
42
|
+
flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.id_documents")
|
43
43
|
render action: :new
|
44
44
|
end
|
45
45
|
end
|
@@ -57,10 +57,10 @@ module Decidim
|
|
57
57
|
@form = UploadForm.from_params(
|
58
58
|
params.merge(
|
59
59
|
user: current_user,
|
60
|
-
verification_type
|
60
|
+
verification_type:,
|
61
61
|
verification_attachment: params[:id_document_upload][:verification_attachment] || @authorization.verification_attachment.blob
|
62
62
|
)
|
63
|
-
).with_context(current_organization:
|
63
|
+
).with_context(current_organization:)
|
64
64
|
|
65
65
|
PerformAuthorizationStep.call(@authorization, @form) do
|
66
66
|
on(:ok) do
|
@@ -69,7 +69,7 @@ module Decidim
|
|
69
69
|
end
|
70
70
|
|
71
71
|
on(:invalid) do
|
72
|
-
flash[:alert] = t("authorizations.update.error", scope: "decidim.verifications.id_documents")
|
72
|
+
flash.now[:alert] = t("authorizations.update.error", scope: "decidim.verifications.id_documents")
|
73
73
|
render action: :edit
|
74
74
|
end
|
75
75
|
end
|
@@ -9,13 +9,13 @@ module Decidim
|
|
9
9
|
helper_method :authorization
|
10
10
|
|
11
11
|
def new
|
12
|
-
enforce_permission_to
|
12
|
+
enforce_permission_to(:create, :authorization, authorization:)
|
13
13
|
|
14
14
|
@form = MobilePhoneForm.new
|
15
15
|
end
|
16
16
|
|
17
17
|
def create
|
18
|
-
enforce_permission_to
|
18
|
+
enforce_permission_to(:create, :authorization, authorization:)
|
19
19
|
|
20
20
|
@form = MobilePhoneForm.from_params(params.merge(user: current_user))
|
21
21
|
|
@@ -23,7 +23,7 @@ module Decidim
|
|
23
23
|
on(:ok) do
|
24
24
|
flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.sms")
|
25
25
|
authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name)
|
26
|
-
redirect_to authorization_method.resume_authorization_path(redirect_url:
|
26
|
+
redirect_to authorization_method.resume_authorization_path(redirect_url:)
|
27
27
|
end
|
28
28
|
on(:invalid) do
|
29
29
|
flash.now[:alert] = t("authorizations.create.error", scope: "decidim.verifications.sms")
|
@@ -33,13 +33,13 @@ module Decidim
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def edit
|
36
|
-
enforce_permission_to
|
36
|
+
enforce_permission_to(:update, :authorization, authorization:)
|
37
37
|
|
38
38
|
@form = ConfirmationForm.from_params(params)
|
39
39
|
end
|
40
40
|
|
41
41
|
def update
|
42
|
-
enforce_permission_to
|
42
|
+
enforce_permission_to(:update, :authorization, authorization:)
|
43
43
|
|
44
44
|
@form = ConfirmationForm.from_params(params)
|
45
45
|
|
@@ -47,11 +47,7 @@ module Decidim
|
|
47
47
|
on(:ok) do
|
48
48
|
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
|
49
49
|
|
50
|
-
|
51
|
-
redirect_to redirect_url
|
52
|
-
else
|
53
|
-
redirect_to decidim_verifications.authorizations_path
|
54
|
-
end
|
50
|
+
redirect_to redirect_url || decidim_verifications.authorizations_path
|
55
51
|
end
|
56
52
|
|
57
53
|
on(:invalid) do
|
@@ -62,7 +58,7 @@ module Decidim
|
|
62
58
|
end
|
63
59
|
|
64
60
|
def destroy
|
65
|
-
enforce_permission_to
|
61
|
+
enforce_permission_to(:destroy, :authorization, authorization:)
|
66
62
|
|
67
63
|
authorization.destroy!
|
68
64
|
flash[:notice] = t("authorizations.destroy.success", scope: "decidim.verifications.sms")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Verifications
|
@@ -25,13 +25,8 @@ module Decidim
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def default_i18n_options
|
28
|
-
super.merge({
|
29
|
-
|
30
|
-
conflicts_url: conflicts_url,
|
31
|
-
managed_user_path: managed_user.profile_path,
|
32
|
-
managed_user_url: managed_user.profile_url,
|
33
|
-
managed_user_name: managed_user.name
|
34
|
-
})
|
28
|
+
super.merge({ conflicts_path:, conflicts_url:, managed_user_path: managed_user.profile_path, managed_user_url: managed_user.profile_url,
|
29
|
+
managed_user_name: managed_user.name })
|
35
30
|
end
|
36
31
|
|
37
32
|
private
|
@@ -7,12 +7,14 @@ module Decidim
|
|
7
7
|
class InformationForm < AuthorizationHandler
|
8
8
|
mimic :id_document_information
|
9
9
|
|
10
|
+
DOCUMENT_TYPES = %w(DNI NIE passport).freeze
|
11
|
+
|
10
12
|
attribute :document_number, String
|
11
13
|
attribute :document_type, String
|
12
14
|
attribute :verification_type, String
|
13
15
|
|
14
16
|
validates :document_type,
|
15
|
-
inclusion: { in:
|
17
|
+
inclusion: { in: DOCUMENT_TYPES },
|
16
18
|
presence: true
|
17
19
|
|
18
20
|
validates :document_number,
|
@@ -42,7 +44,7 @@ module Decidim
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def document_types_for_select
|
45
|
-
|
47
|
+
DOCUMENT_TYPES.map do |type|
|
46
48
|
[
|
47
49
|
I18n.t(type.downcase, scope: "decidim.verifications.id_documents"),
|
48
50
|
type
|
@@ -53,12 +55,6 @@ module Decidim
|
|
53
55
|
def uses_online_method?
|
54
56
|
verification_type == "online"
|
55
57
|
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def document_types
|
60
|
-
Decidim::Verifications.document_types
|
61
|
-
end
|
62
58
|
end
|
63
59
|
end
|
64
60
|
end
|
@@ -22,7 +22,7 @@ module Decidim
|
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
|
-
# When there
|
25
|
+
# When there is a phone number, sanitize it allowing only numbers and +.
|
26
26
|
def mobile_phone_number
|
27
27
|
return unless super
|
28
28
|
|
@@ -32,7 +32,7 @@ module Decidim
|
|
32
32
|
# The verification metadata to validate in the next step.
|
33
33
|
def verification_metadata
|
34
34
|
{
|
35
|
-
verification_code
|
35
|
+
verification_code:,
|
36
36
|
code_sent_at: Time.current
|
37
37
|
}
|
38
38
|
end
|
@@ -43,7 +43,7 @@ module Decidim
|
|
43
43
|
return unless sms_gateway
|
44
44
|
return @verification_code if defined?(@verification_code)
|
45
45
|
|
46
|
-
return unless sms_gateway.new(mobile_phone_number, generated_code).deliver_code
|
46
|
+
return unless sms_gateway.new(mobile_phone_number, generated_code, sms_gateway_context).deliver_code
|
47
47
|
|
48
48
|
@verification_code = generated_code
|
49
49
|
end
|
@@ -52,6 +52,10 @@ module Decidim
|
|
52
52
|
Decidim.sms_gateway_service.to_s.safe_constantize
|
53
53
|
end
|
54
54
|
|
55
|
+
def sms_gateway_context
|
56
|
+
{ organization: user&.organization }
|
57
|
+
end
|
58
|
+
|
55
59
|
def generated_code
|
56
60
|
@generated_code ||= SecureRandom.random_number(1_000_000).to_s
|
57
61
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Verifications
|
5
|
+
module ApplicationHelper
|
6
|
+
def announcement_title(authorization)
|
7
|
+
return t("decidim.verifications.id_documents.authorizations.edit.being_reviewed") unless authorization.rejected?
|
8
|
+
|
9
|
+
body = content_tag :ul do
|
10
|
+
items = content_tag(:li, t("decidim.verifications.id_documents.authorizations.edit.rejection_correctness"))
|
11
|
+
items += content_tag(:li, t("decidim.verifications.id_documents.authorizations.edit.rejection_clarity")).html_safe
|
12
|
+
items
|
13
|
+
end
|
14
|
+
|
15
|
+
{
|
16
|
+
title: t("decidim.verifications.id_documents.authorizations.edit.rejection_notice"),
|
17
|
+
body:
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def authorization_display_data(authorization)
|
22
|
+
{ title: t("#{authorization.name}.name", scope: "decidim.authorization_handlers") }
|
23
|
+
end
|
24
|
+
|
25
|
+
def granted_authorization_display_data(authorization, redirect_url = nil)
|
26
|
+
authorization_display_data(authorization).merge(
|
27
|
+
url: granted_authorization_url(authorization, redirect_url),
|
28
|
+
remote_url: granted_authorization_remote_url(authorization),
|
29
|
+
auth_icon: "checkbox-circle-line",
|
30
|
+
is_granted: true,
|
31
|
+
explanation: granted_authorization_explanation(authorization),
|
32
|
+
button_text: granted_authorization_button_text(authorization)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
def granted_authorization_url(authorization, redirect_url = nil)
|
37
|
+
return if authorization.renewable?
|
38
|
+
return unless authorization.expired?
|
39
|
+
|
40
|
+
url_params = { redirect_url: }.compact
|
41
|
+
authorization_method(authorization).root_path(**url_params)
|
42
|
+
end
|
43
|
+
|
44
|
+
def granted_authorization_remote_url(authorization)
|
45
|
+
return unless authorization.renewable?
|
46
|
+
|
47
|
+
renew_modal_authorizations_path(handler: authorization.name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def granted_authorization_explanation(authorization)
|
51
|
+
expiration_timestamp = authorization.expires_at.presence && l(authorization.expires_at, format: :long_with_particles)
|
52
|
+
if authorization.expired?
|
53
|
+
t("expired_at", scope: "decidim.authorization_handlers", timestamp: expiration_timestamp)
|
54
|
+
else
|
55
|
+
"#{t("granted_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.granted_at, format: :long_with_particles))}\
|
56
|
+
#{t("expires_at", scope: "decidim.authorization_handlers", timestamp: expiration_timestamp) if expiration_timestamp.present?}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def granted_authorization_button_text(authorization)
|
61
|
+
return t("authorizations.index.show_renew_info", scope: "decidim.verifications") if authorization.renewable?
|
62
|
+
return unless authorization.expired?
|
63
|
+
|
64
|
+
t("authorizations.index.expired_verification", scope: "decidim.verifications")
|
65
|
+
end
|
66
|
+
|
67
|
+
def pending_authorization_display_data(authorization, redirect_url = nil)
|
68
|
+
url_params = { redirect_url: }.compact
|
69
|
+
|
70
|
+
authorization_display_data(authorization).merge(
|
71
|
+
url: authorization_method(authorization).resume_authorization_path(**url_params),
|
72
|
+
auth_icon: "time-line",
|
73
|
+
explanation: t("started_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.updated_at, format: :long_with_particles)),
|
74
|
+
button_text: t("authorizations.index.introduce_code", scope: "decidim.verifications")
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def unauthorized_method_display_data(method, redirect_url = nil)
|
79
|
+
url_params = { redirect_url: }.compact
|
80
|
+
|
81
|
+
{
|
82
|
+
url: method.root_path(**url_params),
|
83
|
+
auth_icon: method.icon,
|
84
|
+
title: t("#{method.key}.name", scope: "decidim.authorization_handlers"),
|
85
|
+
explanation: t("#{method.key}.explanation", scope: "decidim.authorization_handlers"),
|
86
|
+
button_text: t("authorizations.index.subscribe", scope: "decidim.verifications")
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|