decidim-verifications 0.27.4 → 0.28.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/app/cells/decidim/verifications/revocations/show.erb +18 -16
  4. data/app/commands/decidim/verifications/authorize_user.rb +24 -3
  5. data/app/commands/decidim/verifications/confirm_user_authorization.rb +1 -1
  6. data/app/commands/decidim/verifications/csv_census/admin/create_census_data.rb +1 -1
  7. data/app/commands/decidim/verifications/id_documents/admin/confirm_user_offline_authorization.rb +1 -1
  8. data/app/commands/decidim/verifications/perform_authorization_step.rb +1 -1
  9. data/app/commands/decidim/verifications/revoke_all_authorizations.rb +2 -2
  10. data/app/commands/decidim/verifications/revoke_by_condition_authorizations.rb +3 -3
  11. data/app/controllers/concerns/decidim/verifications/renewable.rb +2 -2
  12. data/app/controllers/decidim/verifications/application_controller.rb +3 -0
  13. data/app/controllers/decidim/verifications/authorizations_controller.rb +20 -4
  14. data/app/controllers/decidim/verifications/id_documents/authorizations_controller.rb +6 -6
  15. data/app/controllers/decidim/verifications/sms/authorizations_controller.rb +7 -11
  16. data/app/events/decidim/verifications/managed_user_error_event.rb +3 -8
  17. data/app/forms/decidim/verifications/postal_letter/postage_form.rb +1 -1
  18. data/app/forms/decidim/verifications/sms/mobile_phone_form.rb +7 -3
  19. data/app/helpers/decidim/verifications/application_helper.rb +91 -0
  20. data/app/jobs/decidim/verifications/csv_census/application_job.rb +1 -1
  21. data/app/jobs/decidim/verifications/csv_census/remove_duplicates_job.rb +1 -1
  22. data/app/models/decidim/verifications/csv_census/data.rb +1 -1
  23. data/app/models/decidim/verifications/csv_datum.rb +3 -3
  24. data/app/packs/entrypoints/decidim_verifications.js +2 -0
  25. data/app/packs/stylesheets/verifications.scss +58 -0
  26. data/app/presenters/decidim/verifications/postal_letter/authorization_presenter.rb +1 -1
  27. data/app/queries/decidim/verifications/authorizations.rb +2 -2
  28. data/app/services/decidim/authorization_handler.rb +45 -13
  29. data/app/views/decidim/verifications/authorizations/_item.html.erb +31 -0
  30. data/app/views/decidim/verifications/authorizations/first_login.html.erb +20 -21
  31. data/app/views/decidim/verifications/authorizations/index.html.erb +28 -73
  32. data/app/views/decidim/verifications/authorizations/new.html.erb +27 -29
  33. data/app/views/decidim/verifications/authorizations/renew_modal.html.erb +23 -30
  34. data/app/views/decidim/verifications/csv_census/admin/census/index.html.erb +54 -39
  35. data/app/views/decidim/verifications/csv_census/admin/census/instructions.html.erb +3 -2
  36. data/app/views/decidim/verifications/id_documents/admin/config/edit.html.erb +30 -21
  37. data/app/views/decidim/verifications/id_documents/admin/confirmations/new.html.erb +38 -22
  38. data/app/views/decidim/verifications/id_documents/admin/offline_confirmations/new.html.erb +39 -21
  39. data/app/views/decidim/verifications/id_documents/admin/pending_authorizations/index.html.erb +4 -4
  40. data/app/views/decidim/verifications/id_documents/authorizations/_form.html.erb +4 -10
  41. data/app/views/decidim/verifications/id_documents/authorizations/choose.html.erb +10 -19
  42. data/app/views/decidim/verifications/id_documents/authorizations/edit.html.erb +32 -41
  43. data/app/views/decidim/verifications/id_documents/authorizations/new.html.erb +19 -25
  44. data/app/views/decidim/verifications/postal_letter/admin/pending_authorizations/index.html.erb +53 -48
  45. data/app/views/decidim/verifications/postal_letter/authorizations/edit.html.erb +32 -34
  46. data/app/views/decidim/verifications/postal_letter/authorizations/new.html.erb +20 -25
  47. data/app/views/decidim/verifications/sms/authorizations/edit.html.erb +25 -34
  48. data/app/views/decidim/verifications/sms/authorizations/new.html.erb +20 -25
  49. data/app/views/dummy_authorization/_form.html.erb +6 -16
  50. data/app/views/layouts/decidim/authorizations.html.erb +8 -0
  51. data/config/assets.rb +8 -0
  52. data/config/environment.rb +3 -0
  53. data/config/locales/ar.yml +1 -53
  54. data/config/locales/ca.yml +46 -40
  55. data/config/locales/cs.yml +48 -42
  56. data/config/locales/de.yml +46 -40
  57. data/config/locales/el.yml +1 -62
  58. data/config/locales/en.yml +52 -46
  59. data/config/locales/es-MX.yml +47 -41
  60. data/config/locales/es-PY.yml +47 -41
  61. data/config/locales/es.yml +46 -40
  62. data/config/locales/eu.yml +93 -80
  63. data/config/locales/fi-plain.yml +48 -42
  64. data/config/locales/fi.yml +45 -39
  65. data/config/locales/fr-CA.yml +50 -44
  66. data/config/locales/fr.yml +50 -44
  67. data/config/locales/ga-IE.yml +0 -1
  68. data/config/locales/gl.yml +1 -62
  69. data/config/locales/hu.yml +48 -45
  70. data/config/locales/id-ID.yml +1 -53
  71. data/config/locales/is-IS.yml +3 -26
  72. data/config/locales/it.yml +1 -62
  73. data/config/locales/ja.yml +50 -44
  74. data/config/locales/lt.yml +53 -37
  75. data/config/locales/lv.yml +1 -61
  76. data/config/locales/nl.yml +1 -62
  77. data/config/locales/no.yml +1 -62
  78. data/config/locales/pl.yml +1 -62
  79. data/config/locales/pt-BR.yml +1 -62
  80. data/config/locales/pt.yml +1 -62
  81. data/config/locales/ro-RO.yml +5 -62
  82. data/config/locales/ru.yml +1 -31
  83. data/config/locales/sk.yml +1 -61
  84. data/config/locales/sq-AL.yml +1 -0
  85. data/config/locales/sv.yml +3 -62
  86. data/config/locales/th-TH.yml +1 -0
  87. data/config/locales/tr-TR.yml +1 -62
  88. data/config/locales/uk.yml +1 -31
  89. data/config/locales/zh-CN.yml +1 -62
  90. data/config/locales/zh-TW.yml +33 -27
  91. data/lib/decidim/verifications/adapter.rb +7 -7
  92. data/lib/decidim/verifications/csv_census/workflow.rb +1 -0
  93. data/lib/decidim/verifications/id_documents/workflow.rb +1 -0
  94. data/lib/decidim/verifications/postal_letter/workflow.rb +1 -0
  95. data/lib/decidim/verifications/sms/engine.rb +2 -1
  96. data/lib/decidim/verifications/sms/example_gateway.rb +3 -2
  97. data/lib/decidim/verifications/version.rb +1 -1
  98. data/lib/decidim/verifications/workflow_manifest.rb +2 -1
  99. data/lib/decidim/verifications/workflows.rb +2 -2
  100. metadata +27 -15
  101. data/app/views/decidim/verifications/authorizations/_granted_authorization.html.erb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0876daacf5843de75e8bcc983e461321e8c4dda211240dbcfaf5b4b96a18f04e'
