decidim-verifications 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/app/cells/decidim/verifications/authorization_metadata/show.erb +13 -0
  4. data/app/cells/decidim/verifications/authorization_metadata_cell.rb +22 -0
  5. data/app/cells/decidim/verifications/revocations/show.erb +40 -0
  6. data/app/cells/decidim/verifications/revocations_cell.rb +19 -0
  7. data/app/commands/decidim/verifications/confirm_user_authorization.rb +49 -9
  8. data/app/commands/decidim/verifications/destroy_user_authorization.rb +24 -0
  9. data/app/commands/decidim/verifications/revoke_all_authorizations.rb +48 -0
  10. data/app/commands/decidim/verifications/revoke_by_condition_authorizations.rb +68 -0
  11. data/app/controllers/concerns/decidim/verifications/renewable.rb +37 -0
  12. data/app/controllers/decidim/verifications/admin/verifications_controller.rb +40 -0
  13. data/app/controllers/decidim/verifications/application_controller.rb +5 -1
  14. data/app/controllers/decidim/verifications/authorizations_controller.rb +18 -2
  15. data/app/controllers/decidim/verifications/csv_census/authorizations_controller.rb +3 -1
  16. data/app/controllers/decidim/verifications/id_documents/admin/confirmations_controller.rb +1 -1
  17. data/app/controllers/decidim/verifications/id_documents/authorizations_controller.rb +2 -0
  18. data/app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb +3 -1
  19. data/app/controllers/decidim/verifications/sms/authorizations_controller.rb +3 -1
  20. data/app/forms/decidim/verifications/admin/revocations_before_date_form.rb +16 -0
  21. data/app/queries/decidim/verifications/authorizations_before_date.rb +51 -0
  22. data/app/services/decidim/authorization_handler.rb +4 -0
  23. data/app/views/decidim/verifications/authorizations/_granted_authorization.html.erb +29 -24
  24. data/app/views/decidim/verifications/authorizations/first_login.html.erb +2 -2
  25. data/app/views/decidim/verifications/authorizations/index.html.erb +20 -11
  26. data/app/views/decidim/verifications/authorizations/new.html.erb +2 -2
  27. data/app/views/decidim/verifications/authorizations/renew_modal.html.erb +38 -0
  28. data/app/views/decidim/verifications/id_documents/authorizations/_form.html.erb +2 -0
  29. data/app/views/decidim/verifications/postal_letter/authorizations/edit.html.erb +2 -0
  30. data/app/views/decidim/verifications/postal_letter/authorizations/new.html.erb +2 -0
  31. data/app/views/decidim/verifications/sms/authorizations/edit.html.erb +2 -0
  32. data/app/views/decidim/verifications/sms/authorizations/new.html.erb +2 -0
  33. data/config/locales/ar.yml +2 -0
  34. data/config/locales/bg-BG.yml +17 -0
  35. data/config/locales/ca.yml +30 -0
  36. data/config/locales/cs.yml +30 -0
  37. data/config/locales/da-DK.yml +1 -0
  38. data/config/locales/de.yml +31 -0
  39. data/config/locales/el.yml +257 -0
  40. data/config/locales/en.yml +30 -0
  41. data/config/locales/es-MX.yml +30 -0
  42. data/config/locales/es-PY.yml +30 -0
  43. data/config/locales/es.yml +30 -0
  44. data/config/locales/et-EE.yml +1 -0
  45. data/config/locales/eu.yml +2 -0
  46. data/config/locales/fi-plain.yml +30 -0
  47. data/config/locales/fi.yml +40 -10
  48. data/config/locales/fr-CA.yml +258 -0
  49. data/config/locales/fr.yml +30 -0
  50. data/config/locales/ga-IE.yml +1 -0
  51. data/config/locales/gl.yml +2 -0
  52. data/config/locales/hr-HR.yml +1 -0
  53. data/config/locales/hu.yml +23 -0
  54. data/config/locales/id-ID.yml +2 -0
  55. data/config/locales/it.yml +30 -0
  56. data/config/locales/ja-JP.yml +257 -0
  57. data/config/locales/lt-LT.yml +1 -0
  58. data/config/locales/lv-LV.yml +250 -0
  59. data/config/locales/mt-MT.yml +1 -0
  60. data/config/locales/nl.yml +30 -0
  61. data/config/locales/no.yml +2 -0
  62. data/config/locales/pl.yml +31 -0
  63. data/config/locales/pt-BR.yml +3 -1
  64. data/config/locales/pt.yml +125 -94
  65. data/config/locales/ro-RO.yml +259 -0
  66. data/config/locales/sk-SK.yml +258 -0
  67. data/config/locales/sk.yml +258 -0
  68. data/config/locales/sl.yml +5 -0
  69. data/config/locales/sr-CS.yml +1 -0
  70. data/config/locales/sv.yml +30 -0
  71. data/config/locales/tr-TR.yml +2 -0
  72. data/lib/decidim/verifications/adapter.rb +12 -0
  73. data/lib/decidim/verifications/csv_census/engine.rb +3 -1
  74. data/lib/decidim/verifications/engine.rb +13 -0
  75. data/lib/decidim/verifications/id_documents/engine.rb +1 -0
  76. data/lib/decidim/verifications/postal_letter/engine.rb +3 -1
  77. data/lib/decidim/verifications/sms/engine.rb +3 -1
  78. data/lib/decidim/verifications/version.rb +1 -1
  79. data/lib/decidim/verifications/workflow_manifest.rb +3 -0
  80. data/lib/decidim/verifications/workflows.rb +1 -1
  81. metadata +35 -8
