decidim-user_fields 0.0.1 → 0.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/README.md +320 -55
- data/Rakefile +253 -0
- data/app/forms/decidim/custom_user_fields/admin/customizations_config_form.rb +67 -0
- data/app/forms/decidim/custom_user_fields/verifications/verification_form.rb +85 -0
- data/app/overrides/decidim/admin/officializations/index/_export_users_dropdown.html.erb.deface +1 -3
- data/app/overrides/decidim/devise/invitations/edit/extra_user_fields_form.html.erb.deface +2 -2
- data/app/overrides/decidim/devise/omniauth_registrations/new/extra_user_fields.html.erb.deface +3 -0
- data/app/overrides/invitation_override.rb +31 -0
- data/app/packs/entrypoints/decidim_custom_user_fields.js +0 -0
- data/app/packs/stylesheets/decidim/custom_user_fields/_decidim_custom_user_fields.scss +48 -0
- data/app/views/decidim/custom_user_fields/_profile_form.html.erb +2 -2
- data/app/views/decidim/custom_user_fields/_registration_form.html.erb +2 -2
- data/app/views/decidim/custom_user_fields/_verification_form.erb +4 -0
- data/app/views/decidim/custom_user_fields/system/_customizations_tab.html.erb +15 -0
- data/config/assets.rb +9 -0
- data/config/i18n-tasks.yml +22 -0
- data/config/locales/decidim_custom_user_fields_scenarios.en.yml +50 -0
- data/config/locales/decidim_custom_user_fields_scenarios.fr.yml +48 -0
- data/config/locales/decidim_toggle.en.yml +13 -0
- data/config/locales/decidim_toggle.fr.yml +13 -0
- data/config/locales/decidim_user_fields.en.yml +25 -0
- data/config/locales/decidim_user_fields.fr.yml +25 -0
- data/lib/decidim/custom_user_fields/custom_user_fields.rb +10 -14
- data/lib/decidim/custom_user_fields/customization_field_naming.rb +17 -0
- data/lib/decidim/custom_user_fields/customizations/builder.rb +48 -0
- data/lib/decidim/custom_user_fields/customizations/customization.rb +29 -0
- data/lib/decidim/custom_user_fields/customizations.rb +42 -0
- data/lib/decidim/custom_user_fields/decidim_integrations.rb +52 -0
- data/lib/decidim/custom_user_fields/definition_guidance.rb +109 -0
- data/lib/decidim/custom_user_fields/dev/bootstrap.rb +102 -0
- data/lib/decidim/custom_user_fields/dev/local_oidc_seeder.rb +150 -0
- data/lib/decidim/custom_user_fields/dev/omniauth_providers_patcher.rb +68 -0
- data/lib/decidim/custom_user_fields/dev/openid_connect_setup.rb +110 -0
- data/lib/decidim/custom_user_fields/dev/scenario_customizations.rb +72 -0
- data/lib/decidim/custom_user_fields/engine.rb +59 -26
- data/lib/decidim/custom_user_fields/extended_data.rb +52 -0
- data/lib/decidim/custom_user_fields/field_definition.rb +28 -6
- data/lib/decidim/custom_user_fields/fields/boolean_field.rb +51 -0
- data/lib/decidim/custom_user_fields/fields/date_field.rb +91 -22
- data/lib/decidim/custom_user_fields/fields/dummy_field.rb +40 -0
- data/lib/decidim/custom_user_fields/fields/extra_field_ref_field.rb +118 -0
- data/lib/decidim/custom_user_fields/fields/generic_field.rb +99 -6
- data/lib/decidim/custom_user_fields/fields/text_area_field.rb +51 -27
- data/lib/decidim/custom_user_fields/fields/text_field.rb +47 -6
- data/lib/decidim/custom_user_fields/i18n/customization_keys.rb +55 -0
- data/lib/decidim/custom_user_fields/i18n/customization_keys_scanner.rb +80 -0
- data/lib/decidim/custom_user_fields/i18n/tasks.rb +7 -0
- data/lib/decidim/custom_user_fields/overrides/authorizations_controller.rb +18 -0
- data/lib/decidim/custom_user_fields/overrides/command.rb +23 -21
- data/lib/decidim/custom_user_fields/overrides/confirmations_controller.rb +15 -0
- data/lib/decidim/custom_user_fields/overrides/devise_authentication_methods.rb +68 -0
- data/lib/decidim/custom_user_fields/overrides/form_definition.rb +27 -8
- data/lib/decidim/custom_user_fields/overrides/invitations_controller.rb +109 -0
- data/lib/decidim/custom_user_fields/overrides/omniauth_command.rb +40 -0
- data/lib/decidim/custom_user_fields/overrides/omniauth_registrations_controller.rb +93 -0
- data/lib/decidim/custom_user_fields/overrides/user.rb +16 -0
- data/lib/decidim/custom_user_fields/registration_fields.rb +99 -0
- data/lib/decidim/custom_user_fields/update_customizations_config_command.rb +39 -0
- data/lib/decidim/custom_user_fields/upgrade/migrate_toggle_config.rb +74 -0
- data/lib/decidim/custom_user_fields/verifications/builder.rb +100 -0
- data/lib/decidim/custom_user_fields/verifications/verifications.rb +82 -0
- data/lib/decidim/custom_user_fields/version.rb +4 -2
- data/lib/decidim/user_fields.rb +46 -13
- data/lib/tasks/decidim/custom_user_fields/custom_user_fields_upgrade.rake +16 -0
- data/lib/tasks/decidim/custom_user_fields/custom_user_fields_webpacker.rake +59 -0
- data/lib/tasks/decidim/custom_user_fields/decidim_custom_user_fields_upgrade_tasks.rake +16 -0
- data/lib/tasks/decidim/custom_user_fields/dev/local_setup.rake +16 -0
- metadata +81 -16
- data/app/overrides/decidim/devise/invitations/edit/extra_user_fields.html.erb.deface +0 -3
data/Rakefile
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "decidim/dev/common_rake"
|
|
5
|
+
|
|
6
|
+
# Dummy generation boots Rails (`app:template`) before this task can patch files.
|
|
7
|
+
def dummy_shakapacker_yml_source
|
|
8
|
+
core = Gem.loaded_specs["decidim-core"]&.full_gem_path
|
|
9
|
+
from_core = core && File.join(core, "lib/decidim/shakapacker/shakapacker.yml")
|
|
10
|
+
return from_core if from_core && File.exist?(from_core)
|
|
11
|
+
|
|
12
|
+
File.join(Gem.loaded_specs.fetch("shakapacker").full_gem_path, "lib/install/config/shakapacker.yml")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def copy_dummy_shakapacker_yml!(dummy_root)
|
|
16
|
+
dest = File.join(dummy_root, "config/shakapacker.yml")
|
|
17
|
+
return if File.exist?(dest) && !File.empty?(dest)
|
|
18
|
+
return unless File.directory?(File.join(dummy_root, "config"))
|
|
19
|
+
|
|
20
|
+
FileUtils.cp(dummy_shakapacker_yml_source, dest)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def poll_dummy_shakapacker_yml(dummy_root, stop)
|
|
24
|
+
thread = Thread.new do
|
|
25
|
+
until stop.call
|
|
26
|
+
copy_dummy_shakapacker_yml!(dummy_root)
|
|
27
|
+
sleep 0.1
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
thread.abort_on_exception = true
|
|
31
|
+
thread
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def with_dummy_shakapacker_yml(dummy_root)
|
|
35
|
+
stop = false
|
|
36
|
+
thread = poll_dummy_shakapacker_yml(dummy_root, -> { stop })
|
|
37
|
+
yield
|
|
38
|
+
ensure
|
|
39
|
+
stop = true
|
|
40
|
+
thread&.join
|
|
41
|
+
copy_dummy_shakapacker_yml!(dummy_root)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def inject_toggle_into_dummy_gemfile!(dummy_root)
|
|
45
|
+
gemfile = File.join(dummy_root, "Gemfile")
|
|
46
|
+
return unless File.exist?(gemfile)
|
|
47
|
+
|
|
48
|
+
contents = File.read(gemfile).sub(dummy_toggle_gem_pattern, "")
|
|
49
|
+
File.write(gemfile, "#{contents.rstrip}\n\n#{dummy_toggle_gem_declaration}\n")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def dummy_toggle_gem_pattern
|
|
53
|
+
/^[ \t]*gem ["']decidim-toggle["'][^\n]*(?:\n[ \t]+(?:git:|github:|branch:|tag:|path:|ref:)[^\n]*)*\n?/
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def dummy_toggle_gem_declaration
|
|
57
|
+
<<~RUBY.strip
|
|
58
|
+
gem "decidim-toggle",
|
|
59
|
+
git: "https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-toggle.git",
|
|
60
|
+
branch: "main"
|
|
61
|
+
RUBY
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def install_module(path)
|
|
65
|
+
Dir.chdir(path) do
|
|
66
|
+
Bundler.with_unbundled_env do
|
|
67
|
+
sh "bundle exec rails decidim_toggle:install:migrations"
|
|
68
|
+
next unless File.read("Gemfile").include?("decidim-ephemeral_participation")
|
|
69
|
+
|
|
70
|
+
sh "bundle exec rails decidim_ephemeral_participation:install:migrations"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def ephemeral_gem_in_bundle?
|
|
76
|
+
Bundler.definition.dependencies.any? { |dep| dep.name == "decidim-ephemeral_participation" }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def inject_ephemeral_into_dummy_gemfile!(dummy_root, enabled: ephemeral_gem_in_bundle?)
|
|
80
|
+
return unless enabled
|
|
81
|
+
|
|
82
|
+
gemfile = File.join(dummy_root, "Gemfile")
|
|
83
|
+
contents = File.read(gemfile)
|
|
84
|
+
return if contents.include?("decidim-ephemeral_participation")
|
|
85
|
+
|
|
86
|
+
File.open(gemfile, "a") do |file|
|
|
87
|
+
file.puts <<~RUBY
|
|
88
|
+
|
|
89
|
+
gem "decidim-ephemeral_participation",
|
|
90
|
+
git: "https://gitlab.com/octree_gva/decidim/vocacity/decidim-modules/decidim-ephemeral_participation.git",
|
|
91
|
+
tag: "v0.0.9"
|
|
92
|
+
RUBY
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def seed_db(path)
|
|
97
|
+
Dir.chdir(path) do
|
|
98
|
+
raise "db:seed failed" unless system("bundle exec rails db:seed")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
desc "Prepare for testing"
|
|
103
|
+
task :prepare_tests do
|
|
104
|
+
# Remove previous existing db, and recreate one.
|
|
105
|
+
disable_docker_compose = ENV.fetch("DISABLED_DOCKER_COMPOSE", "false") == "true"
|
|
106
|
+
unless disable_docker_compose
|
|
107
|
+
sh "docker compose -f docker-compose.yml down -v"
|
|
108
|
+
sh "docker compose -f docker-compose.yml up -d --remove-orphans"
|
|
109
|
+
end
|
|
110
|
+
ENV["RAILS_ENV"] = "test"
|
|
111
|
+
test_db = {
|
|
112
|
+
"adapter" => "postgresql",
|
|
113
|
+
"encoding" => "unicode",
|
|
114
|
+
"host" => ENV.fetch("DATABASE_HOST", "localhost"),
|
|
115
|
+
"port" => ENV.fetch("DATABASE_PORT", "5432").to_i,
|
|
116
|
+
"username" => ENV.fetch("DATABASE_USERNAME", "decidim"),
|
|
117
|
+
"password" => ENV.fetch("DATABASE_PASSWORD", "TEST-baeGhi4Ohtahcee5eejoaxaiwaezaiGo"),
|
|
118
|
+
"database" => "decidim_test",
|
|
119
|
+
# GitLab/docker Postgres services rarely offer TLS on the internal hostname
|
|
120
|
+
"sslmode" => ENV.fetch("DATABASE_SSLMODE", "disable"),
|
|
121
|
+
# Ephemeral migration changes available_authorizations array → jsonb then updates rows.
|
|
122
|
+
"prepared_statements" => false
|
|
123
|
+
}
|
|
124
|
+
# Dummy app is CI-only; Spring / bin/rails often boot `development` even when we intend `test`.
|
|
125
|
+
# Mirror `test` so `db:migrate` never dies on missing `development` (see ActiveRecord::AdapterNotSpecified).
|
|
126
|
+
database_yml = {
|
|
127
|
+
"development" => test_db.dup,
|
|
128
|
+
"test" => test_db.dup
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
config_file = File.expand_path("spec/decidim_dummy_app/config/database.yml", __dir__)
|
|
132
|
+
File.open(config_file, "w") { |f| YAML.dump(database_yml, f) }
|
|
133
|
+
Dir.chdir("spec/decidim_dummy_app") do
|
|
134
|
+
# Strip Bundler’s parent-project env (`BUNDLE_GEMFILE`, etc. from `bundle exec rake` at engine root)
|
|
135
|
+
# so `bundle exec` in the dummy app resolves that Gemfile. Use `with_unbundled_env`, not only
|
|
136
|
+
# `with_original_env` (Bundler docs: subcommands in another directory).
|
|
137
|
+
Bundler.with_unbundled_env do
|
|
138
|
+
# Fresh DB every run: regenerating the dummy app rewrites migration timestamps, so an
|
|
139
|
+
# existing schema (local compose volume / re-run) would hit PG::DuplicateTable.
|
|
140
|
+
# Use Rake `sh` so a failed migrate aborts; `env` sets vars in the shell (reliable vs Kernel#system env quirks).
|
|
141
|
+
sh "env RAILS_ENV=test DISABLE_SPRING=1 DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:drop db:create db:migrate"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def root_gemfile_path
|
|
147
|
+
File.expand_path("Gemfile", __dir__)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Appraisal jobs set BUNDLE_GEMFILE. AppGenerator copies the engine-root Gemfile, not that path.
|
|
151
|
+
def alternate_bundle_gemfile
|
|
152
|
+
gemfile = ENV.fetch("BUNDLE_GEMFILE", nil)
|
|
153
|
+
return if gemfile.blank?
|
|
154
|
+
|
|
155
|
+
expanded = File.expand_path(gemfile)
|
|
156
|
+
return if expanded == root_gemfile_path
|
|
157
|
+
return unless File.exist?(expanded) && File.exist?("#{expanded}.lock")
|
|
158
|
+
|
|
159
|
+
expanded
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Dummy app lives in spec/decidim_dummy_app; the engine is ../.. from there.
|
|
163
|
+
# The ephemeral lock records PATH remote: /app (compose mount), which is wrong in CI.
|
|
164
|
+
def lockfile_for_dummy_app(contents)
|
|
165
|
+
contents.sub(/^PATH\n remote: .+$/, "PATH\n remote: ../..")
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def with_active_gemfile_staged
|
|
169
|
+
backup_gemfile = nil
|
|
170
|
+
backup_lock = nil
|
|
171
|
+
root_gemfile = root_gemfile_path
|
|
172
|
+
root_lock = "#{root_gemfile}.lock"
|
|
173
|
+
gemfile = alternate_bundle_gemfile
|
|
174
|
+
if gemfile
|
|
175
|
+
backup_gemfile = File.read(root_gemfile)
|
|
176
|
+
backup_lock = File.binread(root_lock) if File.exist?(root_lock)
|
|
177
|
+
File.write(root_gemfile, File.read(gemfile))
|
|
178
|
+
File.binwrite(root_lock, lockfile_for_dummy_app(File.binread("#{gemfile}.lock")))
|
|
179
|
+
end
|
|
180
|
+
yield
|
|
181
|
+
ensure
|
|
182
|
+
if backup_gemfile
|
|
183
|
+
File.write(root_gemfile, backup_gemfile)
|
|
184
|
+
if backup_lock
|
|
185
|
+
File.binwrite(root_lock, backup_lock)
|
|
186
|
+
else
|
|
187
|
+
FileUtils.rm_f(root_lock)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# `--demo` copies initiative handlers that eager-load Decidim::Initiatives.
|
|
193
|
+
# This Gemfile does not load that component.
|
|
194
|
+
def strip_optional_initiatives_stubs!(dummy_root)
|
|
195
|
+
%w(
|
|
196
|
+
app/services/dummy_signature_handler.rb
|
|
197
|
+
app/services/dummy_sms_mobile_phone_validator.rb
|
|
198
|
+
config/initializers/decidim_initiatives.rb
|
|
199
|
+
app/views/decidim/initiatives
|
|
200
|
+
).each { |relative| FileUtils.rm_rf(File.join(dummy_root, relative)) }
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
desc "Generates a dummy app for testing"
|
|
204
|
+
task :test_app do
|
|
205
|
+
dummy_root = File.expand_path("spec/decidim_dummy_app", __dir__)
|
|
206
|
+
needs_ephemeral = ephemeral_gem_in_bundle?
|
|
207
|
+
with_dummy_shakapacker_yml(dummy_root) do
|
|
208
|
+
with_active_gemfile_staged do
|
|
209
|
+
Bundler.with_original_env do
|
|
210
|
+
ENV.delete("BUNDLE_GEMFILE")
|
|
211
|
+
generate_decidim_app(
|
|
212
|
+
"spec/decidim_dummy_app",
|
|
213
|
+
"--app_name",
|
|
214
|
+
"decidim_test",
|
|
215
|
+
"--path",
|
|
216
|
+
"../..",
|
|
217
|
+
"--skip_spring",
|
|
218
|
+
"--demo",
|
|
219
|
+
"--force_ssl",
|
|
220
|
+
"false",
|
|
221
|
+
"--locales",
|
|
222
|
+
"en,ca,es,fr"
|
|
223
|
+
)
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
strip_optional_initiatives_stubs!(dummy_root)
|
|
228
|
+
inject_ephemeral_into_dummy_gemfile!(dummy_root, enabled: needs_ephemeral)
|
|
229
|
+
inject_toggle_into_dummy_gemfile!(dummy_root)
|
|
230
|
+
# Install under with_unbundled_env before install_module (needs `bundle exec rails`).
|
|
231
|
+
Dir.chdir(File.expand_path("spec/decidim_dummy_app", __dir__)) do
|
|
232
|
+
Bundler.with_unbundled_env do
|
|
233
|
+
sh "bundle install -j $(nproc) --retry 3"
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
install_module("spec/decidim_dummy_app")
|
|
237
|
+
Rake::Task["prepare_tests"].invoke
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
desc "Generates a development app"
|
|
241
|
+
task :development_app do
|
|
242
|
+
Bundler.with_original_env do
|
|
243
|
+
generate_decidim_app(
|
|
244
|
+
"development_app",
|
|
245
|
+
"--app_name",
|
|
246
|
+
"#{base_app_name}_development_app",
|
|
247
|
+
"--path",
|
|
248
|
+
"..",
|
|
249
|
+
"--recreate_db",
|
|
250
|
+
"--demo"
|
|
251
|
+
)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module Admin
|
|
6
|
+
class CustomizationsConfigForm < Decidim::Form
|
|
7
|
+
include Decidim::Toggle::ModuleConfigForm
|
|
8
|
+
include Decidim::Toggle::InformativeCallouts
|
|
9
|
+
|
|
10
|
+
self.module_config_name = "custom_user_fields"
|
|
11
|
+
|
|
12
|
+
mimic :organization
|
|
13
|
+
|
|
14
|
+
attribute :first_login_mode, :string, default: "prompt_authorization"
|
|
15
|
+
attribute :enabled_customization, :string, default: ""
|
|
16
|
+
|
|
17
|
+
validates :first_login_mode,
|
|
18
|
+
inclusion: { in: RegistrationFields::FIRST_LOGIN_MODES },
|
|
19
|
+
allow_blank: true
|
|
20
|
+
validates :enabled_customization,
|
|
21
|
+
inclusion: { in: :allowed_enabled_customization_values },
|
|
22
|
+
allow_blank: true
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
def from_model(organization)
|
|
26
|
+
super.tap do |form|
|
|
27
|
+
form.enabled_customization = RegistrationFields.enabled_customization_names(organization).first.to_s
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def collection_for_first_login_mode
|
|
32
|
+
RegistrationFields::FIRST_LOGIN_MODES.map do |value|
|
|
33
|
+
[value, ::I18n.t(value, scope: "decidim.custom_user_fields.system.first_login_mode")]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def collection_for_enabled_customization
|
|
38
|
+
[none_customization_option] + customization_radio_options
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def none_customization_option
|
|
42
|
+
["", ::I18n.t("none", scope: "decidim_toggle.system.custom_user_fields")]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def customization_radio_options
|
|
46
|
+
Customizations.all.map do |customization|
|
|
47
|
+
name = customization.name.to_s
|
|
48
|
+
# Handle customisations with no "#{name}_enabled" (e.g. scenarios defined outside this module)
|
|
49
|
+
label = ::I18n.t(
|
|
50
|
+
"#{name}_enabled",
|
|
51
|
+
scope: "decidim_toggle.system.custom_user_fields",
|
|
52
|
+
default: name.to_s.humanize
|
|
53
|
+
)
|
|
54
|
+
[name, label]
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def allowed_enabled_customization_values
|
|
62
|
+
Customizations.all.map { |customization| customization.name.to_s }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module Verifications
|
|
6
|
+
class VerificationForm < ::Decidim::AuthorizationHandler
|
|
7
|
+
include ActionView::Helpers::SanitizeHelper
|
|
8
|
+
include ActiveModel::Validations::Callbacks
|
|
9
|
+
|
|
10
|
+
# Identity cast: parent `attribute :user, Decidim::User` re-instantiates via
|
|
11
|
+
# Decidim::Attributes::Model and breaks STI under reload when views materialize attributes.
|
|
12
|
+
attribute :user
|
|
13
|
+
|
|
14
|
+
before_validation :sanitize_values
|
|
15
|
+
validate :custom_field_validation
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
attr_accessor :decidim_custom_fields
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def fields
|
|
22
|
+
self.class.decidim_custom_fields
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def custom_field_validation
|
|
26
|
+
data = field_data
|
|
27
|
+
fields.each do |f|
|
|
28
|
+
value = f.sanitized_value(data[f.name])
|
|
29
|
+
f.validate(value, data, errors)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def metadata
|
|
34
|
+
save_extended_data!
|
|
35
|
+
data = field_data
|
|
36
|
+
super.merge(
|
|
37
|
+
fields.to_h do |field|
|
|
38
|
+
key = field.name
|
|
39
|
+
plain_val = field.sanitized_value(data[key])
|
|
40
|
+
|
|
41
|
+
value = field.skip_hashing? ? plain_val : Digest::SHA256.hexdigest(plain_val)
|
|
42
|
+
[key, value]
|
|
43
|
+
end
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_partial_path
|
|
48
|
+
"/decidim/custom_user_fields/verification_form"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# Avoid Decidim::Attributes::Model re-instantiating `user` (STI dual-class crash).
|
|
54
|
+
def field_data
|
|
55
|
+
fields.to_h { |f| [f.name, self[f.name]] }.with_indifferent_access
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def sanitize_values
|
|
59
|
+
fields.each do |field|
|
|
60
|
+
key = field.name
|
|
61
|
+
next unless attribute_names.include?(key.to_s)
|
|
62
|
+
|
|
63
|
+
self[key] = field.sanitized_value(self[key])
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def non_extra_fields
|
|
68
|
+
fields.reject { |f| f.type == :extra_field_ref }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def extra_fields
|
|
72
|
+
fields.select { |f| f.type == :extra_field_ref }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def save_extended_data!
|
|
76
|
+
extended_data = user.extended_data.with_indifferent_access
|
|
77
|
+
extra_fields.reject { |field| field.options[:skip_update_on_verified] }.each do |field|
|
|
78
|
+
extended_data[field.storage_name] = field.sanitized_value(self[field.name])
|
|
79
|
+
end
|
|
80
|
+
user.update!(extended_data:)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
<!-- replace "erb[loud]:contains('decidim_form_for')" -->
|
|
2
|
-
<% form = @form || Decidim::RegistrationForm.from_model(resource).with_context(current_organization: current_organization, current_user: current_user) %>
|
|
3
|
-
<%= decidim_form_for form, namespace: "invitation", as: resource_name, url: invitation_path(resource_name, invite_redirect: params[:invite_redirect]), html: { method: :put, class: "register-form new_user" } do |f| %>
|
|
2
|
+
<% form = @form || Decidim::RegistrationForm.from_model(resource).with_context(current_organization: current_organization, current_user: current_user, invitation_token: resource.invitation_token) %>
|
|
3
|
+
<%= decidim_form_for form, namespace: "invitation", as: resource_name, url: invitation_path(resource_name, invite_redirect: params[:invite_redirect]), html: { method: :put, class: "register-form new_user" } do |f| %>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Deface::Override.new(
|
|
4
|
+
virtual_path: "decidim/devise/invitations/edit",
|
|
5
|
+
name: "decidim_user_field_add_extra_user_fields_to_invitation_edit",
|
|
6
|
+
insert_after: "erb[loud]:contains('f.text_field :nickname')",
|
|
7
|
+
text: <<~ERB
|
|
8
|
+
<!-- add email as hidden field -->
|
|
9
|
+
<%= f.hidden_field :email %>
|
|
10
|
+
<%= render partial: '/decidim/custom_user_fields/registration_form', locals: { f: f, resource: resource } %>
|
|
11
|
+
ERB
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
Deface::Override.new(
|
|
15
|
+
virtual_path: "decidim/devise/invitations/edit",
|
|
16
|
+
name: "decidim_user_field_add_invitation_token_to_invitation_edit",
|
|
17
|
+
replace: "erb[loud]:contains('f.hidden_field :invitation_token')",
|
|
18
|
+
text: <<~ERB
|
|
19
|
+
<%= f.hidden_field :invitation_token, value: f.object.context.invitation_token %>
|
|
20
|
+
ERB
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
Deface::Override.new(
|
|
24
|
+
virtual_path: "decidim/devise/invitations/edit",
|
|
25
|
+
name: "decidim_user_field_replace_invitation_form",
|
|
26
|
+
replace: "erb[loud]:contains('decidim_form_for')",
|
|
27
|
+
text: <<~ERB
|
|
28
|
+
<% form = @form || Decidim::RegistrationForm.from_model(resource).with_context(current_organization: current_organization, current_user: current_user, invitation_token: resource.invitation_token) %>
|
|
29
|
+
<%= decidim_form_for form, namespace: "invitation", as: resource_name, url: invitation_path(resource_name, invite_redirect: params[:invite_redirect]), html: { method: :put, class: "register-form new_user" } do |f| %>
|
|
30
|
+
ERB
|
|
31
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
.decidim_custom_user_fields__section {
|
|
2
|
+
.field_label--date {
|
|
3
|
+
display: block;
|
|
4
|
+
margin-top: 1.5rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.datepicker__help-text-container {
|
|
8
|
+
height: unset;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&--verification, &--registration {
|
|
12
|
+
|
|
13
|
+
.field_label:not(:first-child) {
|
|
14
|
+
margin-top: 1rem;
|
|
15
|
+
}
|
|
16
|
+
.field_label {
|
|
17
|
+
&--text, &--textarea {
|
|
18
|
+
&, & input {
|
|
19
|
+
display: block !important;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
.datepicker__datepicker-row {
|
|
24
|
+
display: block !important;
|
|
25
|
+
}
|
|
26
|
+
.datepicker__date-column, .datepicker__time-column {
|
|
27
|
+
display: flex;
|
|
28
|
+
gap: 1rem;
|
|
29
|
+
}
|
|
30
|
+
.datepicker__calendar-button {
|
|
31
|
+
top: unset;
|
|
32
|
+
left: unset;
|
|
33
|
+
right:unset;
|
|
34
|
+
bottom: unset;
|
|
35
|
+
transform: scale(1.5);
|
|
36
|
+
position: relative;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&--registration, &--profile {
|
|
41
|
+
& > .field_label {
|
|
42
|
+
display: block;
|
|
43
|
+
}
|
|
44
|
+
& > .field_label:not(:last-child) {
|
|
45
|
+
margin-bottom: 2rem;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<div class="
|
|
2
|
-
<% Decidim::CustomUserFields.
|
|
1
|
+
<div class="decidim_custom_user_fields__section decidim_custom_user_fields__section--profile">
|
|
2
|
+
<% Decidim::CustomUserFields::RegistrationFields.active_registration_fields(f.object.current_organization).each do |field|
|
|
3
3
|
concat field.form_tag(f)
|
|
4
4
|
end %>
|
|
5
5
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<div class="
|
|
2
|
-
<% Decidim::CustomUserFields.
|
|
1
|
+
<div class="decidim_custom_user_fields__section decidim_custom_user_fields__section--registration">
|
|
2
|
+
<% Decidim::CustomUserFields::RegistrationFields.active_registration_fields(f.object.current_organization).each do |field|
|
|
3
3
|
concat field.form_tag(f)
|
|
4
4
|
end %>
|
|
5
5
|
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% organization = local_assigns[:organization] %>
|
|
2
|
+
<% tab = local_assigns[:tab] %>
|
|
3
|
+
<%= decidim_toggle_settings_tab_form(organization, tab) do |tf| %>
|
|
4
|
+
<% form_class = tf.object.class %>
|
|
5
|
+
<div class="field">
|
|
6
|
+
<%= tf.collection_select(
|
|
7
|
+
:first_login_mode,
|
|
8
|
+
form_class.collection_for_first_login_mode,
|
|
9
|
+
:first,
|
|
10
|
+
:last
|
|
11
|
+
) %>
|
|
12
|
+
<p class="field-helptext"><%= t("decidim_toggle.system.custom_user_fields.helptext.first_login_mode") %></p>
|
|
13
|
+
</div>
|
|
14
|
+
<%= tf.fields_for_names(:enabled_customization) %>
|
|
15
|
+
<% end %>
|
data/config/assets.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
base_path = File.expand_path("..", __dir__)
|
|
4
|
+
|
|
5
|
+
Decidim::Webpacker.register_path("#{base_path}/app/packs")
|
|
6
|
+
Decidim::Webpacker.register_entrypoints(
|
|
7
|
+
decidim_custom_user_fields: "#{base_path}/app/packs/entrypoints/decidim_custom_user_fields.js"
|
|
8
|
+
)
|
|
9
|
+
Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/custom_user_fields/decidim_custom_user_fields")
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# i18n-tasks for decidim-user_fields
|
|
2
|
+
# https://github.com/glebm/i18n-tasks
|
|
3
|
+
#
|
|
4
|
+
# Host apps: add this require so customization registry keys are treated as used:
|
|
5
|
+
# <% require "decidim/custom_user_fields/i18n/tasks" %>
|
|
6
|
+
<% require "decidim/custom_user_fields/i18n/tasks" %>
|
|
7
|
+
|
|
8
|
+
base_locale: en
|
|
9
|
+
locales: [en, fr]
|
|
10
|
+
|
|
11
|
+
data:
|
|
12
|
+
read:
|
|
13
|
+
- config/locales/decidim_user_fields.%{locale}.yml
|
|
14
|
+
- config/locales/decidim_toggle.%{locale}.yml
|
|
15
|
+
- config/locales/decidim_custom_user_fields_scenarios.%{locale}.yml
|
|
16
|
+
write:
|
|
17
|
+
- config/locales/decidim_user_fields.%{locale}.yml
|
|
18
|
+
|
|
19
|
+
search:
|
|
20
|
+
paths:
|
|
21
|
+
- app/
|
|
22
|
+
- lib/
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
en:
|
|
2
|
+
decidim:
|
|
3
|
+
authorization_handlers:
|
|
4
|
+
twelve_plus:
|
|
5
|
+
name: "12 plus"
|
|
6
|
+
explanation: "Verify you are at least 12 years old"
|
|
7
|
+
sixteen_plus:
|
|
8
|
+
name: "16 plus"
|
|
9
|
+
explanation: "Verify you are at least 16 years old"
|
|
10
|
+
eighteen_plus:
|
|
11
|
+
name: "18 plus"
|
|
12
|
+
explanation: "Verify you are at least 18 years old"
|
|
13
|
+
location_validated:
|
|
14
|
+
name: "Location validated"
|
|
15
|
+
explanation: "Validate your location details"
|
|
16
|
+
association_only:
|
|
17
|
+
name: "Association only"
|
|
18
|
+
explanation: "Only for association representatives"
|
|
19
|
+
custom_user_fields:
|
|
20
|
+
customizations:
|
|
21
|
+
birthdate_age_gates: "Birthdate age gates"
|
|
22
|
+
location_validation: "Location validation"
|
|
23
|
+
association: "Association representative"
|
|
24
|
+
extended_data:
|
|
25
|
+
birthdate_age_gates_birthdate:
|
|
26
|
+
label: "Birthdate"
|
|
27
|
+
association_represent_association:
|
|
28
|
+
label: "I represent an association"
|
|
29
|
+
required: "This field is required"
|
|
30
|
+
represent_association:
|
|
31
|
+
label: "I represent an association"
|
|
32
|
+
twelve_plus:
|
|
33
|
+
birthdate:
|
|
34
|
+
label: "Birthdate"
|
|
35
|
+
sixteen_plus:
|
|
36
|
+
birthdate:
|
|
37
|
+
label: "Birthdate"
|
|
38
|
+
eighteen_plus:
|
|
39
|
+
birthdate:
|
|
40
|
+
label: "Birthdate"
|
|
41
|
+
location_validated:
|
|
42
|
+
birthdate:
|
|
43
|
+
label: "Birthdate (DD.MM.YYYY)"
|
|
44
|
+
postal_code:
|
|
45
|
+
label: "Postal code"
|
|
46
|
+
full_name:
|
|
47
|
+
label: "Full name"
|
|
48
|
+
association_only:
|
|
49
|
+
represent_association:
|
|
50
|
+
label: "I represent an association"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
fr:
|
|
2
|
+
decidim:
|
|
3
|
+
authorization_handlers:
|
|
4
|
+
twelve_plus:
|
|
5
|
+
name: "12 ans et plus"
|
|
6
|
+
explanation: "Vérifier que vous avez au moins 12 ans"
|
|
7
|
+
sixteen_plus:
|
|
8
|
+
name: "16 ans et plus"
|
|
9
|
+
explanation: "Vérifier que vous avez au moins 16 ans"
|
|
10
|
+
eighteen_plus:
|
|
11
|
+
name: "18 ans et plus"
|
|
12
|
+
explanation: "Vérifier que vous avez au moins 18 ans"
|
|
13
|
+
location_validated:
|
|
14
|
+
name: "Localisation validée"
|
|
15
|
+
explanation: "Valider vos informations de localisation"
|
|
16
|
+
association_only:
|
|
17
|
+
name: "Association uniquement"
|
|
18
|
+
explanation: "Réservé aux représentants d'association"
|
|
19
|
+
custom_user_fields:
|
|
20
|
+
customizations:
|
|
21
|
+
birthdate_age_gates: "Contrôles d'âge par date de naissance"
|
|
22
|
+
location_validation: "Validation de localisation"
|
|
23
|
+
association: "Représentant d'association"
|
|
24
|
+
extended_data:
|
|
25
|
+
birthdate_age_gates_birthdate:
|
|
26
|
+
label: "Date de naissance"
|
|
27
|
+
association_represent_association:
|
|
28
|
+
label: "Je représente une association"
|
|
29
|
+
required: "Ce champ est obligatoire"
|
|
30
|
+
twelve_plus:
|
|
31
|
+
birthdate:
|
|
32
|
+
label: "Date de naissance"
|
|
33
|
+
sixteen_plus:
|
|
34
|
+
birthdate:
|
|
35
|
+
label: "Date de naissance"
|
|
36
|
+
eighteen_plus:
|
|
37
|
+
birthdate:
|
|
38
|
+
label: "Date de naissance"
|
|
39
|
+
location_validated:
|
|
40
|
+
birthdate:
|
|
41
|
+
label: "Date de naissance (JJ.MM.AAAA)"
|
|
42
|
+
postal_code:
|
|
43
|
+
label: "Code postal"
|
|
44
|
+
full_name:
|
|
45
|
+
label: "Nom complet"
|
|
46
|
+
association_only:
|
|
47
|
+
represent_association:
|
|
48
|
+
label: "Je représente une association"
|