decidim-verifications 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -0
  3. data/Rakefile +3 -0
  4. data/app/commands/decidim/verifications/authorize_user.rb +61 -0
  5. data/app/commands/decidim/verifications/confirm_user_authorization.rb +49 -0
  6. data/app/commands/decidim/verifications/perform_authorization_step.rb +48 -0
  7. data/app/controllers/decidim/verifications/authorizations_controller.rb +91 -0
  8. data/app/controllers/decidim/verifications/id_documents/admin/confirmations_controller.rb +48 -0
  9. data/app/controllers/decidim/verifications/id_documents/admin/pending_authorizations_controller.rb +28 -0
  10. data/app/controllers/decidim/verifications/id_documents/admin/rejections_controller.rb +37 -0
  11. data/app/controllers/decidim/verifications/id_documents/authorizations_controller.rb +82 -0
  12. data/app/controllers/decidim/verifications/postal_letter/admin/pending_authorizations_controller.rb +27 -0
  13. data/app/controllers/decidim/verifications/postal_letter/admin/postages_controller.rb +41 -0
  14. data/app/controllers/decidim/verifications/postal_letter/authorizations_controller.rb +74 -0
  15. data/app/forms/decidim/verifications/id_documents/information_form.rb +50 -0
  16. data/app/forms/decidim/verifications/id_documents/information_rejection_form.rb +15 -0
  17. data/app/forms/decidim/verifications/id_documents/upload_form.rb +20 -0
  18. data/app/forms/decidim/verifications/postal_letter/address_form.rb +28 -0
  19. data/app/forms/decidim/verifications/postal_letter/confirmation_form.rb +19 -0
  20. data/app/forms/decidim/verifications/postal_letter/postage_form.rb +34 -0
  21. data/app/presenters/decidim/verifications/id_documents/authorization_presenter.rb +20 -0
  22. data/app/presenters/decidim/verifications/postal_letter/authorization_presenter.rb +59 -0
  23. data/app/queries/decidim/verifications/authorizations.rb +41 -0
  24. data/app/services/decidim/authorization_handler.rb +112 -0
  25. data/app/services/decidim/dummy_authorization_handler.rb +27 -0
  26. data/app/uploaders/decidim/verifications/attachment_uploader.rb +16 -0
  27. data/app/views/decidim/verifications/authorizations/first_login.html.erb +22 -0
  28. data/app/views/decidim/verifications/authorizations/index.html.erb +78 -0
  29. data/app/views/decidim/verifications/authorizations/new.html.erb +33 -0
  30. data/app/views/decidim/verifications/id_documents/admin/confirmations/new.html.erb +26 -0
  31. data/app/views/decidim/verifications/id_documents/admin/pending_authorizations/index.html.erb +32 -0
  32. data/app/views/decidim/verifications/id_documents/authorizations/edit.html.erb +53 -0
  33. data/app/views/decidim/verifications/id_documents/authorizations/new.html.erb +35 -0
  34. data/app/views/decidim/verifications/postal_letter/admin/pending_authorizations/index.html.erb +50 -0
  35. data/app/views/decidim/verifications/postal_letter/authorizations/edit.html.erb +37 -0
  36. data/app/views/decidim/verifications/postal_letter/authorizations/new.html.erb +27 -0
  37. data/config/locales/ca.yml +126 -0
  38. data/config/locales/en.yml +126 -0
  39. data/config/locales/es.yml +126 -0
  40. data/config/locales/eu.yml +125 -0
  41. data/config/locales/fi.yml +125 -0
  42. data/config/locales/fr.yml +125 -0
  43. data/config/locales/it.yml +125 -0
  44. data/config/locales/nl.yml +125 -0
  45. data/config/locales/pl.yml +125 -0
  46. data/config/locales/pt.yml +125 -0
  47. data/config/locales/ru.yml +5 -0
  48. data/config/locales/uk.yml +41 -0
  49. data/db/migrate/20171030133426_move_authorizations_to_new_api.rb +66 -0
  50. data/lib/decidim/verifications.rb +26 -0
  51. data/lib/decidim/verifications/adapter.rb +88 -0
  52. data/lib/decidim/verifications/dummy.rb +5 -0
  53. data/lib/decidim/verifications/engine.rb +24 -0
  54. data/lib/decidim/verifications/id_documents.rb +6 -0
  55. data/lib/decidim/verifications/id_documents/admin.rb +12 -0
  56. data/lib/decidim/verifications/id_documents/admin_engine.rb +21 -0
  57. data/lib/decidim/verifications/id_documents/engine.rb +18 -0
  58. data/lib/decidim/verifications/id_documents/workflow.rb +6 -0
  59. data/lib/decidim/verifications/postal_letter.rb +6 -0
  60. data/lib/decidim/verifications/postal_letter/admin.rb +12 -0
  61. data/lib/decidim/verifications/postal_letter/admin_engine.rb +21 -0
  62. data/lib/decidim/verifications/postal_letter/engine.rb +18 -0
  63. data/lib/decidim/verifications/postal_letter/workflow.rb +6 -0
  64. data/lib/decidim/verifications/registry.rb +39 -0
  65. data/lib/decidim/verifications/version.rb +10 -0
  66. data/lib/decidim/verifications/workflow_manifest.rb +56 -0
  67. data/lib/decidim/verifications/workflows.rb +58 -0
  68. metadata +152 -0