@@ -5,7 +5,7 @@ module Decidim
5
5
  class ApplicationController < Decidim::ApplicationController
6
6
  include NeedsPermission
7
7
 
8
- before_action :confirmed_user, only: [:new, :create]
8
+ before_action :confirmed_user, only: [:new, :create, :renew]
9
9
 
10
10
  def new
11
11
  raise NotImplementedError
@@ -15,6 +15,10 @@ module Decidim
15
15
  raise NotImplementedError
16
16
  end
17
17
 
18
+ def renew
19
+ raise NotImplementedError
20
+ end
21
+
18
22
  private
19
23
 
20
24
  def confirmed_user
@@ -4,11 +4,12 @@ module Decidim
4
4
  module Verifications
5
5
  # This controller allows users to create and destroy their authorizations. It
6
6
  # shouldn't be necessary to expand it to add new authorization schemes.
7
- class AuthorizationsController < ApplicationController
8
- helper_method :handler, :unauthorized_methods
7
+ class AuthorizationsController < Verifications::ApplicationController
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::Verifications::Renewable
12
13
  helper Decidim::DecidimFormHelper
13
14
  helper Decidim::CtaButtonHelper
14
15
  helper Decidim::AuthorizationFormHelper
@@ -48,6 +49,12 @@ module Decidim
48
49
 
49
50
  protected
50
51
 
52
+ def authorization_method(authorization)
53
+ return unless authorization
54
+
55
+ Decidim::Verifications::Adapter.from_element(authorization.name)
56
+ end
57
+
51
58
  def handler
52
59
  @handler ||= Decidim::AuthorizationHandler.handler_for(handler_name, handler_params)
53
60
  end
@@ -92,6 +99,15 @@ module Decidim
92
99
 
93
100
  store_location_for(:user, redirect_url)
94
101
  end
102
+
103
+ private
104
+
105
+ def authorization
106
+ @authorization ||= Decidim::Authorization.find_by(
107
+ user: current_user,
108
+ name: handler_name
109
+ )
110
+ end
95
111
  end
96
112
  end
97
113
  end
@@ -4,13 +4,15 @@ module Decidim
4
4
  module Verifications
5
5
  module CsvCensus