4
- data.tar.gz: a64506d6ccb0a9f8ca061a6a00fcef017abd653d1a3e5f7206e43deaad7cffc6
3
+ metadata.gz: 85354d931745f3b401023315e5955fd50ab555c46854b73244555571f9c36ee9
4
+ data.tar.gz: 8f43458cce4271a60c805e64c9cb21c8fd5aa17dfc1258dff4f3ca8010211f0b
5
5
  SHA512:
6
- metadata.gz: d20803a28557abc2527163c4a5c803b3a8a8176505a37ad0cb222e9b948d4510d4cfd9bc50eda42c777806eeed6035ef81ba4eed24e09695af54941a07ad178d
7
- data.tar.gz: 8d72f0a369bd63461096a146f4d74f34b6b14575635a8311ec66d310845bca08a6a0be780a2889400a581985f5ac71d57631cc37313eb980fc7aecb69ec7a916
6
+ metadata.gz: ef1462c9db4ef91b65a2951ef728ada27e218fda67375ab46c61e4ef875780a027331605356d1eb60b17bad6004dadda96e965a5ddeaa93d6a59d06efe8c73c3
7
+ data.tar.gz: d45df3f6548550ed9f754c5bae2747a74269db6412ed44823871867b8617f05bfe2a49bc9ddf9560d781eff5b4112c79b9d81998e98ae2887809f64cb348e50f
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'll
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 can't renew its authorization, but this can be enabled when registering the workflow, the time between renewals can be configured (one day by default).
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
 
