decidim-direct_verifications 0.17.7 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdece320908b5c93c6b1312fae64fbb23814d8c48e99bd258cdee55dcb2b37b3
4
- data.tar.gz: 0d70c5cf75fd68c848ce52328589cce67524197f5cc95dbcbd2ff5cc7d559ed5
3
+ metadata.gz: 860fec657e68dab8325cde196bbfaa66059ede6b76414bb250a549d5639ebe6e
4
+ data.tar.gz: f40a1f9bb946c0254c518cba3dd05a1e1764bd23729270e80554076cd07ffc12
5
5
  SHA512:
6
- metadata.gz: ce76ca5c3dcf855eba9f1ecd0d963bfb03791a80ed9fbee729e891932a96390b94df9ca748e19f73aaefb03afd5f55b0a1b873eb470eccf3d67b9e116118d23f
7
- data.tar.gz: 761e7647eeb5d859c17694a8c681d9538cd6ffd680071d7f9f4cbe7d3aa3c718fac5451ed9624fdfad8a0e5101cd95690a3cce3d3e514e11ba7d2fa708478082
6
+ metadata.gz: 87f25e203fe473612d2b53ae4986a5452d2096f12543d00eba10c1a8ba7d04c09471cbc9a15eed4916281ea07186152c61d630d0e40320c27d63cde699b6b7a0
7
+ data.tar.gz: b3c34eccfd75f9849c5866fc402969fc7c0e2c99313983bd302fe025254e299356790697ed34ab9f96ef8c4cace2c335dd3bb6f4dbb412f9073c4316c1554d10
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Decidim::DirectVerifications
2
2
 