6
6
  class AuthorizationsController < Decidim::ApplicationController
7
+ include Decidim::Verifications::Renewable
8
+
7
9
  helper_method :authorization
8
10
 
9
11
  before_action :load_authorization
10
12
 
11
13
  def new
12
14
  @form = CensusForm.from_params(user: current_user)
13
- ConfirmCensusAuthorization.call(@authorization, @form) do
15
+ ConfirmCensusAuthorization.call(@authorization, @form, session) do
14
16
  on(:ok) do
15
17
  flash[:notice] = t("authorizations.new.success", scope: "decidim.verifications.csv_census")
16
18
  end
@@ -23,7 +23,7 @@ module Decidim
23
23
 
24
24
  @form = InformationForm.from_params(params)
25
25
 
26
- ConfirmUserAuthorization.call(@pending_authorization, @form) do
26
+ ConfirmUserAuthorization.call(@pending_authorization, @form, session) do
27
27
  on(:ok) do
28
28
  flash[:notice] = t("confirmations.create.success", scope: "decidim.verifications.id_documents.admin")
29
29
  redirect_to pending_authorizations_path
@@ -7,6 +7,8 @@ module Decidim
7
7
  # Handles verification by identity document upload
8
8
  #
9
9
  class AuthorizationsController < ApplicationController
10
+ include Decidim::Verifications::Renewable
11
+
10
12
  helper_method :authorization, :verification_type, :using_offline?, :using_online?, :available_methods
11
13
 
12
14
  before_action :load_authorization
@@ -4,6 +4,8 @@ module Decidim
4
4
  module Verifications
5
5
  module PostalLetter
6
6
  class AuthorizationsController < ApplicationController
7
+ include Decidim::Verifications::Renewable
8
+
7
9
  helper_method :authorization
8
10
 
9
11
  before_action :load_authorization
@@ -43,7 +45,7 @@ module Decidim
43
45
 
44
46
  @form = ConfirmationForm.from_params(params)
45
47
 
46
- ConfirmUserAuthorization.call(@authorization, @form) do
48
+ ConfirmUserAuthorization.call(@authorization, @form, session) do
47
49
  on(:ok) do
48
50
  flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.postal_letter")
49
51
  redirect_to decidim_verifications.authorizations_path
@@ -4,6 +4,8 @@ module Decidim
4
4
  module Verifications
5
5
  module Sms
6
6
  class AuthorizationsController < ApplicationController
7
+ include Decidim::Verifications::Renewable
8
+
7
9
  helper_method :authorization
8
10
 
9
11
  def new
@@ -41,7 +43,7 @@ module Decidim
41
43
 
42
44
  @form = ConfirmationForm.from_params(params)
43
45
 
44
- ConfirmUserAuthorization.call(authorization, @form) do
46
+ ConfirmUserAuthorization.call(authorization, @form, session) do
45
47
  on(:ok) do
46
48
  flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
47
49
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module Admin
6
+ class RevocationsBeforeDateForm < Decidim::Form
7
+ include TranslatableAttributes
8
+
9
+ attribute :impersonated_only, Boolean
10
+ attribute :before_date, Decidim::Attributes::LocalizedDate
11
+
12
+ validates :before_date, presence: true
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ # Finds authorizations by different criteria
6
+ class AuthorizationsBeforeDate < Rectify::Query
7
+ # Initializes the class.
8
+ #
9
+ # @param organization [Organization] The organization where this authorization belongs to
10
+ # @param date [Date] The verification's date of an authorization
11
+ # @param granted [boolean] Whether return granted auths only or not granted only
12
+ # @param impersonated_only [boolean] Whether return impersonated auths only
13
+ def initialize(organization:, date:, granted: true, impersonated_only: false)
14
+ @organization = organization
15
+ @date = date
16
+ @granted = granted
17
+ @impersonated_only = impersonated_only
18
+ end
19
+
20
+ # Finds the Authorizations for the given method
21
+ #
22
+ # Returns an ActiveRecord::Relation.
23
+ def query
24
+ return Decidim::Authorization.none unless organization
25
+
26
+ query = Decidim::Authorization.left_outer_joins(:organization).where(decidim_organizations: { id: organization.id })
27
+
28
+ if impersonated_only
29
+ query = query
30
+ .left_outer_joins(:user)
31
+ .where(decidim_users: { decidim_organization_id: organization.id })
32
+ .where(decidim_users: { managed: true })
33
+ end
34
+
35
+ query = query.where("#{Decidim::Authorization.table_name}.created_at < ?", date) unless date.nil?
36
+
37
+ query = if granted
38
+ query.where.not(granted_at: nil)
39
+ else
40
+ query.where(granted_at: nil)
41
+ end
42
+
43
+ query
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :organization, :date, :granted, :impersonated_only
49
+ end
50
+ end
51
+ end
@@ -56,6 +56,10 @@ module Decidim
56
56
  # params the user sent with the authorization form want to be persisted for