@@ -126,7 +126,7 @@ In order to setup Decidim with SMS verification you need to:
126
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.
127
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`.
128
128
 
129
- Keep in mind that Decidim won't store a free text version of the mobile phone, only a hashed
129
+ Keep in mind that Decidim will not store a free text version of the mobile phone, only a hashed
130
130
  version so we can avoid duplicates and guarantee the users' privacy.
131
131
 
132
132
  You can find an example [here][example SMS gateway].
@@ -211,7 +211,7 @@ for additional technical details.
211
211
  ## How Handlers work
212
212
 
213
213
  For a workflow to be visible in the user's profile, the organization must have
214
- it in it's `available_authorizations` and the given handler must exist.
214
+ it in it is `available_authorizations` and the given handler must exist.
215
215
  The name of the handler must match the authorization name plus the "Hander"
216
216
  suffix. It also has to be in the `Decidim::Verifications` namespace.
217
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
- decidim_verifications.admin_verifications_destroy_all_path,
12
- method: :delete,
13
- class: "button",
14
- data: { confirm: t("decidim.admin.menu.authorization_revocation.destroy.confirm_all") } %>
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="card">
20
- <div class="card-section">
21
- <div class="row column">
22
- <%= form.check_box :impersonated_only %>
23
- </div>
24
- <div class="row column">
25
- <%= form.date_field :before_date, value: Date.today.prev_month.strftime("%d/%m/%Y"), autocomplete: "off" %>
26
- <%= label_tag(:before_date_info, t("decidim.admin.menu.authorization_revocation.before_date_info")) %>
27
- </div>
28
- <div class="button--double">
29
- <%= form.submit t("decidim.admin.menu.authorization_revocation.button_before"), data: { confirm: t("decidim.admin.menu.authorization_revocation.destroy.confirm") } %>
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 wasn't valid and we couldn't proceed.
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
- conflict = create_verification_conflict
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 wasn't valid and we couldn't proceed.
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 wasn't valid and couldn't proceed-
17
+ # - :invalid when the form was not valid and could not proceed-
18
18
  #
19
19
  # Returns nothing.
20
20
  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 wasn't valid and we couldn't proceed.
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 wasn't valid and we couldn't proceed.
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 wasn't valid and we couldn't proceed.
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: 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 wasn't valid and we couldn't proceed.
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: 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: 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 :renew, :authorization, authorization: authorization
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 :renew, :authorization, authorization: authorization
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
- # shouldn't be necessary to expand it to add new authorization schemes.
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/user_profile", only: [:index]
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} doesn't
76
- exist or you haven't added it to `Decidim.authorization_handlers.
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: 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: 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: 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: 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 :create, :authorization, authorization: authorization
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 :create, :authorization, authorization: authorization
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: 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 :update, :authorization, authorization: authorization
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 :update, :authorization, authorization: authorization
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
- if redirect_url
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 :destroy, :authorization, authorization: authorization
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
- # frozen-string_literal: true
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
- conflicts_path: conflicts_path,
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
@@ -24,7 +24,7 @@ module Decidim
24
24
  def verification_metadata
25
25
  {
26
26
  address: full_address,
27
- verification_code: verification_code,
27
+ verification_code:,
28
28
  letter_sent_at: Time.current
29
29
  }
30
30
  end
@@ -22,7 +22,7 @@ module Decidim
22
22
  )
23
23
  end
24
24
 
25
- # When there's a phone number, sanitize it allowing only numbers and +.
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: 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
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module Verifications
5
5
  module CsvCensus
6
- class ApplicationJob < ActiveJob::Base
6
+ class ApplicationJob < Decidim::ApplicationJob
7
7
  end
8
8
  end
9
9
  end
@@ -9,7 +9,7 @@ module Decidim
9
9
  def perform(organization)
10
10
  duplicated_census(organization).pluck(:email).each do |email|
11
11
  CsvDatum.inside(organization)
12
- .where(email: email)
12
+ .where(email:)
13
13
  .order(id: :desc)
14
14
  .all(1..-1)
15
15
  .each(&:delete)
@@ -21,7 +21,7 @@ module Decidim
21
21
  @values = []
22
22
  @errors = []
23
23
 
24
- CSV.foreach(@file) do |row|
24
+ CSV.foreach(@file, encoding: "BOM|UTF-8") do |row|
25
25
  process_row(row)
26
26
  end
27
27
  end
@@ -9,18 +9,18 @@ module Decidim
9
9
  validates :email, format: { with: ::Devise.email_regexp }
10
10
 
11
11
  def self.inside(organization)
12
- where(organization: organization)
12
+ where(organization:)
13
13
  end
14
14
 
15
15
  def self.search_user_email(organization, email)
16
16
  inside(organization)
17
- .where(email: email)
17
+ .where(email:)
18
18
  .order(created_at: :desc, id: :desc)
19
19
  .first
20
20
  end
21
21
 
22
22
  def self.insert_all(organization, values)
23
- values.each { |value| create(email: value, organization: organization) }
23
+ values.each { |value| create(email: value, organization:) }
24
24
  end
25
25
 
26
26
  def self.clear(organization)
@@ -0,0 +1,2 @@
1
+ // CSS
2
+ import "stylesheets/verifications.scss"