3
- [![Build Status](https://travis-ci.org/Platoniq/decidim-verifications-direct_verifications.svg?branch=master)](https://travis-ci.org/Platoniq/decidim-verifications-direct_verifications)
3
+ ![Test](https://github.com/Platoniq/decidim-verifications-direct_verifications/workflows/Test/badge.svg)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/2195deb4de6c6354a6bc/maintainability)](https://codeclimate.com/github/Platoniq/decidim-verifications-direct_verifications/maintainability)
5
+ [![codecov](https://codecov.io/gh/Platoniq/decidim-verifications-direct_verifications/branch/master/graph/badge.svg?token=FR1zkV71S2)](https://codecov.io/gh/Platoniq/decidim-verifications-direct_verifications)
4
6
 
5
7
  A [Decidim](https://github.com/decidim/decidim) that provides a verification method called `Direct verification`. Works only on the admin side, final users do not intervene in the verification process.
6
8
 
@@ -84,6 +86,11 @@ en:
84
86
  direct_verifications_managers:
85
87
  name: Organization managers
86
88
  explanation: Direct Verifications Subgroup explanation
89
+ verifications:
90
+ authorizations:
91
+ first_login:
92
+ actions:
93
+ direct_verifications_managers: Organization managers
87
94
  ```
88
95
 
89
96
  Similarly, you can also overwrite the default title "Direct verification" by creating the key again in your locales:
@@ -95,6 +102,11 @@ en:
95
102
  direct_verifications:
96
103
  name: Generic organization members
97
104
  explanation: Direct Verifications Subgroup explanation
105
+ verifications:
106
+ authorizations:
107
+ first_login:
108
+ actions:
109
+ direct_verifications: Generic organization members
98
110
  ```
99
111
 
100
112
 
@@ -6,73 +6,98 @@ module Decidim
6
6
  module Admin
7
7
  class DirectVerificationsController < Decidim::Admin::ApplicationController
8
8
  include NeedsPermission
9
+ helper_method :workflows, :current_authorization_handler
9
10
 
10
11
  layout "decidim/admin/users"
11
12
 
12
13
  def index
13
14
  enforce_permission_to :index, :authorization
14
- @authorization_handler = :direct_verifications
15
- @workflows = workflows
16
15
  end
17
16
 
18
17
  def create
19
18
  enforce_permission_to :create, :authorization
20
19
 
21
- @userlist = params[:userlist]
22
- @workflows = workflows
23
- processor = UserProcessor.new(current_organization, current_user)
24
- processor.emails = extract_emails_to_hash @userlist
25
- processor.authorization_handler = authorization_handler(params[:authorization_handler])
26
- stats = UserStats.new(current_organization)
27
- stats.authorization_handler = processor.authorization_handler
28
- if params[:register]
29
- processor.register_users
30
- flash[:warning] = t(".registered", count: processor.emails.count,
31
- registered: processor.processed[:registered].count,
32
- errors: processor.errors[:registered].count)
33
- end
34
- if params[:authorize] == "in"
35
- processor.authorize_users
36
- flash[:notice] = t(".authorized", handler: t("#{processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
37
- count: processor.emails.count,
38
- authorized: processor.processed[:authorized].count,
39
- errors: processor.errors[:authorized].count)
40
- elsif params[:authorize] == "out"
41
- processor.revoke_users
42
- flash[:notice] = t(".revoked", handler: t("#{processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
43
- count: processor.emails.count,
44
- revoked: processor.processed[:revoked].count,
45
- errors: processor.errors[:revoked].count)
46
- else
47
- stats.emails = processor.emails.keys
48
- flash[:info] = t(".info", handler: t("#{processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
49
- count: processor.emails.count,
50
- authorized: stats.authorized,
51
- unconfirmed: stats.unconfirmed,
52
- registered: stats.registered)
53
- render(action: :index) && return
54
- end
20
+ @userslist = params[:userslist]
21
+ @processor = UserProcessor.new(current_organization, current_user, session)
22
+ @processor.emails = extract_emails_to_hash @userslist
23
+ @processor.authorization_handler = current_authorization_handler
24
+ @stats = UserStats.new(current_organization)
25
+ @stats.authorization_handler = @processor.authorization_handler
26
+ register_users
27
+ authorize_users
28
+ revoke_users
29
+
30
+ render(action: :index) && return if show_users_info
31
+
55
32
  redirect_to direct_verifications_path
56
33
  end
57
34
 
58
35
  private
59
36
 
37
+ def register_users
38
+ return unless params[:register]
39
+
40
+ @processor.register_users
41
+ flash[:warning] = t(".registered", count: @processor.emails.count,
42
+ registered: @processor.processed[:registered].count,
43
+ errors: @processor.errors[:registered].count)
44
+ end
45
+
46
+ def authorize_users
47
+ return unless params[:authorize] == "in"
48
+
49
+ @processor.authorize_users
50
+ flash[:notice] = t(".authorized", handler: t("#{@processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
51
+ count: @processor.emails.count,
52
+ authorized: @processor.processed[:authorized].count,
53
+ errors: @processor.errors[:authorized].count)
54
+ end
55
+
56
+ def revoke_users
57
+ return unless params[:authorize] == "out"
58
+
59
+ @processor.revoke_users
60
+ flash[:notice] = t(".revoked", handler: t("#{@processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
61
+ count: @processor.emails.count,
62
+ revoked: @processor.processed[:revoked].count,
63
+ errors: @processor.errors[:revoked].count)
64
+ end
65
+
66
+ def show_users_info
67
+ return if params[:authorize].in? %w(in out)
68
+
69
+ @stats.emails = @processor.emails.keys
70
+ flash.now[:info] = t(".info", handler: t("#{@processor.authorization_handler}.name", scope: "decidim.authorization_handlers"),
71
+ count: @processor.emails.count,
72
+ authorized: @stats.authorized,
73
+ unconfirmed: @stats.unconfirmed,
74
+ registered: @stats.registered)
75
+ true
76
+ end
77
+
60
78
  def extract_emails_to_hash(txt)
61
- reg = /([^@\r\n]*)\b([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,})\b/i
62
- txt.scan(reg).map do |m|
63
- [
64
- m[1].delete("<>").strip,
65
- m[0].gsub(/[^[:print:]]|[\"\$\<\>\|\\]/, "").strip
66
- ]
67
- end .to_h
79
+ reg = /([A-Z0-9+._-]+@[A-Z0-9._-]+\.[A-Z0-9_-]+)\b/i
80
+ emails = {}
81
+ txt.split(/[\r\n;,]/).each do |line|
82
+ reg.match line do |m|
83
+ n = line.split(m[0]).first
84
+ emails[m[0]] = (n.presence || "").gsub(/[^[:print:]]|[\"\$\<\>\|\\]/, "").strip
85
+ end
86
+ end
87
+ emails
68
88
  end
69
89
 
70
90
  def authorization_handler(authorization_handler)
71
91
  @authorization_handler = authorization_handler.presence || :direct_verifications
72
92
  end
73
93
 
94
+ def current_authorization_handler
95
+ authorization_handler(params[:authorization_handler])
96
+ end
97
+
74
98
  def configured_workflows
75
99
  return Decidim::DirectVerifications.config.manage_workflows if Decidim::DirectVerifications.config
100
+
76
101
  ["direct_verifications"]
77
102
  end
78
103
 
@@ -1,40 +1,40 @@
1
1
  <div class="card">
2
2
  <div class="card-divider">
3
3
  <h2 class="card-title">
4
- <%= t('admin.index.title', scope: 'decidim.direct_verifications.verification') %>
5
- <%= link_to t("admin.index.stats", scope: 'decidim.direct_verifications.verification'), stats_path, class: "button tiny button--title" %>
4
+ <%= t("admin.index.title", scope: "decidim.direct_verifications.verification") %>
5
+ <%= link_to t("admin.index.stats", scope: "decidim.direct_verifications.verification"), stats_path, class: "button tiny button--title" %>
6
6
  </h2>
7
7
  </div>
8
8
  <div class="card-section">
9
- <p><%= t('decidim.direct_verifications.verification.admin.new.info') %></p>
10
- <%= form_tag direct_verifications_path, multipart: true, class: 'form' do %>
11
- <%= label_tag :userlist, t('admin.new.textarea', scope: 'decidim.direct_verifications.verification') %>
12
- <%= text_area_tag :userlist, @userlist, rows: 10 %>
9
+ <p><%= t("decidim.direct_verifications.verification.admin.new.info") %></p>
10
+ <%= form_tag direct_verifications_path, multipart: true, class: "form" do %>
11
+ <%= label_tag :userslist, t("admin.new.textarea", scope: "decidim.direct_verifications.verification") %>
12
+ <%= text_area_tag :userslist, @userslist, rows: 10 %>
13
13
  <label>
14
14
  <%= check_box_tag :register %>
15
- <%= t('admin.new.register', scope: 'decidim.direct_verifications.verification') %>
15
+ <%= t("admin.new.register", scope: "decidim.direct_verifications.verification") %>
16
16
  <div data-alert class="callout alert hide">
17
- <%= t('admin.direct_verifications.gdpr_disclaimer', scope: 'decidim.direct_verifications.verification') %>
17
+ <%= t("admin.direct_verifications.gdpr_disclaimer", scope: "decidim.direct_verifications.verification") %>
18
18
  </div>
19
19
  </label>
20
20
  <label>
21
- <%= radio_button_tag :authorize, 'in' %>
22
- <%= t('admin.new.authorize', scope: 'decidim.direct_verifications.verification') %>
21
+ <%= radio_button_tag :authorize, "in" %>
22
+ <%= t("admin.new.authorize", scope: "decidim.direct_verifications.verification") %>
23
23
  </label>
24
24
  <label>
25
- <%= radio_button_tag :authorize, 'out' %>
26
- <%= t('admin.new.revoke', scope: 'decidim.direct_verifications.verification') %>
25
+ <%= radio_button_tag :authorize, "out" %>
26
+ <%= t("admin.new.revoke", scope: "decidim.direct_verifications.verification") %>
27
27
  </label>
28
28
  <label>
29
- <%= radio_button_tag :authorize, 'check', true %>
30
- <%= t('admin.new.check', scope: 'decidim.direct_verifications.verification') %>
29
+ <%= radio_button_tag :authorize, "check", true %>
30
+ <%= t("admin.new.check", scope: "decidim.direct_verifications.verification") %>
31
31
  </label>
32
32
 
33
- <%= label_tag :authorization_handler, t('admin.new.authorization_handler', scope: 'decidim.direct_verifications.verification') %>
33
+ <%= label_tag :authorization_handler, t("admin.new.authorization_handler", scope: "decidim.direct_verifications.verification") %>
34
34
 
35
- <%= select_tag :authorization_handler, options_for_select(@workflows, @authorization_handler) %>
35
+ <%= select_tag :authorization_handler, options_for_select(workflows, current_authorization_handler) %>
36
36
 
37
- <%= submit_tag t('admin.new.submit', scope: 'decidim.direct_verifications.verification'), class: 'button' %>
37
+ <%= submit_tag t("admin.new.submit", scope: "decidim.direct_verifications.verification"), class: "button" %>
38
38
 
39
39
  <% end %>
40
40
 
@@ -1,15 +1,15 @@
1
1
  <div class="card">
2
2
  <div class="card-divider">
3
3
  <h2 class="card-title">
4
- <%= t('admin.index.stats', scope: 'decidim.direct_verifications.verification') %>
5
- <%= link_to t("admin.index.title", scope: 'decidim.direct_verifications.verification'), direct_verifications_path, class: "button tiny button--title" %>
4
+ <%= t("admin.index.stats", scope: "decidim.direct_verifications.verification") %>
5
+ <%= link_to t("admin.index.title", scope: "decidim.direct_verifications.verification"), direct_verifications_path, class: "button tiny button--title" %>
6
6
  </h2>
7
7
  </div>
8
8
  <div class="card-section">
9
9
  <table class="table-list">
10
10
  <thead>
11
11
  <tr>
12
- <th><%= t("admin.new.authorization_handler", scope: 'decidim.direct_verifications.verification') %></th>
12
+ <th><%= t("admin.new.authorization_handler", scope: "decidim.direct_verifications.verification") %></th>
13
13
  <th><%= t(".registered") %></th>
14
14
  <th><%= t(".authorized") %></th>
15
15
  <th><%= t(".unconfirmed") %></th>
@@ -59,6 +59,11 @@ ca:
59
59
  authorizations:
60
60
  new:
61
61
  no_action: Aquest mètode requereix que un administrador us verifiqui
62
+ verifications:
63
+ authorizations:
64
+ first_login:
65
+ actions:
66
+ direct_verifications: Verificació directa
62
67
  devise:
63
68
  mailer:
64
69
  direct_invite:
@@ -57,6 +57,11 @@ en:
57
57
  authorizations:
58
58
  new:
59
59
  no_action: This method requires an administrator that verifies you
60
+ verifications:
61
+ authorizations:
62
+ first_login:
63
+ actions:
64
+ direct_verifications: Direct verification
60
65
  devise:
61
66
  mailer:
62
67
  direct_invite:
@@ -59,6 +59,11 @@ es:
59
59
  authorizations:
60
60
  new:
61
61
  no_action: Este método requiere que un administrador os verifique
62
+ verifications:
63
+ authorizations:
64
+ first_login:
65
+ actions:
66
+ direct_verifications: Verificación directa
62
67
  devise:
63
68
  mailer:
64
69
  direct_invite:
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_examples_for "checking users" do |params|
4
+ context "when check without mails" do
5
+ it "renders the index with info message" do
6
+ params[:userslist] = ""
7
+ perform_enqueued_jobs do
8
+ post :create, params: params
9
+ expect(flash[:info]).not_to be_empty
10
+ expect(flash[:info]).to include("0 users detected")
11
+ expect(subject).to render_template("decidim/direct_verifications/verification/admin/direct_verifications/index")
12
+ end
13
+ end
14
+ end
15
+
16
+ context "when check with mails" do
17
+ it "renders the index with info message" do
18
+ params[:userslist] = "mail@example.com"
19
+ perform_enqueued_jobs do
20
+ post :create, params: params
21
+ expect(flash[:info]).not_to be_empty
22
+ expect(flash[:info]).to include("1 users detected")
23
+ expect(subject).to render_template("decidim/direct_verifications/verification/admin/direct_verifications/index")
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ shared_examples_for "registering users" do |params|
30
+ context "when there are valid emails" do
31
+ it "creates warning message" do
32
+ perform_enqueued_jobs do
33
+ post :create, params: params
34
+ expect(flash[:warning]).not_to be_empty
35
+ expect(flash[:warning]).to include("1 detected")
36
+ expect(flash[:warning]).to include("0 errors")
37
+ expect(flash[:warning]).to include("1 users")
38
+ expect(flash[:warning]).to include("registered")
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ shared_examples_for "authorizing users" do |params|
45
+ context "when there are valid emails" do
46
+ it "creates notice message" do
47
+ perform_enqueued_jobs do
48
+ post :create, params: params
49
+ expect(flash[:notice]).not_to be_empty
50
+ expect(flash[:notice]).to include("1 detected")
51
+ expect(flash[:notice]).to include("0 errors")
52
+ expect(flash[:notice]).to include("1 users")
53
+ expect(flash[:notice]).to include("verified")
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ shared_examples_for "revoking users" do |params|
60
+ context "when there are valid emails" do
61
+ it "creates notice message" do
62
+ create(
63
+ :authorization,
64
+ :granted,
65
+ name: verification_type,
66
+ user: authorized_user
67
+ )
68
+ perform_enqueued_jobs do
69
+ post :create, params: params
70
+ expect(flash[:notice]).not_to be_empty
71
+ expect(flash[:notice]).to include("1 detected")
72
+ expect(flash[:notice]).to include("0 errors")
73
+ expect(flash[:notice]).to include("1 users")
74
+ expect(flash[:notice]).to include("revoked")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -3,16 +3,17 @@
3
3
  module Decidim
4
4
  module DirectVerifications
5
5
  class UserProcessor
6
- def initialize(organization, current_user)
6
+ def initialize(organization, current_user, session)
7
7
  @organization = organization
8
8
  @current_user = current_user
9
9
  @authorization_handler = :direct_verifications
10
10
  @errors = { registered: [], authorized: [], revoked: [] }
11
11
  @processed = { registered: [], authorized: [], revoked: [] }
12
12
  @emails = {}
13
+ @session = session
13
14
  end
14
15
 
15
- attr_reader :organization, :current_user, :errors, :processed, :emails
16
+ attr_reader :organization, :current_user, :session, :errors, :processed, :emails
16
17
  attr_accessor :authorization_handler
17
18
 
18
19
  def emails=(email_list)
@@ -22,6 +23,7 @@ module Decidim
22
23
  def register_users
23
24
  @emails.each do |email, name|
24
25
  next if find_user(email)
26
+
25
27
  form = register_form(email, name)
26
28
  begin
27
29
  InviteUser.call(form) do
@@ -44,7 +46,8 @@ module Decidim
44
46
  if (u = find_user(email))
45
47
  auth = authorization(u)
46
48
  next unless !auth.granted? || auth.expired?
47
- Verification::ConfirmUserAuthorization.call(auth, authorize_form(u)) do
49
+
50
+ Verification::ConfirmUserAuthorization.call(auth, authorize_form(u), session) do
48
51
  on(:ok) do
49
52
  add_processed :authorized, email
50
53
  end
@@ -63,6 +66,7 @@ module Decidim
63
66
  if (u = find_user(email))
64
67
  auth = authorization(u)
65
68
  next unless auth.granted?
69
+
66
70
  Verification::DestroyUserAuthorization.call(auth) do
67
71
  on(:ok) do
68
72
  add_processed :revoked, email
@@ -39,7 +39,7 @@ module Decidim
39
39
  if authorization_handler.empty?
40
40
  filter = { decidim_organization_id: organization.id }
41
41
  filter[:email] = emails unless emails.empty?
42
- return User.where(filter)
42
+ return User.where(filter).where.not(email: "")
43
43
  end
44
44
  authorized_users(false)
45
45
  end
@@ -53,19 +53,22 @@ module Decidim
53
53
  q = q.where("decidim_authorizations.granted_at >= :date", date: Time.current - expires_in) if expires_in
54
54
  end
55
55
  end
56
- q = q.where("decidim_users.decidim_organization_id=:org", org: organization.id)
56
+ q = q.where("decidim_users.decidim_organization_id=:org and decidim_users.email!=''", org: organization.id)
57
57
  return q if emails.empty?
58
+
58
59
  q.where("decidim_users.email IN (:emails)", emails: emails)
59
60
  end
60
61
 
61
62
  def expires_in
62
63
  return unless workflow_manifest
63
64
  return if workflow_manifest.expires_in.zero?
65
+
64
66
  workflow_manifest.expires_in
65
67
  end
66
68
 
67
69
  def workflow_manifest
68
70
  return if authorization_handler.empty?
71
+
69
72
  @workflow_manifest ||= Decidim::Verifications.find_workflow_manifest(authorization_handler)
70
73
  end
71
74
  end
@@ -3,7 +3,8 @@
3
3
  module Decidim
4
4
  # This holds the decidim-direct_verifications version.
5
5
  module DirectVerifications
6
- VERSION = "0.17.7"
7
- DECIDIM_VERSION = ">= 0.17.0"
6
+ VERSION = "0.22.1"
7
+ DECIDIM_VERSION = "0.22"
8
+ MIN_DECIDIM_VERSION = ">= 0.22.0"
8
9
  end
9
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-direct_verifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.7
4
+ version: 0.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Vergés
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-admin
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.17.0
19
+ version: 0.22.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.17.0
26
+ version: 0.22.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: decidim-core
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.17.0
33
+ version: 0.22.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.17.0
40
+ version: 0.22.0
41
41
  description: Provides a verification method that also registers users directly in
42
42
  the platform. Can be used to mass verificate user with other verification handlers
43
43
  email:
@@ -66,6 +66,7 @@ files:
66
66
  - config/locales/es.yml
67
67
  - lib/decidim/direct_verifications.rb
68
68
  - lib/decidim/direct_verifications/config.rb
69
+ - lib/decidim/direct_verifications/tests/verification_controller_examples.rb
69
70
  - lib/decidim/direct_verifications/user_processor.rb
70
71
  - lib/decidim/direct_verifications/user_stats.rb
71
72
  - lib/decidim/direct_verifications/verification.rb