@@ -0,0 +1,5 @@
1
+ ru:
2
+ activemodel:
3
+ attributes:
4
+ id_document_upload:
5
+ user: Участник
@@ -0,0 +1,41 @@
1
+ uk:
2
+ activemodel:
3
+ attributes:
4
+ id_document_information:
5
+ document_number: Номер документа (з літерою)
6
+ document_type: Тип документа
7
+ id_document_upload:
8
+ document_number: Номер документа (з літерою)
9
+ document_type: Тип вашого документа
10
+ user: Учасник
11
+ verification_attachment: Сканована копія вашого документа
12
+ decidim:
13
+ admin:
14
+ menu:
15
+ authorization_workflows: Перевірки
16
+ authorization_handlers:
17
+ help: Допомога
18
+ multistep: Багатокроковий
19
+ name: Ім'я
20
+ postal_letter:
21
+ explanation: Ми надішлемо вам поштовий лист із кодом, який вам потрібно ввести, щоб ми могли підтвердити вашу адресу
22
+ verifications:
23
+ postal_letter:
24
+ admin:
25
+ pending_authorizations:
26
+ index:
27
+ username: Ім'я учасника
28
+ verification_code: Код підтвердження
29
+ postages:
30
+ create:
31
+ error: Помилка позначення листа як відправленого
32
+ success: Лист успішно позначено як відправлений
33
+ authorizations:
34
+ create:
35
+ error: Виникла проблема з вашим запитом
36
+ success: Дякуємо! Ми надішлемо код підтвердження на вашу адресу
37
+ edit:
38
+ send: Підтвердити
39
+ title: Введіть код підтвердження, який ви отримали
40
+ new:
41
+ send: Надішліть мені листа
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Assumes to authorizations in the old format (as rectify form classes) will be
5
+ # registered as the underscored class name using the new API. For example, a
6
+ # previous
7
+ #
8
+ # ```
9
+ # config.authorization_handlers = ["Decidim::ExampleCensusHandler"]
10
+ # ```
11
+ #
12
+ # will now be
13
+ #
14
+ # ```
15
+ # Decidim::Verifications.register_workflow(:example_census_handler) do |auth|
16
+ # auth.form = "Decidim::ExampleCensusHandler"
17
+ # end
18
+ # ```
19
+ #
20
+ class MoveAuthorizationsToNewApi < ActiveRecord::Migration[5.1]
21
+ class Organization < ApplicationRecord
22
+ self.table_name = :decidim_organizations
23
+ end
24
+
25
+ class Feature < ApplicationRecord
26
+ self.table_name = :decidim_features
27
+ end
28
+
29
+ def up
30
+ Organization.find_each do |organization|
31
+ migrated_authorizations = organization.available_authorizations.map do |authorization|
32
+ authorization.demodulize.underscore
33
+ end
34
+
35
+ organization.update!(available_authorizations: migrated_authorizations)
36
+ end
37
+
38
+ Feature.find_each do |feature|
39
+ feature.permissions.transform_values! do |value|
40
+ value["authorization_handler_name"].classify.demodulize.underscore
41
+ end
42
+
43
+ feature.save!
44
+ end
45
+ end
46
+
47
+ def down
48
+ Organization.find_each do |organization|
49
+ migrated_authorizations = organization.available_authorizations.map do |authorization|
50
+ Decidim::Verifications.find_workflow_manifest(authorization).form
51
+ end
52
+
53
+ organization.update!(available_authorizations: migrated_authorizations)
54
+ end
55
+
56
+ Feature.find_each do |feature|
57
+ feature.permissions.transform_values! do |value|
58
+ workflow = Decidim::Verifications.find_workflow_manifest(value)
59
+
60
+ workflow.form.underscore
61
+ end
62
+
63
+ feature.save!
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/verifications/engine"
4
+ require "decidim/verifications/workflows"
5
+
6
+ require "decidim/verifications/id_documents"
7
+ require "decidim/verifications/postal_letter"
8
+ require "decidim/verifications/dummy"
9
+
10
+ module Decidim
11
+ def self.authorization_workflows
12
+ Decidim::Verifications.workflows
13
+ end
14
+
15
+ def self.authorization_engines
16
+ Decidim::Verifications.workflows.select(&:engine)
17
+ end
18
+
19
+ def self.authorization_admin_engines
20
+ Decidim::Verifications.workflows.select(&:admin_engine)
21
+ end
22
+
23
+ def self.authorization_handlers
24
+ Decidim::Verifications.workflows.select(&:form)
25
+ end
26
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ class InvalidVerificationRoute < StandardError
6
+ def new(route:)
7
+ msg = <<~MSG
8
+ You specified a direct handler but you're trying to use `#{route}`
9
+ which is only available for multi-step authorization workflows. Change
10
+ your workflow to define an engine with a `#{route}` route.
11
+ MSG
12
+
13
+ super(msg)
14
+ end
15
+ end
16
+
17
+ class UnregisteredVerificationManifest < StandardError
18
+ end
19
+
20
+ #
21
+ # Provides a unified interface for direct and deferred authorizations, so
22
+ # they can be used transparently
23
+ #
24
+ class Adapter
25
+ include Rails.application.routes.mounted_helpers
26
+
27
+ def self.from_collection(collection)
28
+ collection.map { |e| from_element(e) }
29
+ end
30
+
31
+ def self.from_element(element)
32
+ manifest = Verifications.find_workflow_manifest(element)
33
+
34
+ raise UnregisteredVerificationManifest unless manifest
35
+
36
+ new(manifest)
37
+ end
38
+
39
+ def initialize(manifest)
40
+ @manifest = manifest
41
+ end
42
+
43
+ delegate :key, :name, :fullname, :description, :type, to: :manifest
44
+
45
+ #
46
+ # Main entry point for the verification engine
47
+ #
48
+ def root_path(redirect_url: nil)
49
+ if manifest.type == "direct"
50
+ decidim_verifications.new_authorization_path(handler: name, redirect_url: redirect_url)
51
+ else
52
+ main_engine.send(:root_path, redirect_url: redirect_url)
53
+ end
54
+ end
55
+
56
+ #
57
+ # In the case of deferred authorizations, route to resume an authorization
58
+ # process. Otherwise it rises
59
+ #
60
+ def resume_authorization_path(redirect_url: nil)
61
+ if manifest.type == "direct"
62
+ raise InvalidDirectVerificationRoute.new(route: "edit_authorization_path")
63
+ end
64
+
65
+ main_engine.send(:edit_authorization_path, redirect_url: redirect_url)
66
+ end
67
+
68
+ #
69
+ # Administrational entry point for the verification engine
70
+ #
71
+ def admin_root_path
72
+ if manifest.type == "direct"
73
+ raise InvalidDirectVerificationROute.new(route: "admin_route_path")
74
+ end
75
+
76
+ public_send(:"decidim_admin_#{name}").send(:root_path)
77
+ end
78
+
79
+ private
80
+
81
+ attr_reader :manifest
82
+
83
+ def main_engine
84
+ send("decidim_#{manifest.name}")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Decidim::Verifications.register_workflow(:dummy_authorization_handler) do |workflow|
4
+ workflow.form = "Decidim::DummyAuthorizationHandler"
5
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ # Decidim's core Rails Engine.
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace Decidim::Verifications
8
+
9
+ routes do
10
+ authenticate(:user) do
11
+ resources :authorizations, only: [:new, :create, :index] do
12
+ collection do
13
+ get :first_login
14
+ end
15
+ end
16
+
17
+ Decidim.authorization_engines.each do |manifest|
18
+ mount manifest.engine, at: "/#{manifest.name}", as: "decidim_#{manifest.name}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/verifications/id_documents/admin"
4
+ require "decidim/verifications/id_documents/engine"
5
+ require "decidim/verifications/id_documents/admin_engine"
6
+ require "decidim/verifications/id_documents/workflow"
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module IdDocuments
6
+ # This module contains all the domain logic associated to Decidim's
7
+ # identity documents authorization admin panel.
8
+ module Admin
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module IdDocuments
6
+ # This is an engine that performs an example user authorization.
7
+ class AdminEngine < ::Rails::Engine
8
+ isolate_namespace Decidim::Verifications::IdDocuments::Admin
9
+
10
+ routes do
11
+ resources :pending_authorizations, only: :index do
12
+ resource :confirmations, only: [:new, :create], as: :confirmation
13
+ resource :rejections, only: :create, as: :rejection
14
+ end
15
+
16
+ root to: "pending_authorizations#index"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module IdDocuments
6
+ # This is an engine that performs an example user authorization.
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace Decidim::Verifications::IdDocuments
9
+
10
+ routes do
11
+ resource :authorizations, only: [:new, :create, :edit, :update], as: :authorization
12
+
13
+ root to: "authorizations#new"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Decidim::Verifications.register_workflow(:id_documents) do |workflow|
4
+ workflow.engine = Decidim::Verifications::IdDocuments::Engine
5
+ workflow.admin_engine = Decidim::Verifications::IdDocuments::AdminEngine
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/verifications/postal_letter/admin"
4
+ require "decidim/verifications/postal_letter/engine"
5
+ require "decidim/verifications/postal_letter/admin_engine"
6
+ require "decidim/verifications/postal_letter/workflow"
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module PostalLetter
6
+ # This module contains all the domain logic associated to Decidim's
7
+ # postal letter authorization admin panel.
8
+ module Admin
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module PostalLetter
6
+ # This is an engine that implements the administration interface for
7
+ # user authorization by postal letter code.
8
+ class AdminEngine < ::Rails::Engine
9
+ isolate_namespace Decidim::Verifications::PostalLetter::Admin
10
+
11
+ routes do
12
+ resources :pending_authorizations, only: :index do
13
+ resource :postages, only: :create, as: :postage
14
+ end
15
+
16
+ root to: "pending_authorizations#index"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Verifications
5
+ module PostalLetter
6
+ # This is an engine that performs an example user authorization.
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace Decidim::Verifications::PostalLetter
9
+
10
+ routes do
11
+ resource :authorizations, only: [:new, :create, :edit, :update], as: :authorization
12
+
13
+ root to: "authorizations#new"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Decidim::Verifications.register_workflow(:postal_letter) do |workflow|
4
+ workflow.engine = Decidim::Verifications::PostalLetter::Engine
5
+ workflow.admin_engine = Decidim::Verifications::PostalLetter::AdminEngine
6
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/verifications/workflow_manifest"
4
+
5
+ module Decidim
6
+ module Verifications
7
+ #
8
+ # Takes care of holding and accessing verification methods.
9
+ #
10
+ class Registry
11
+ def register_workflow(name)
12
+ manifest = WorkflowManifest.new(name: name.to_s)
13
+ yield(manifest)
14
+ add_workflow(manifest)
15
+ end
16
+
17
+ def add_workflow(manifest)
18
+ manifest.validate!
19
+ workflow_collection.add(manifest)
20
+ end
21
+
22
+ def clear_workflows
23
+ workflow_collection.clear
24
+ end
25
+
26
+ def reset_workflows(*manifests)
27
+ clear_workflows
28
+
29
+ manifests.each do |manifest|
30
+ add_workflow(manifest)
31
+ end
32
+ end
33
+
34
+ def workflow_collection
35
+ @workflow_collection ||= Set.new
36
+ end
37
+ end
38
+ end
39
+ end