decidim-user_fields 0.0.2 → 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 +308 -49
- 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/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 +80 -10
- 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 +34 -9
- 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 +25 -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 +80 -15
- data/app/overrides/decidim/devise/invitations/edit/extra_user_fields.html.erb.deface +0 -3
|
@@ -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"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
en:
|
|
2
|
+
decidim_toggle:
|
|
3
|
+
system:
|
|
4
|
+
custom_user_fields:
|
|
5
|
+
first_login_mode: "First login mode"
|
|
6
|
+
enabled_customization: "Customization"
|
|
7
|
+
none: "None"
|
|
8
|
+
birthdate_age_gates_enabled: "Birthdate age gates"
|
|
9
|
+
location_validation_enabled: "Location validation"
|
|
10
|
+
association_enabled: "Association representative"
|
|
11
|
+
helptext:
|
|
12
|
+
first_login_mode: "Choose whether participants are prompted to verify after their first sign-in. Authorizations remain available when actions require them."
|
|
13
|
+
enabled_customization: "Enable only one customization at a time to avoid conflicts. Choose none to keep extra fields and bundled authorizations off."
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
fr:
|
|
2
|
+
decidim_toggle:
|
|
3
|
+
system:
|
|
4
|
+
custom_user_fields:
|
|
5
|
+
first_login_mode: "Mode première connexion"
|
|
6
|
+
enabled_customization: "Personnalisation"
|
|
7
|
+
none: "Aucune"
|
|
8
|
+
birthdate_age_gates_enabled: "Contrôles d'âge par date de naissance"
|
|
9
|
+
location_validation_enabled: "Validation de localisation"
|
|
10
|
+
association_enabled: "Représentant d'association"
|
|
11
|
+
helptext:
|
|
12
|
+
first_login_mode: "Choisir si les participants sont invités à se vérifier après leur première connexion. Les autorisations restent disponibles lorsque les actions les exigent."
|
|
13
|
+
enabled_customization: "Activer une seule personnalisation à la fois pour éviter les conflits. Choisir aucune pour laisser les champs extra et les autorisations groupées désactivés."
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
en:
|
|
2
|
+
decidim:
|
|
3
|
+
custom_user_fields:
|
|
4
|
+
system:
|
|
5
|
+
customizations_tab: "User fields"
|
|
6
|
+
first_login_mode:
|
|
7
|
+
prompt_authorization: "Prompt authorization"
|
|
8
|
+
none: "None"
|
|
9
|
+
customizations:
|
|
10
|
+
incompatible_authorizations: "Incompatible with enabled authorizations: %{authorizations}"
|
|
11
|
+
unknown_customization: "Unknown customization: %{name}"
|
|
12
|
+
date:
|
|
13
|
+
required: "This date is required"
|
|
14
|
+
bad_format: "This date is badly formatted"
|
|
15
|
+
bad_not_before: "This date is invalid"
|
|
16
|
+
bad_not_after: "This date is invalid"
|
|
17
|
+
bad_date: "This date is invalid"
|
|
18
|
+
textarea:
|
|
19
|
+
required: "This text is required"
|
|
20
|
+
bad_length: "This text is invalid"
|
|
21
|
+
too_long: "Must be less than %{count} characters"
|
|
22
|
+
too_short: "Must be more than %{count} characters"
|
|
23
|
+
text:
|
|
24
|
+
bad_values: "This value is not allowed"
|
|
25
|
+
bad_format: "Please check this format again"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
fr:
|
|
2
|
+
decidim:
|
|
3
|
+
custom_user_fields:
|
|
4
|
+
system:
|
|
5
|
+
customizations_tab: "Champs utilisateur"
|
|
6
|
+
first_login_mode:
|
|
7
|
+
prompt_authorization: "Demander une autorisation"
|
|
8
|
+
none: "Aucun"
|
|
9
|
+
customizations:
|
|
10
|
+
incompatible_authorizations: "Incompatible avec les autorisations activées : %{authorizations}"
|
|
11
|
+
unknown_customization: "Personnalisation inconnue : %{name}"
|
|
12
|
+
date:
|
|
13
|
+
required: "Cette date est obligatoire"
|
|
14
|
+
bad_format: "Cette date est mal formatée"
|
|
15
|
+
bad_not_before: "Cette date est invalide"
|
|
16
|
+
bad_not_after: "Cette date est invalide"
|
|
17
|
+
bad_date: "Cette date est invalide"
|
|
18
|
+
textarea:
|
|
19
|
+
required: "Ce texte est obligatoire"
|
|
20
|
+
bad_length: "Ce texte est invalide"
|
|
21
|
+
too_long: "Doit être moins de %{count} caractères"
|
|
22
|
+
too_short: "Doit être plus de %{count} caractères"
|
|
23
|
+
text:
|
|
24
|
+
bad_values: "Cette valeur n'est pas autorisée"
|
|
25
|
+
bad_format: "Vérifiez à nouveau ce format"
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "decidim/custom_user_fields/definition_guidance"
|
|
4
|
+
|
|
1
5
|
module Decidim
|
|
2
6
|
module CustomUserFields
|
|
3
7
|
include ActiveSupport::Configurable
|
|
4
8
|
|
|
9
|
+
DSL_METHODS = [:configure, :register_customization].freeze
|
|
10
|
+
|
|
5
11
|
def self.configure
|
|
6
12
|
yield self
|
|
7
13
|
end
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# by default
|
|
12
|
-
config_accessor :default_email_on_notification do
|
|
13
|
-
false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.custom_fields
|
|
17
|
-
@custom_fields ||= []
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.add_field(field_type, field_definition)
|
|
21
|
-
custom_fields.push(FieldDefinition.new(field_type, field_definition))
|
|
22
|
-
self
|
|
15
|
+
def self.register_customization(name, &)
|
|
16
|
+
Customizations.register(name, &)
|
|
23
17
|
end
|
|
24
18
|
|
|
25
19
|
class Error < StandardError; end
|
|
20
|
+
|
|
21
|
+
extend DefinitionMissing
|
|
26
22
|
end
|
|
27
23
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module CustomizationFieldNaming
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def prefixed(customization_name, field_name)
|
|
9
|
+
name = field_name.to_s
|
|
10
|
+
prefix = "#{customization_name}_"
|
|
11
|
+
return field_name.to_sym if name.start_with?(prefix)
|
|
12
|
+
|
|
13
|
+
:"#{prefix}#{name}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module Customizations
|
|
6
|
+
class Builder
|
|
7
|
+
include DefinitionMissing
|
|
8
|
+
|
|
9
|
+
DSL_METHODS = [:registration_fields, :authorization].freeze
|
|
10
|
+
|
|
11
|
+
def initialize(customization)
|
|
12
|
+
@customization = customization
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def registration_fields(&)
|
|
16
|
+
field_builder = RegistrationFieldsBuilder.new(@customization)
|
|
17
|
+
yield field_builder
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def authorization(name, &)
|
|
21
|
+
Decidim::CustomUserFields::Verifications.register(name, customization: @customization.name, &)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class RegistrationFieldsBuilder
|
|
26
|
+
include DefinitionMissing
|
|
27
|
+
|
|
28
|
+
DSL_METHODS = [:add_field].freeze
|
|
29
|
+
|
|
30
|
+
def initialize(customization)
|
|
31
|
+
@customization = customization
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def add_field(field_name, field_definition)
|
|
35
|
+
if RegistrationFields.reserved_key?(field_name.to_s.to_sym)
|
|
36
|
+
raise Decidim::CustomUserFields::Error,
|
|
37
|
+
"Field name #{field_name} is reserved by decidim-core extended_data"
|
|
38
|
+
end
|
|
39
|
+
field_name = CustomizationFieldNaming.prefixed(@customization.name, field_name)
|
|
40
|
+
|
|
41
|
+
@customization.fields.push(
|
|
42
|
+
FieldDefinition.new(field_name, field_definition, "extended_data")
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module Customizations
|
|
6
|
+
class Customization
|
|
7
|
+
attr_reader :name, :fields, :workflow_handlers
|
|
8
|
+
|
|
9
|
+
def initialize(name)
|
|
10
|
+
@name = name.to_sym
|
|
11
|
+
@fields = []
|
|
12
|
+
@workflow_handlers = []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def label
|
|
16
|
+
::I18n.t(
|
|
17
|
+
@name,
|
|
18
|
+
scope: "decidim.custom_user_fields.customizations",
|
|
19
|
+
default: @name.to_s.humanize
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def register_handler!(handler_name)
|
|
24
|
+
@workflow_handlers << handler_name.to_s unless @workflow_handlers.include?(handler_name.to_s)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|