57
57
  # future use.
58
58
  #
59
+ # As a convention, an 'extras' key can be used to store information not
60
+ # directly related with authorization. Thus, when rendering previous
61
+ # verification data, on renewal, 'extras' is not rendered to the user.
62
+ #
59
63
  # Returns a Hash.
60
64
  def metadata
61
65
  {}
@@ -1,27 +1,32 @@
1
- <div class="card--list__item">
2
- <div class="card--list__text">
3
- <%= icon "lock-locked", class: "card--list__icon" %>
4
- <div>
5
- <h5 class="card--list__heading">
6
- <%= t("#{authorization.name}.name", scope: "decidim.authorization_handlers") %>
7
- </h5>
8
- <span class="text-small">
9
- <% if authorization.expired? %>
10
- <%= t("expired_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.expires_at, format: :long)) %>
11
- <% else %>
12
- <%= t("granted_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.granted_at, format: :long)) %>
13
- <% if authorization.expires_at.present? %>
14
- <%= t("expires_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.expires_at, format: :long)) %>
15
- <% end %>
1
+ <div class="card--list__text">
2
+ <%= icon "lock-locked", class: "card--list__icon", role: "img", "aria-hidden": true %>
3
+ <div>
4
+ <h5 class="card--list__heading">
5
+ <%= t("#{authorization.name}.name", scope: "decidim.authorization_handlers") %>
6
+ </h5>
7
+ <span class="text-small <%= "alert" if authorization.expired? %>">
8
+ <% if authorization.expired? %>
9
+ <%= t("expired_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.expires_at, format: :long)) %>
10
+ <% else %>
11
+ <%= t("granted_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.granted_at, format: :long)) %>
12
+ <% if authorization.expires_at.present? %>
13
+ <%= t("expires_at", scope: "decidim.authorization_handlers", timestamp: l(authorization.expires_at, format: :long)) %>
16
14
  <% end %>
17
- </span>
18
- </div>
15
+ <% end %>
16
+ </span>
19
17
  </div>
20
- <% if authorization.expired? %>
21
- <div class="card--list__data">
22
- <span class="card--list__data__icon">
23
- <%= icon "reload" %>
24
- </span>
25
- </div>
26
- <% end %>
27
18
  </div>
19
+
20
+ <% if authorization.expired? %>
21
+ <div class="card--list__data">
22
+ <span class="card--list__data__icon">
23
+ <%= icon "reload", aria_label: t("renew", scope: "decidim.authorization_handlers"), role: "img" %>
24
+ </span>
25
+ </div>
26
+ <% elsif authorization.renewable? %>
27
+ <div class="card--list__data">
28
+ <span class="card--list__data__icon">
29
+ <%= icon "reload", aria_label: t("renew", scope: "decidim.authorization_handlers"), role: "img" %>
30
+ </span>
31
+ </div>
32
+ <% end %>
@@ -1,4 +1,4 @@
1
- <main class="wrapper">
1
+ <div class="wrapper">
2
2
  <div class="row collapse">
3
3
  <div class="row collapse">
4
4
  <div class="columns large-8 large-centered text-center">
@@ -19,4 +19,4 @@
19
19
  </div>
20
20
  </div>
21
21
  </div>
22
- </main>
22
+ </div>
@@ -1,28 +1,37 @@
1
+ <% add_decidim_page_title(t("authorizations", scope: "layouts.decidim.user_profile")) %>
2
+ <% content_for(:subtitle) { t("authorizations", scope: "layouts.decidim.user_profile") } %>
3
+
1
4
  <div class="row column authorizations-list">
2
5
  <section class="section">
3
6
  <% if @granted_authorizations.any? %>
4
7
  <div class="card card--list">
5
8
  <% @granted_authorizations.each do |authorization| %>
6
9
  <% if authorization.expired? %>
7
- <% authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name) %>
8
- <%= link_to authorization_method.root_path do %>
10
+ <%= link_to authorization_method(authorization).root_path, title: t(".expired_verification"), class: "card--list__item" do %>
9
11
  <% render partial: "granted_authorization", locals: { authorization: authorization } %>
10
12
  <% end %>
13
+ <% elsif authorization.renewable? %>
14
+ <%= link_to "#", title: t(".show_renew_info"), data: { open: "renew-modal", "open-url": renew_modal_authorizations_path(handler: authorization.name) }, class: "card--list__item authorization-renewable" do %>
15
+ <%= render partial: "granted_authorization", locals: { authorization: authorization } %>
16
+ <% end %>
11
17
  <% else %>
12
- <%= render partial: "granted_authorization", locals: { authorization: authorization } %>
18
+ <div class="card--list__item">
19
+ <%= render partial: "granted_authorization", locals: { authorization: authorization } %>
20
+ </div>
13
21
  <% end %>
14
22
  <% end %>
15
23
  </div>
24
+
25
+ <div id="renew-modal" data-reveal class="reveal" aria-labelledby="<%= t("renew_modal.title", scope: "decidim.verifications.authorizations") %>" aria-hidden="true" role="dialog"></div>
16
26
  <% end %>
17
27
 
18
28
  <% if @pending_authorizations.any? %>
19
29
  <div class="card card--list">
20
30
  <% @pending_authorizations.each do |authorization| %>
21
- <% authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name) %>
22
- <%= link_to authorization_method.resume_authorization_path do %>
31
+ <%= link_to authorization_method(authorization).resume_authorization_path do %>
23
32
  <div class="card--list__item">
24
33
  <div class="card--list__text">
25
- <%= icon "reload", class: "card--list__icon" %>
34
+ <%= icon "reload", class: "card--list__icon", aria_label: t(".pending_verification"), role: "img" %>
26
35
  <div>
27
36
  <h5 class="card--list__heading">
28
37
  <%= t("#{authorization.name}.name", scope: "decidim.authorization_handlers") %>
@@ -32,9 +41,9 @@
32
41
  </span>
33
42
  </div>
34
43
  </div>
35
- <div class="card--list__data">
44
+ <div class="card--list__data" aria-hidden="true">
36
45
  <span class="card--list__data__icon">
37
- <%= icon "chevron-right" %>
46
+ <%= icon "chevron-right", role: "img", "aria-hidden": true %>
38
47
  </span>
39
48
  </div>
40
49
  </div>
@@ -49,7 +58,7 @@
49
58
  <%= link_to unauthorized_method.root_path do %>
50
59
  <div class="card--list__item">
51
60
  <div class="card--list__text">
52
- <%= icon "lock-unlocked", class: "card--list__icon" %>
61
+ <%= icon "lock-unlocked", class: "card--list__icon", aria_label: t(".unauthorized_verification"), role: "img" %>
53
62
  <div>
54
63
  <h5 class="card--list__heading">
55
64
  <%= t("#{unauthorized_method.key}.name", scope: "decidim.authorization_handlers") %>
@@ -59,9 +68,9 @@
59
68
  </span>
60
69
  </div>
61
70
  </div>
62
- <div class="card--list__data">
71
+ <div class="card--list__data" aria-hidden="true">
63
72
  <span class="card--list__data__icon">
64
- <%= icon "chevron-right" %>
73
+ <%= icon "chevron-right", role: "img", "aria-hidden": true %>
65
74
  </span>
66
75
  </div>
67
76
  </div>
@@ -1,4 +1,4 @@
1
- <main class="wrapper">
1
+ <div class="wrapper">
2
2
  <div class="row collapse">
3
3
  <div class="row collapse">
4
4
  <div class="columns large-8 large-centered text-center page-title">
@@ -29,4 +29,4 @@
29
29
  </div>
30
30
  </div>
31
31
  </div>
32
- </main>
32
+ </div>
@@ -0,0 +1,38 @@
1
+ <div class="reveal__header">
2
+ <h3 class="reveal__title">
3
+ <%= t("renew_modal.title", scope: "decidim.verifications.authorizations") %>
4
+ </h3>
5
+
6
+ <button class="close-button" data-close aria-label="<%= t("renew_modal.close", scope: "decidim.verifications.authorizations") %>"
7
+ type="button">
8
+ <span aria-hidden="true">&times;</span>
9
+ </button>
10
+ </div>
11
+
12
+ <div class="row">
13
+ <p>
14
+ <strong>
15
+ <%= t("#{authorization.name}.name", scope: "decidim.authorization_handlers") %>
16
+ </strong>
17
+ <br>
18
+ <span class="text-muted">
19
+ <%= t("#{authorization.name}.explanation", scope: "decidim.authorization_handlers") %>
20
+ </span>
21
+ </p>
22
+
23
+ <%= cell(authorization.metadata_cell, authorization) %>
24
+
25
+ <p>
26
+ <%= t("renew_modal.info_renew", scope: "decidim.verifications.authorizations") %>
27
+ </p>
28
+ </div>
29
+
30
+ <div class="row">
31
+ <div class="column flex-center">
32
+ <button class="clear button secondary expanded" data-close type="button">
33
+ <%= t("renew_modal.cancel", scope: "decidim.verifications.authorizations") %>
34
+ </button>
35
+
36
+ <%= link_to t("renew_modal.continue", scope: "decidim.verifications.authorizations"), authorization_method(authorization).renew_path, class: "button expanded" %>
37
+ </div>
38
+ </div>
@@ -1,3 +1,5 @@
1
+ <%= form_required_explanation %>
2
+
1
3
  <div class="card-section">
2
4
  <div class="field">
3
5
  <%= form.select :document_type, @form.document_types_for_select, prompt: true %>
@@ -12,6 +12,8 @@
12
12
  <div class="card">
13
13
  <div class="card__content">
14
14
  <%= decidim_form_for(@form, url: authorization_path, method: :put) do |form| %>
15
+ <%= form_required_explanation %>
16
+
15
17
  <div class="field">
16
18
  <%= form.text_field :verification_code %>
17
19
  </div>
@@ -11,6 +11,8 @@
11
11
  <div class="card">
12
12
  <div class="card__content">
13
13
  <%= decidim_form_for(@form, url: authorization_path) do |form| %>
14
+ <%= form_required_explanation %>
15
+
14
16
  <div class="field">
15
17
  <%= form.text_field :full_address %>
16
18
  </div>
@@ -11,6 +11,8 @@
11
11
  <div class="card">
12
12
  <div class="card__content">
13
13
  <%= decidim_form_for(@form, url: authorization_path(redirect_url: redirect_url), method: :put) do |form| %>
14
+ <%= form_required_explanation %>
15
+
14
16
  <div class="field">
15
17
  <%= form.text_field :verification_code %>
16
18
  </div>