decidim-file_authorization_handler 0.27.1.6 → 0.28.2.0
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 +4 -4
- data/app/services/file_authorization_handler.rb +7 -4
- data/app/views/decidim/file_authorization_handler/admin/censuses/_upload_info.html.erb +5 -0
- data/app/views/decidim/file_authorization_handler/admin/censuses/show.html.erb +32 -27
- data/config/locales/ca.yml +2 -1
- data/config/locales/en.yml +2 -1
- data/config/locales/es.yml +2 -1
- data/lib/decidim/file_authorization_handler/admin_engine.rb +6 -5
- data/lib/decidim/file_authorization_handler/version.rb +2 -2
- metadata +13 -82
- data/spec/controllers/decidim/file_authorization_handler/admin/censuses_controller_spec.rb +0 -57
- data/spec/factories/census_datum.rb +0 -14
- data/spec/factories/factories.rb +0 -3
- data/spec/fixtures/files/data-with_extras.csv +0 -5
- data/spec/fixtures/files/data1.csv +0 -4
- data/spec/fixtures/files/with-errors.csv +0 -7
- data/spec/helpers/decidim/file_authorization_handler/encoding_helper.rb +0 -11
- data/spec/jobs/decidim/file_authorization_handler/remove_duplicates_job_spec.rb +0 -20
- data/spec/models/decidim/file_authorization_handler/census_datum_spec.rb +0 -75
- data/spec/models/decidim/file_authorization_handler/csv_data_spec.rb +0 -41
- data/spec/models/decidim/file_authorization_handler/status_spec.rb +0 -21
- data/spec/permissions/decidim/file_authorization_handler/admin/permissions_spec.rb +0 -58
- data/spec/services/decidim/file_authorization_handler/file_authorization_handler_spec.rb +0 -77
- data/spec/spec_helper.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91f007f8c10ff184e7828552c2b527075bcdbf4aa220db5cb2c48ef5dbcc6cbf
|
4
|
+
data.tar.gz: f0bfd5bfe3b636c4974d5f56baddb475c0a09c672c35fa07a56905016bdedf31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f00f12a1073047d26ea7ffabc370d5df5902f8192100de698a6f8d8286a0a17e41f3f05c5a92f623b21aa0b573e2ff72457a862ec1252cc1a5e2e9106952f5
|
7
|
+
data.tar.gz: de3cf55b3c36e17303cb1b48cbb8a905e66c57bedadcd5e91347997594b171d83a028475219c0bd94fa90b83003562f38fca90398f3cefad15c1431d489a8ce2
|
@@ -5,9 +5,6 @@
|
|
5
5
|
class FileAuthorizationHandler < Decidim::AuthorizationHandler
|
6
6
|
# This is the input (from the user) to validate against
|
7
7
|
attribute :id_document, String
|
8
|
-
# This is a hack in order to sign initiatives because in decidim-initiatives/app/forms/decidim/initiatives/vote_form.rb
|
9
|
-
# send to handler_for a param named document_number.
|
10
|
-
attribute :document_number, String
|
11
8
|
attribute :birthdate, Decidim::Attributes::LocalizedDate
|
12
9
|
|
13
10
|
# This is the validation to perform
|
@@ -16,6 +13,12 @@ class FileAuthorizationHandler < Decidim::AuthorizationHandler
|
|
16
13
|
validates :birthdate, presence: true
|
17
14
|
validate :censed
|
18
15
|
|
16
|
+
# Customized constructor to support decidim-initiatives.
|
17
|
+
def initialize(params)
|
18
|
+
params[:id_document] = params.delete(:document_number) unless params.has_key?(:id_document)
|
19
|
+
super(params)
|
20
|
+
end
|
21
|
+
|
19
22
|
def metadata
|
20
23
|
@metadata ||= begin
|
21
24
|
meta = { birthdate: census_for_user&.birthdate&.strftime("%Y/%m/%d") }
|
@@ -53,7 +56,7 @@ class FileAuthorizationHandler < Decidim::AuthorizationHandler
|
|
53
56
|
return unless organization
|
54
57
|
|
55
58
|
@census_for_user ||= Decidim::FileAuthorizationHandler::CensusDatum
|
56
|
-
.search_id_document(organization, id_document
|
59
|
+
.search_id_document(organization, id_document)
|
57
60
|
end
|
58
61
|
|
59
62
|
def organization
|
@@ -1,39 +1,44 @@
|
|
1
|
+
<% add_decidim_page_title(t("admin.show.title", scope: "decidim.file_authorization_handler")) %>
|
1
2
|
|
2
3
|
<div class="card">
|
3
|
-
<div class="card-
|
4
|
-
<
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
<div class="card-section p-4">
|
5
|
+
<div class="item_show__header">
|
6
|
+
<h1 class="item_show__header-title">
|
7
|
+
<%= t("admin.show.title", scope: "decidim.file_authorization_handler") %>
|
8
|
+
<% if @status.count > 0 %>
|
9
|
+
<%= link_to t('decidim.file_authorization_handler.admin.destroy.title'),
|
10
|
+
censuses_path,
|
11
|
+
method: :delete,
|
12
|
+
class: 'button button__sm button__secondary alert hollow tiny button--title destroy',
|
13
|
+
data: { confirm: t('decidim.file_authorization_handler.admin.destroy.confirm') } %>
|
14
|
+
<% end %>
|
15
|
+
</h1>
|
16
|
+
</div>
|
9
17
|
<% if @status.count > 0 %>
|
10
18
|
<p><%= t('decidim.file_authorization_handler.admin.show.data', count: @status.count,
|
11
19
|
due_date: l(@status.last_import_at, format: :long)) %>
|
12
20
|
</p>
|
13
|
-
|
14
|
-
|
15
|
-
method: :delete,
|
16
|
-
class: 'button alert',
|
17
|
-
data: { confirm: t('decidim.file_authorization_handler.admin.destroy.confirm') } %>
|
18
|
-
<% else %>
|
19
|
-
<p><%= t('admin.show.empty', scope: 'decidim.file_authorization_handler') %></p>
|
21
|
+
<% else %>
|
22
|
+
<p><%= t('admin.show.empty', scope: 'decidim.file_authorization_handler') %></p>
|
20
23
|
<% end %>
|
21
24
|
</div>
|
22
|
-
</div>
|
23
25
|
|
26
|
+
<div id="wrapper-action-view">
|
27
|
+
<div class="card-section p-4">
|
28
|
+
<div class="item_show__header">
|
29
|
+
|
30
|
+
<h1 class="item_show__header-title">
|
31
|
+
<%= t("admin.new.title", scope: "decidim.file_authorization_handler") %><div class="card-section p-4">
|
32
|
+
</h1>
|
33
|
+
</div>
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
<%= form_tag censuses_path, multipart: true, class: 'form' do %>
|
34
|
-
<%= label_tag :name, t('admin.new.file', scope: 'decidim.file_authorization_handler') %>
|
35
|
-
<%= file_field_tag :file %>
|
36
|
-
<%= submit_tag t('admin.new.submit', scope: 'decidim.file_authorization_handler'), class: 'button' %>
|
37
|
-
<% end %>
|
35
|
+
<%= render "upload_info" %>
|
36
|
+
|
37
|
+
<%= form_tag censuses_path, multipart: true, class: 'form' do %>
|
38
|
+
<%= label_tag :name, t('admin.new.file', scope: 'decidim.file_authorization_handler') %>
|
39
|
+
<%= file_field_tag :file %>
|
40
|
+
<%= submit_tag t('admin.new.submit', scope: 'decidim.file_authorization_handler'), class: 'button button__sm button__secondary hollow tiny button--title' %>
|
41
|
+
<% end %>
|
42
|
+
</div>
|
38
43
|
</div>
|
39
44
|
</div>
|
data/config/locales/ca.yml
CHANGED
@@ -19,6 +19,8 @@ ca:
|
|
19
19
|
fields:
|
20
20
|
birthdate: Data de naixement
|
21
21
|
file_authorization_handler:
|
22
|
+
upload_info:
|
23
|
+
format: "Ha de ser un fitxer generat en excel i exportat en CSV amb dues columnes:"
|
22
24
|
errors:
|
23
25
|
messages:
|
24
26
|
not_censed: No hem pogut trobar el teu document d'identitat amb aquesta data de naixement al padró municipal. Si les dades són correctes i el problema persisteix, siusplau, posa't en contacte amb un administrador.
|
@@ -39,7 +41,6 @@ ca:
|
|
39
41
|
data: Hi ha un total de %{count} registres carregats. La última càrrega va ser el dia %{due_date}
|
40
42
|
empty: Encara no hi ha dades censals carregades. Utilitza el següent formulari per importar-lo utilitzant un fitxer CSV.
|
41
43
|
new:
|
42
|
-
info: "Ha de ser un fitxer generat en excel i exportat en CSV amb dues columnes: document d'identitat i data de naixement"
|
43
44
|
title: Pujar un nou cens
|
44
45
|
file: Arxiu excel .csv amb les dades del cens
|
45
46
|
submit: Carrega
|
data/config/locales/en.yml
CHANGED
@@ -19,6 +19,8 @@ en:
|
|
19
19
|
fields:
|
20
20
|
birthdate: Birthdate
|
21
21
|
file_authorization_handler:
|
22
|
+
upload_info:
|
23
|
+
format: 'Must be a file generated by excel and exported with CSV format with two columns:'
|
22
24
|
errors:
|
23
25
|
messages:
|
24
26
|
not_censed: We could not find your document ID matching with this birthdate in our Census. If the data entered is correct and the problem persists, please, contact an administrator.
|
@@ -39,7 +41,6 @@ en:
|
|
39
41
|
data: There are %{count} records loaded in total. Last upload date was on %{due_date}
|
40
42
|
empty: There are no census data. Use the form below to import it using a CSV file.
|
41
43
|
new:
|
42
|
-
info: 'Must be a file generated by excel and exported with CSV format with two columns: identity document and date of birth'
|
43
44
|
title: Upload a new census
|
44
45
|
file: Excel .csv file with census data
|
45
46
|
submit: Upload file
|
data/config/locales/es.yml
CHANGED
@@ -19,6 +19,8 @@ es:
|
|
19
19
|
fields:
|
20
20
|
birthdate: Fecha de nacimiento
|
21
21
|
file_authorization_handler:
|
22
|
+
upload_file:
|
23
|
+
format: 'Debe ser un fichero generado por excel y exportado en formato CSV con dos columnas:'
|
22
24
|
errors:
|
23
25
|
messages:
|
24
26
|
not_censed: No hemos podido encontrar tu documento de identidad con esta fecha de nacimiento en el padrón municipal. Si tus datos son correctos y el problema persiste, por favor, ponte en contacto con un administrador
|
@@ -39,7 +41,6 @@ es:
|
|
39
41
|
data: Hay un total de %{count} registros cargados. La última carga fue el día %{due_date}
|
40
42
|
empty: No hay datos censales. Usa el formulario a continuación para importar usando un fichero CSV.
|
41
43
|
new:
|
42
|
-
info: 'Debe ser un fichero generado por excel y exportado en formato CSV con dos columnas: documento de identidad y fecha de nacimiento'
|
43
44
|
title: Subir un nuevo censo
|
44
45
|
file: Archivo excel .csv con los datos del censo
|
45
46
|
submit: Subir archivo
|
@@ -11,11 +11,12 @@ module Decidim
|
|
11
11
|
|
12
12
|
initializer "decidim_file_authorization.add_admin_menu" do
|
13
13
|
Decidim.menu :admin_menu do |menu|
|
14
|
-
menu.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
menu.add_item :file_authorization_handler,
|
15
|
+
I18n.t("decidim.file_authorization_handler.admin.menu.census"),
|
16
|
+
decidim_file_authorization_handler_admin.censuses_path,
|
17
|
+
icon_name: "file-3-line",
|
18
|
+
position: 7,
|
19
|
+
active: :inclusive
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module FileAuthorizationHandler
|
5
|
-
DECIDIM_VERSION = "0.
|
5
|
+
DECIDIM_VERSION = "0.28.2"
|
6
6
|
|
7
7
|
# Uses the latest matching Decidim version for
|
8
8
|
# - major, minor and patch
|
9
9
|
# - the optional extra number is related to this module's patches
|
10
|
-
VERSION = "#{DECIDIM_VERSION}.
|
10
|
+
VERSION = "#{DECIDIM_VERSION}.0".freeze
|
11
11
|
end
|
12
12
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decidim-file_authorization_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.28.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Gómez
|
8
8
|
- Xavier Redó
|
9
9
|
- Oliver Valls
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: decidim
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.28.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
28
|
+
version: 0.28.2
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: decidim-admin
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.
|
35
|
+
version: 0.28.2
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.
|
42
|
+
version: 0.28.2
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rails
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,56 +60,14 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 0.
|
63
|
+
version: 0.28.2
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: 0.
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: faker
|
73
|
-
requirement: !ruby/object:Gem::Requirement
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
type: :development
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '0'
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: letter_opener_web
|
87
|
-
requirement: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - "~>"
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: 1.3.3
|
92
|
-
type: :development
|
93
|
-
prerelease: false
|
94
|
-
version_requirements: !ruby/object:Gem::Requirement
|
95
|
-
requirements:
|
96
|
-
- - "~>"
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: 1.3.3
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
name: listen
|
101
|
-
requirement: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
106
|
-
type: :development
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
70
|
+
version: 0.28.2
|
113
71
|
description: Census uploads via csv files
|
114
72
|
email:
|
115
73
|
- hola@marsbased.com
|
@@ -129,6 +87,7 @@ files:
|
|
129
87
|
- app/models/decidim/file_authorization_handler/status.rb
|
130
88
|
- app/permissions/decidim/file_authorization_handler/admin/permissions.rb
|
131
89
|
- app/services/file_authorization_handler.rb
|
90
|
+
- app/views/decidim/file_authorization_handler/admin/censuses/_upload_info.html.erb
|
132
91
|
- app/views/decidim/file_authorization_handler/admin/censuses/show.html.erb
|
133
92
|
- app/views/layouts/file_authorization_handler/application.html.erb
|
134
93
|
- config/locales/ca.yml
|
@@ -141,26 +100,12 @@ files:
|
|
141
100
|
- lib/decidim/file_authorization_handler/admin_engine.rb
|
142
101
|
- lib/decidim/file_authorization_handler/engine.rb
|
143
102
|
- lib/decidim/file_authorization_handler/version.rb
|
144
|
-
- spec/controllers/decidim/file_authorization_handler/admin/censuses_controller_spec.rb
|
145
|
-
- spec/factories/census_datum.rb
|
146
|
-
- spec/factories/factories.rb
|
147
|
-
- spec/fixtures/files/data-with_extras.csv
|
148
|
-
- spec/fixtures/files/data1.csv
|
149
|
-
- spec/fixtures/files/with-errors.csv
|
150
|
-
- spec/helpers/decidim/file_authorization_handler/encoding_helper.rb
|
151
|
-
- spec/jobs/decidim/file_authorization_handler/remove_duplicates_job_spec.rb
|
152
|
-
- spec/models/decidim/file_authorization_handler/census_datum_spec.rb
|
153
|
-
- spec/models/decidim/file_authorization_handler/csv_data_spec.rb
|
154
|
-
- spec/models/decidim/file_authorization_handler/status_spec.rb
|
155
|
-
- spec/permissions/decidim/file_authorization_handler/admin/permissions_spec.rb
|
156
|
-
- spec/services/decidim/file_authorization_handler/file_authorization_handler_spec.rb
|
157
|
-
- spec/spec_helper.rb
|
158
103
|
homepage: https://github.com/marsbased/
|
159
104
|
licenses:
|
160
105
|
- AGPLv3
|
161
106
|
metadata:
|
162
107
|
rubygems_mfa_required: 'true'
|
163
|
-
post_install_message:
|
108
|
+
post_install_message:
|
164
109
|
rdoc_options: []
|
165
110
|
require_paths:
|
166
111
|
- lib
|
@@ -176,21 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
121
|
version: '0'
|
177
122
|
requirements: []
|
178
123
|
rubygems_version: 3.3.26
|
179
|
-
signing_key:
|
124
|
+
signing_key:
|
180
125
|
specification_version: 4
|
181
126
|
summary: CSV document + birth date verifier
|
182
|
-
test_files:
|
183
|
-
- spec/controllers/decidim/file_authorization_handler/admin/censuses_controller_spec.rb
|
184
|
-
- spec/factories/census_datum.rb
|
185
|
-
- spec/factories/factories.rb
|
186
|
-
- spec/fixtures/files/data-with_extras.csv
|
187
|
-
- spec/fixtures/files/data1.csv
|
188
|
-
- spec/fixtures/files/with-errors.csv
|
189
|
-
- spec/helpers/decidim/file_authorization_handler/encoding_helper.rb
|
190
|
-
- spec/jobs/decidim/file_authorization_handler/remove_duplicates_job_spec.rb
|
191
|
-
- spec/models/decidim/file_authorization_handler/census_datum_spec.rb
|
192
|
-
- spec/models/decidim/file_authorization_handler/csv_data_spec.rb
|
193
|
-
- spec/models/decidim/file_authorization_handler/status_spec.rb
|
194
|
-
- spec/permissions/decidim/file_authorization_handler/admin/permissions_spec.rb
|
195
|
-
- spec/services/decidim/file_authorization_handler/file_authorization_handler_spec.rb
|
196
|
-
- spec/spec_helper.rb
|
127
|
+
test_files: []
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
RSpec.describe Decidim::FileAuthorizationHandler::Admin::CensusesController, type: :controller do
|
5
|
-
include Warden::Test::Helpers
|
6
|
-
|
7
|
-
routes { Decidim::FileAuthorizationHandler::AdminEngine.routes }
|
8
|
-
|
9
|
-
let(:organization) do
|
10
|
-
create :organization,
|
11
|
-
available_authorizations: ["file_authorization_handler"]
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:user) do
|
15
|
-
create :user, :admin, :confirmed, organization:, admin: true
|
16
|
-
end
|
17
|
-
|
18
|
-
before do
|
19
|
-
controller.request.env["decidim.current_organization"] = organization
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "GET #show" do
|
23
|
-
it "returns http success" do
|
24
|
-
sign_in user, scope: :user
|
25
|
-
get :show
|
26
|
-
|
27
|
-
expect(response).to have_http_status(:success)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "POST #create" do
|
32
|
-
it "imports the csv data" do
|
33
|
-
sign_in user
|
34
|
-
|
35
|
-
# Don't know why don't prepend with `spec/fixtures` automatically
|
36
|
-
file = fixture_file_upload("spec/fixtures/files/data1.csv")
|
37
|
-
post :create, params: { file: }
|
38
|
-
expect(response).to have_http_status(:redirect)
|
39
|
-
|
40
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.count).to be 3
|
41
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.first.id_document).to eq encode_id_document("1111A")
|
42
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.last.id_document).to eq encode_id_document("3333C")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "POST #delete_all" do
|
47
|
-
it "clear all census data" do
|
48
|
-
sign_in user
|
49
|
-
|
50
|
-
create_list :census_datum, 5, organization: organization
|
51
|
-
delete :destroy
|
52
|
-
expect(response).to have_http_status(:redirect)
|
53
|
-
|
54
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.count).to be 0
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
FactoryBot.define do
|
4
|
-
factory :census_datum, class: "Decidim::FileAuthorizationHandler::CensusDatum" do
|
5
|
-
id_document { "123456789A" }
|
6
|
-
birthdate { 20.years.ago }
|
7
|
-
organization
|
8
|
-
extras { nil }
|
9
|
-
|
10
|
-
trait :with_extras do
|
11
|
-
extras { { district: "123456789", postal_code: "ABCDEFGHIJK", segment_1: Random.hex } }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/spec/factories/factories.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decidim
|
4
|
-
module FileAuthorizationHandler
|
5
|
-
module EncodingHelper
|
6
|
-
def encode_id_document(id_document)
|
7
|
-
Digest::SHA256.hexdigest("#{id_document}-#{Rails.application.secrets.secret_key_base}")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Decidim::FileAuthorizationHandler::RemoveDuplicatesJob do
|
6
|
-
let(:org_1) { create :organization }
|
7
|
-
let(:org_2) { create :organization }
|
8
|
-
|
9
|
-
it "remove duplicates in the database" do
|
10
|
-
%w(AAA BBB AAA AAA).each do |doc|
|
11
|
-
create(:census_datum, id_document: doc, organization: org_1)
|
12
|
-
create(:census_datum, id_document: doc, organization: org_2)
|
13
|
-
end
|
14
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.count).to be 8
|
15
|
-
described_class.new.perform org_1
|
16
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.count).to be 6
|
17
|
-
described_class.new.perform org_2
|
18
|
-
expect(Decidim::FileAuthorizationHandler::CensusDatum.count).to be 4
|
19
|
-
end
|
20
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
RSpec.describe Decidim::FileAuthorizationHandler::CensusDatum, type: :model do
|
5
|
-
let(:organization) { create :organization }
|
6
|
-
|
7
|
-
# rubocop: disable Lint/ConstantDefinitionInBlock
|
8
|
-
CensusDatum = Decidim::FileAuthorizationHandler::CensusDatum
|
9
|
-
# rubocop: enable Lint/ConstantDefinitionInBlock
|
10
|
-
|
11
|
-
describe "get census for a given identity document" do
|
12
|
-
it "returns the last inserted when duplicates" do
|
13
|
-
create(:census_datum, id_document: encode_id_document("AAA"))
|
14
|
-
last = create(:census_datum, id_document: encode_id_document("AAA"), organization:)
|
15
|
-
expect(CensusDatum.search_id_document(organization, "AAA")).to eq(last)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "normalizes the document" do
|
19
|
-
census = create(:census_datum, id_document: encode_id_document("AAA"), organization:)
|
20
|
-
expect(CensusDatum.search_id_document(organization, "a-a-a")).to eq(census)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "with #insert_all" do
|
25
|
-
it "inserts a collection of values" do
|
26
|
-
# rubocop: disable Rails/SkipsModelValidations
|
27
|
-
CensusDatum.insert_all(organization, [["1111A", "1990/12/1"], ["2222B", "1990/12/2"]])
|
28
|
-
expect(CensusDatum.count).to be 2
|
29
|
-
CensusDatum.insert_all(organization, [["1111A", "2001/12/1"], ["3333C", "1990/12/3"]])
|
30
|
-
# rubocop: enable Rails/SkipsModelValidations
|
31
|
-
expect(CensusDatum.count).to be 4
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when values is empty" do
|
35
|
-
it "returns without crashing" do
|
36
|
-
# rubocop: disable Rails/SkipsModelValidations
|
37
|
-
CensusDatum.insert_all(organization, [])
|
38
|
-
# rubocop: enable Rails/SkipsModelValidations
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when extra columns exist" do
|
43
|
-
it "inserts extra columns in the #extras column" do
|
44
|
-
# rubocop: disable Rails/SkipsModelValidations
|
45
|
-
CensusDatum.insert_all(organization, [
|
46
|
-
["1111A", "2001/12/1", "001", "1234"],
|
47
|
-
["3333C", "1990/12/3", "ABCD", "01-12/33"],
|
48
|
-
], %w(POSTAL_CODE DISTRICT))
|
49
|
-
# rubocop: enable Rails/SkipsModelValidations
|
50
|
-
|
51
|
-
inserts = CensusDatum.all
|
52
|
-
expect(inserts.size).to be 2
|
53
|
-
expect(inserts.first.extras).to eq({ "postal_code" => "001", "district" => "1234" })
|
54
|
-
expect(inserts.last.extras).to eq({ "postal_code" => "ABCD", "district" => "01-12/33" })
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "normalization methods" do
|
60
|
-
it "normalizes and encodes the id document" do
|
61
|
-
expect(CensusDatum.normalize_and_encode_id_document("1234a"))
|
62
|
-
.to eq encode_id_document("1234A")
|
63
|
-
expect(CensusDatum.normalize_and_encode_id_document(" 1234a "))
|
64
|
-
.to eq encode_id_document("1234A")
|
65
|
-
expect(CensusDatum.normalize_and_encode_id_document(")($·$")).to eq ""
|
66
|
-
expect(CensusDatum.normalize_and_encode_id_document(nil)).to eq ""
|
67
|
-
end
|
68
|
-
|
69
|
-
it "normalizes dates" do
|
70
|
-
expect(CensusDatum.parse_date("20/3/1992")).to eq Date.strptime("1992/03/20", "%Y/%m/%d")
|
71
|
-
expect(CensusDatum.parse_date("1/20/1992")).to be_nil
|
72
|
-
expect(CensusDatum.parse_date("n/3/1992")).to be_nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Decidim::FileAuthorizationHandler::CsvData do
|
6
|
-
let(:file) { file_fixture("data1.csv") }
|
7
|
-
let(:data) { described_class.new(file) }
|
8
|
-
|
9
|
-
it "loads from files" do
|
10
|
-
expect(data.values.length).to be 3
|
11
|
-
expect(data.values[0]).to eq [encode_id_document("1111A"), Date.strptime("1981/01/01", "%Y/%m/%d")]
|
12
|
-
expect(data.values[1]).to eq [encode_id_document("2222B"), Date.strptime("1982/02/02", "%Y/%m/%d")]
|
13
|
-
expect(data.values[2]).to eq [encode_id_document("3333C"), Date.strptime("2017/01/01", "%Y/%m/%d")]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns the zero errored rows when all are good" do
|
17
|
-
expect(data.errors.count).to be 0
|
18
|
-
end
|
19
|
-
|
20
|
-
context "when file has errors" do
|
21
|
-
let(:file) { file_fixture("with-errors.csv") }
|
22
|
-
|
23
|
-
it "returns the number of errored rows" do
|
24
|
-
expect(data.errors.count).to be 3
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "with extra columns" do
|
29
|
-
let(:file) { file_fixture("data-with_extras.csv") }
|
30
|
-
|
31
|
-
it "parses all columns from file" do
|
32
|
-
expect(data.values.length).to be 4
|
33
|
-
expect(data.headers).to eq ["DNI", "Data de naixement", "district"]
|
34
|
-
expect(data.errors.count).to be 0
|
35
|
-
expect(data.values[0]).to eq [encode_id_document("1111A"), Date.strptime("1981/01/01", "%Y/%m/%d"), "17600"]
|
36
|
-
expect(data.values[1]).to eq [encode_id_document("2222B"), Date.strptime("1982/02/02", "%Y/%m/%d"), "17481"]
|
37
|
-
expect(data.values[2]).to eq [encode_id_document("3333C"), Date.strptime("2000/01/01", "%Y/%m/%d"), "17820"]
|
38
|
-
expect(data.values[3]).to eq [encode_id_document("4444D"), Date.strptime("2017/01/01", "%Y/%m/%d"), "17003"]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Decidim::FileAuthorizationHandler::Status, type: :model do
|
6
|
-
let(:organization) { create :organization }
|
7
|
-
|
8
|
-
it "returns last import date" do
|
9
|
-
last = create :census_datum, organization: organization
|
10
|
-
status = Decidim::FileAuthorizationHandler::Status.new(organization)
|
11
|
-
expect(last.created_at.to_i).to eq status.last_import_at.to_i
|
12
|
-
end
|
13
|
-
|
14
|
-
it "retrieve the number of unique documents" do
|
15
|
-
%w(AAA BBB AAA AAA).each do |doc|
|
16
|
-
create(:census_datum, id_document: doc, organization:)
|
17
|
-
end
|
18
|
-
status = Decidim::FileAuthorizationHandler::Status.new(organization)
|
19
|
-
expect(status.count).to be 2
|
20
|
-
end
|
21
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe Decidim::FileAuthorizationHandler::Admin::Permissions do
|
6
|
-
subject { described_class.new(user, permission_action, context).permissions.allowed? }
|
7
|
-
|
8
|
-
let(:dummy_component) { create :dummy_component }
|
9
|
-
let(:organization) { dummy_component.organization }
|
10
|
-
let(:user) { create :user, organization: }
|
11
|
-
let(:context) do
|
12
|
-
{
|
13
|
-
current_component: dummy_component,
|
14
|
-
}
|
15
|
-
end
|
16
|
-
let(:scope) { :admin }
|
17
|
-
let(:auth_subject) { Decidim::FileAuthorizationHandler::CensusDatum }
|
18
|
-
let(:action) do
|
19
|
-
{ scope:, action: action_name, subject: auth_subject }
|
20
|
-
end
|
21
|
-
let(:permission_action) { Decidim::PermissionAction.new(**action) }
|
22
|
-
|
23
|
-
before do
|
24
|
-
organization.update!(available_authorizations: ["file_authorization_handler"])
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when action is allowed" do
|
28
|
-
[:show, :create, :destroy].each do |action_name|
|
29
|
-
let(:action_name) { action_name }
|
30
|
-
|
31
|
-
context "##{action_name}" do
|
32
|
-
it { is_expected.to be true }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context "when action is NOT allowed" do
|
38
|
-
[:manage, :list, :update].each do |action_name|
|
39
|
-
let(:action_name) { action_name }
|
40
|
-
|
41
|
-
it_behaves_like "permission is not set"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when scope is not admin" do
|
46
|
-
let(:scope) { :public }
|
47
|
-
let(:action_name) { :show }
|
48
|
-
|
49
|
-
it_behaves_like "permission is not set"
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when subject is not :authorize" do
|
53
|
-
let(:action_name) { :admin }
|
54
|
-
let(:auth_subject) { :foo }
|
55
|
-
|
56
|
-
it_behaves_like "permission is not set"
|
57
|
-
end
|
58
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
RSpec.describe FileAuthorizationHandler do
|
5
|
-
let(:organization) { create(:organization) }
|
6
|
-
let(:user) { create(:user, organization:) }
|
7
|
-
let(:dni) { "1234A" }
|
8
|
-
let(:encoded_dni) { encode_id_document(dni) }
|
9
|
-
let(:date) { Date.strptime("1990/11/21", "%Y/%m/%d") }
|
10
|
-
let(:handler) do
|
11
|
-
described_class.new(user:, id_document: dni, birthdate: date)
|
12
|
-
.with_context(current_organization: organization)
|
13
|
-
end
|
14
|
-
let!(:unique_id) do
|
15
|
-
Digest::SHA256.hexdigest("#{handler.census_for_user&.id_document}-#{organization.id}-#{Rails.application.secrets.secret_key_base}")
|
16
|
-
end
|
17
|
-
|
18
|
-
context "without extras in CensusDatum" do
|
19
|
-
let(:census_datum) do
|
20
|
-
create(:census_datum, id_document: encoded_dni,
|
21
|
-
birthdate: date,
|
22
|
-
organization:)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "validates against database" do
|
26
|
-
expect(handler.valid?).to be false
|
27
|
-
census_datum
|
28
|
-
expect(handler.valid?).to be true
|
29
|
-
end
|
30
|
-
|
31
|
-
it "normalizes the id document" do
|
32
|
-
census_datum
|
33
|
-
normalizer =
|
34
|
-
described_class.new(user:, id_document: "12-34-a", birthdate: date)
|
35
|
-
.with_context(current_organization: organization)
|
36
|
-
expect(normalizer.valid?).to be true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "generates birthdate metadata" do
|
40
|
-
census_datum
|
41
|
-
expect(handler.valid?).to be true
|
42
|
-
expect(handler.metadata).to eq(birthdate: "1990/11/21")
|
43
|
-
end
|
44
|
-
|
45
|
-
it "generates unique_id correctly" do
|
46
|
-
expect(unique_id).to eq(handler.unique_id)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "works when no current_organization context is provided (but the user is)" do
|
50
|
-
census_datum
|
51
|
-
contextless_handler = described_class.new(user:,
|
52
|
-
id_document: dni,
|
53
|
-
birthdate: date)
|
54
|
-
expect(contextless_handler.valid?).to be true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "with extras in CensusDatum" do
|
59
|
-
let(:date) { Date.strptime("2000/01/01", "%Y/%m/%d") }
|
60
|
-
let(:census_datum) do
|
61
|
-
create(:census_datum, :with_extras, id_document: encoded_dni,
|
62
|
-
birthdate: date,
|
63
|
-
organization:)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "adds extras as metadata" do
|
67
|
-
census_datum
|
68
|
-
expect(handler.valid?).to be true
|
69
|
-
expect(handler.metadata).to eq({
|
70
|
-
birthdate: "2000/01/01",
|
71
|
-
district: census_datum.extras["district"],
|
72
|
-
postal_code: census_datum.extras["postal_code"],
|
73
|
-
segment_1: census_datum.extras["segment_1"],
|
74
|
-
})
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] ||= "test"
|
4
|
-
|
5
|
-
require "decidim/dev"
|
6
|
-
require "decidim/admin"
|
7
|
-
require "decidim/core"
|
8
|
-
require "decidim/verifications"
|
9
|
-
require "decidim/core/test"
|
10
|
-
require "social-share-button"
|
11
|
-
require "letter_opener_web"
|
12
|
-
|
13
|
-
require "helpers/decidim/file_authorization_handler/encoding_helper"
|
14
|
-
|
15
|
-
ENV["ENGINE_NAME"] = File.dirname(__dir__).split("/").last
|
16
|
-
|
17
|
-
Decidim::Dev.dummy_app_path = File.expand_path(File.join(".", "spec", "decidim_dummy_app"))
|
18
|
-
|
19
|
-
require "decidim/dev/test/base_spec_helper"
|
20
|
-
|
21
|
-
RSpec.configure do |config|
|
22
|
-
config.include Decidim::FileAuthorizationHandler::EncodingHelper
|
23
|
-
end
|