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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module Fields
|
|
6
|
+
class ExtraFieldRefField < GenericField
|
|
7
|
+
attr_accessor :reference, :customization_name
|
|
8
|
+
|
|
9
|
+
delegate :configure_form, :validate, :sanitized_value, :skip_hashing?, to: :peer_field
|
|
10
|
+
|
|
11
|
+
def validate_customization_reference!
|
|
12
|
+
resolve_reference_definition
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def map_model(_form, _data)
|
|
16
|
+
raise Error, "Can't use Extra Field Ref for registration"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def form_tag(form)
|
|
20
|
+
user = current_user(form)
|
|
21
|
+
extended_data = (user.extended_data || {}).with_indifferent_access
|
|
22
|
+
ref = resolve_reference_definition
|
|
23
|
+
stored = extended_data[ref.name]
|
|
24
|
+
assign_form_value(form.object, stored) if stored.present?
|
|
25
|
+
|
|
26
|
+
if stored.present? && options[:hide_if_value]
|
|
27
|
+
content_tag(
|
|
28
|
+
:span,
|
|
29
|
+
form.hidden_field(name),
|
|
30
|
+
class: "#{class_name} #{class_modifer("hidden")}"
|
|
31
|
+
)
|
|
32
|
+
else
|
|
33
|
+
peer = peer_field
|
|
34
|
+
old_context = peer.i18n_context
|
|
35
|
+
peer.i18n_context = i18n_context
|
|
36
|
+
field_tag = peer.form_tag(form)
|
|
37
|
+
peer.i18n_context = old_context
|
|
38
|
+
field_tag
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def i18n_context
|
|
43
|
+
"decidim.custom_user_fields.extended_data"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def peer_field
|
|
49
|
+
@peer_field ||= build_peer_field
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def build_peer_field
|
|
53
|
+
ref = resolve_reference_definition
|
|
54
|
+
peer_type = ref.type
|
|
55
|
+
if peer_type == :extra_field_ref
|
|
56
|
+
raise Decidim::CustomUserFields::Error,
|
|
57
|
+
"extra_field_ref #{name} resolved to another extra_field_ref (#{reference_field_name})"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Force :type last so neither ref.options nor overlays can recreate ExtraFieldRefField.
|
|
61
|
+
kwargs = ref.options.except(:type, "type", :ref, "ref").merge(overlay_options).merge(type: peer_type)
|
|
62
|
+
FieldDefinition.new(name, kwargs, handler_name).field
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def reference_field_name
|
|
66
|
+
CustomizationFieldNaming.prefixed(customization_name, options[:ref] || name)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def storage_name
|
|
70
|
+
reference_field_name
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Extra-field-ref metadata must not leak into the peer field kwargs
|
|
74
|
+
# (especially :type), or FieldDefinition rebuilds another ExtraFieldRefField.
|
|
75
|
+
def overlay_options
|
|
76
|
+
options.except(:ref, :type, :hide_if_value, :skip_update_on_verified, "ref", "type")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def resolve_reference_definition
|
|
80
|
+
@reference ||= begin
|
|
81
|
+
if customization_name.blank?
|
|
82
|
+
raise Decidim::CustomUserFields::Error,
|
|
83
|
+
"customization must be set for extra_field_ref field #{name}"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
customization = Customizations.find(customization_name)
|
|
87
|
+
raise Decidim::CustomUserFields::Error, "Customization #{customization_name} not found" unless customization
|
|
88
|
+
|
|
89
|
+
match = customization.fields.find { |field| field.name == reference_field_name }
|
|
90
|
+
unless match
|
|
91
|
+
raise Decidim::CustomUserFields::Error,
|
|
92
|
+
"Field #{reference_field_name} not found in customization #{customization_name}"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
match.deep_dup.tap do |reference|
|
|
96
|
+
overlays = overlay_options
|
|
97
|
+
next if overlays.empty?
|
|
98
|
+
|
|
99
|
+
reference.options = reference.options.except(:type, "type").merge(overlays)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def assign_form_value(form_object, value)
|
|
105
|
+
if form_object.respond_to?("#{name}=")
|
|
106
|
+
form_object.public_send("#{name}=", value)
|
|
107
|
+
else
|
|
108
|
+
form_object[name] = value
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def current_user(form)
|
|
113
|
+
form.object.user
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -1,38 +1,131 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Decidim
|
|
2
4
|
module CustomUserFields
|
|
3
5
|
module Fields
|
|
4
6
|
class GenericField
|
|
5
|
-
extend Forwardable
|
|
6
7
|
include ActionView::Helpers::TagHelper
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
delegate :name, :type, :handler_name, to: :definition
|
|
10
|
+
|
|
11
|
+
attr_reader :definition
|
|
12
|
+
attr_accessor :options
|
|
9
13
|
|
|
10
|
-
attr_reader :definition, :options
|
|
11
14
|
def initialize(definition, options)
|
|
12
15
|
@definition = definition
|
|
13
16
|
@options = options
|
|
14
17
|
end
|
|
15
18
|
|
|
19
|
+
def validate(_value, _data, _errors); end
|
|
20
|
+
|
|
21
|
+
def sanitized_value(raw_value)
|
|
22
|
+
raw_value
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def skip_hashing?
|
|
26
|
+
options[:skip_hashing].present?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Key used in user.extended_data (overridden by ExtraFieldRefField).
|
|
30
|
+
def storage_name
|
|
31
|
+
name
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def ui_options
|
|
35
|
+
options[:ui] || {}
|
|
36
|
+
end
|
|
37
|
+
|
|
16
38
|
def configure_form(_form)
|
|
17
39
|
raise Error, "Configure Form is not implemented for #{definition.type} type"
|
|
18
40
|
end
|
|
19
41
|
|
|
42
|
+
def configure_settings(_settings)
|
|
43
|
+
raise Error, "Configure Settings is not implemented for #{definition.type} type"
|
|
44
|
+
end
|
|
45
|
+
|
|
20
46
|
def map_model(_form, _model_data)
|
|
21
47
|
raise Error, "Map Model is not implemented for #{definition.type} type"
|
|
22
48
|
end
|
|
23
49
|
|
|
24
|
-
def form_tag(_form)
|
|
50
|
+
def form_tag(_form, _custom_label = nil)
|
|
25
51
|
raise Error, "Form Tag is not implemented for #{definition.type} type"
|
|
26
52
|
end
|
|
27
53
|
|
|
28
54
|
def class_name
|
|
29
|
-
|
|
30
|
-
|
|
55
|
+
@class_name ||= [
|
|
56
|
+
"field",
|
|
57
|
+
class_modifer(type),
|
|
58
|
+
class_modifer(name.to_s.underscore)
|
|
59
|
+
].join(" ")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def label_class_name
|
|
63
|
+
@label_class_name ||= [
|
|
64
|
+
"field_label",
|
|
65
|
+
class_modifer(type, "field_label"),
|
|
66
|
+
class_modifer(name.to_s.underscore, "field_label")
|
|
67
|
+
].join(" ")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def class_modifer(modifier, block = "field")
|
|
71
|
+
"#{block}--#{modifier}"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def label_exists?(label)
|
|
75
|
+
::I18n.exists?(i18n_handler_label(label))
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def label(label)
|
|
79
|
+
i18n_identifier = i18n_handler_label(label)
|
|
80
|
+
unless ::I18n.exists?(i18n_identifier)
|
|
81
|
+
Rails.logger.error("Missing #{i18n_handler_label(label)}")
|
|
82
|
+
return i18n_identifier
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
::I18n.t(
|
|
86
|
+
i18n_identifier,
|
|
87
|
+
default: i18n_identifier
|
|
88
|
+
)
|
|
31
89
|
end
|
|
32
90
|
|
|
33
91
|
def required?
|
|
34
92
|
options[:required].present? && options[:required]
|
|
35
93
|
end
|
|
94
|
+
|
|
95
|
+
def apply_form_validations(form, validations)
|
|
96
|
+
validations = validations.dup
|
|
97
|
+
if validations.has_key?(:presence)
|
|
98
|
+
validations.delete(:presence) if validations[:presence] == false
|
|
99
|
+
elsif required?
|
|
100
|
+
validations[:presence] = true
|
|
101
|
+
end
|
|
102
|
+
return if validations.blank?
|
|
103
|
+
|
|
104
|
+
field_name = name
|
|
105
|
+
validation_options = validations.dup
|
|
106
|
+
if registration_form?(form)
|
|
107
|
+
validation_options[:if] = lambda { |record|
|
|
108
|
+
record.active_custom_field_names.include?(field_name)
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
form.validates(name, **validation_options)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def registration_form?(form)
|
|
115
|
+
form.included_modules.include?(Decidim::CustomUserFields::FormDefinition)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def i18n_context
|
|
119
|
+
@i18n_context ||= "decidim.custom_user_fields.#{handler_name}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
attr_writer :i18n_context
|
|
123
|
+
|
|
124
|
+
private
|
|
125
|
+
|
|
126
|
+
def i18n_handler_label(label)
|
|
127
|
+
"#{i18n_context}.#{name}.#{label}"
|
|
128
|
+
end
|
|
36
129
|
end
|
|
37
130
|
end
|
|
38
131
|
end
|
|
@@ -1,34 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Decidim
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module Fields
|
|
6
|
+
class TextAreaField < GenericField
|
|
7
|
+
def configure_form(form)
|
|
8
|
+
form.attribute(name, String)
|
|
9
|
+
validations = {
|
|
10
|
+
presence: required? && {
|
|
11
|
+
message: label(:required)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if options[:min].present? || options[:max].present?
|
|
15
|
+
min_max_options = {
|
|
16
|
+
wrong_length: proc do
|
|
17
|
+
label(:bad_length)
|
|
18
|
+
end,
|
|
19
|
+
too_long: proc do
|
|
20
|
+
label(:too_long)
|
|
21
|
+
end,
|
|
22
|
+
too_short: proc do
|
|
23
|
+
label(:too_short)
|
|
24
|
+
end
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
26
|
+
min_max_options[:minimum] = options[:min].to_i if options[:min].present?
|
|
27
|
+
min_max_options[:maximum] = options[:max].to_i if options[:max].present?
|
|
28
|
+
validations[:length] = min_max_options
|
|
29
|
+
validations[:allow_blank] = !required?
|
|
29
30
|
end
|
|
31
|
+
apply_form_validations(form, validations)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def sanitized_value(value)
|
|
35
|
+
stripped_value = (value || "").strip
|
|
36
|
+
return stripped_value if stripped_value.present?
|
|
37
|
+
|
|
38
|
+
nil
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def map_model(form, data)
|
|
42
|
+
form[name] = data[name] if data[name].present?
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def form_tag(form_tag)
|
|
46
|
+
field_options = {
|
|
47
|
+
rows: ui_options[:row] || 2,
|
|
48
|
+
label: label(:label),
|
|
49
|
+
help_text: label_exists?(:help_text) && label(:help_text),
|
|
50
|
+
label_options: { class: label_class_name },
|
|
51
|
+
class: class_name
|
|
52
|
+
}
|
|
53
|
+
form_tag.text_area(name, **field_options)
|
|
30
54
|
end
|
|
31
55
|
end
|
|
32
56
|
end
|
|
33
57
|
end
|
|
34
|
-
|
|
58
|
+
end
|
|
@@ -1,21 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Decidim
|
|
2
4
|
module CustomUserFields
|
|
3
5
|
module Fields
|
|
4
6
|
class TextField < GenericField
|
|
5
7
|
def configure_form(form)
|
|
6
8
|
form.attribute(name, String)
|
|
7
|
-
|
|
9
|
+
validations = {}
|
|
10
|
+
validations[:presence] = true if required?
|
|
11
|
+
if options[:values_in]
|
|
12
|
+
validations[:inclusion] = {
|
|
13
|
+
in: options[:values_in],
|
|
14
|
+
message: proc do |_, _|
|
|
15
|
+
label(:bad_values)
|
|
16
|
+
end
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if options[:format]
|
|
21
|
+
validations[:format] = {
|
|
22
|
+
with: options[:format],
|
|
23
|
+
message: proc do |_, _|
|
|
24
|
+
label(:bad_format)
|
|
25
|
+
end
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
apply_form_validations(form, validations)
|
|
8
30
|
end
|
|
9
31
|
|
|
10
32
|
def map_model(form, data)
|
|
11
|
-
form[name] = data[name] if data[name].present?
|
|
33
|
+
form[name] = data[name].strip if data[name].present?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def validate(value, _data, errors)
|
|
37
|
+
if required? && value.blank?
|
|
38
|
+
errors.add(name, label(:required))
|
|
39
|
+
elsif options[:values_in] && value.present? && options[:values_in].exclude?(value)
|
|
40
|
+
errors.add(name, label(:bad_values))
|
|
41
|
+
elsif options[:format] && value.present? && value !~ options[:format]
|
|
42
|
+
errors.add(name, label(:bad_format))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def sanitized_value(value)
|
|
47
|
+
stripped_value = (value || "").strip
|
|
48
|
+
return stripped_value if stripped_value.present?
|
|
49
|
+
|
|
50
|
+
nil
|
|
12
51
|
end
|
|
13
52
|
|
|
14
53
|
def form_tag(form_tag)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
54
|
+
form_tag.text_field(
|
|
55
|
+
name,
|
|
56
|
+
label: label(:label),
|
|
57
|
+
help_text: label_exists?(:help_text) && label(:help_text),
|
|
58
|
+
class: class_name,
|
|
59
|
+
label_options: { class: label_class_name }
|
|
19
60
|
)
|
|
20
61
|
end
|
|
21
62
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module I18n
|
|
6
|
+
# Required translation keys derived from {Customizations} registry.
|
|
7
|
+
# Used by RSpec and the i18n-tasks custom scanner.
|
|
8
|
+
module CustomizationKeys
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def required_keys
|
|
12
|
+
Decidim::CustomUserFields::Customizations.all.flat_map do |customization|
|
|
13
|
+
keys_for(customization)
|
|
14
|
+
end.uniq.sort
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def missing(locale: :en)
|
|
18
|
+
required_keys.reject { |key| ::I18n.exists?(key, locale) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def keys_for(customization)
|
|
22
|
+
name = customization.name
|
|
23
|
+
keys = [
|
|
24
|
+
"decidim_toggle.system.custom_user_fields.#{name}_enabled",
|
|
25
|
+
"decidim.custom_user_fields.customizations.#{name}"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
customization.fields.each do |field|
|
|
29
|
+
keys << "decidim.custom_user_fields.extended_data.#{field.name}.label"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
customization.workflow_handlers.each do |handler|
|
|
33
|
+
keys << "decidim.authorization_handlers.#{handler}.name"
|
|
34
|
+
keys << "decidim.authorization_handlers.#{handler}.explanation"
|
|
35
|
+
auth_fields_for(handler).each do |field|
|
|
36
|
+
keys << "decidim.custom_user_fields.#{handler}.#{field.name}.label"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
keys
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def auth_fields_for(handler)
|
|
44
|
+
klass_name = handler.to_s.camelize
|
|
45
|
+
return [] unless Decidim::CustomUserFields::Verifications.const_defined?(klass_name, false)
|
|
46
|
+
|
|
47
|
+
klass = Decidim::CustomUserFields::Verifications.const_get(klass_name, false)
|
|
48
|
+
Array(klass.try(:decidim_custom_fields))
|
|
49
|
+
rescue NameError
|
|
50
|
+
[]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "i18n/tasks"
|
|
4
|
+
require "i18n/tasks/scanners/scanner"
|
|
5
|
+
require "i18n/tasks/scanners/results/key_occurrences"
|
|
6
|
+
require "i18n/tasks/scanners/results/occurrence"
|
|
7
|
+
require "decidim/custom_user_fields/i18n/customization_keys"
|
|
8
|
+
|
|
9
|
+
module Decidim
|
|
10
|
+
module CustomUserFields
|
|
11
|
+
module I18n
|
|
12
|
+
# Reports {CustomizationKeys.required_keys} as used for i18n-tasks.
|
|
13
|
+
class CustomizationKeysScanner < ::I18n::Tasks::Scanners::Scanner
|
|
14
|
+
def initialize(config: {}, **_kwargs)
|
|
15
|
+
super()
|
|
16
|
+
@config = config
|
|
17
|
+
@registry_ready = false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def keys
|
|
21
|
+
ensure_registry_loaded!
|
|
22
|
+
return [] unless @registry_ready
|
|
23
|
+
|
|
24
|
+
CustomizationKeys.required_keys.map do |key|
|
|
25
|
+
::I18n::Tasks::Scanners::Results::KeyOccurrences.new(
|
|
26
|
+
key:,
|
|
27
|
+
occurrences: [synthetic_occurrence(key)]
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
attr_reader :config
|
|
35
|
+
|
|
36
|
+
def ensure_registry_loaded!
|
|
37
|
+
if defined?(::Rails) && ::Rails.application &&
|
|
38
|
+
defined?(Decidim::CustomUserFields::Customizations)
|
|
39
|
+
@registry_ready = true
|
|
40
|
+
return
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
gem_root = ENV.fetch("ENGINE_ROOT") do
|
|
44
|
+
File.expand_path("../../../..", __dir__)
|
|
45
|
+
end
|
|
46
|
+
environment = File.join(gem_root, "spec/decidim_dummy_app/config/environment.rb")
|
|
47
|
+
unless File.exist?(environment)
|
|
48
|
+
warn(
|
|
49
|
+
"[decidim-user_fields] CustomizationKeysScanner: could not load " \
|
|
50
|
+
"#{environment}; registry keys skipped."
|
|
51
|
+
)
|
|
52
|
+
@registry_ready = false
|
|
53
|
+
return
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
require environment
|
|
57
|
+
Decidim::CustomUserFields::ScenarioCustomizations.register! if defined?(Decidim::CustomUserFields::ScenarioCustomizations)
|
|
58
|
+
@registry_ready = defined?(Decidim::CustomUserFields::Customizations)
|
|
59
|
+
rescue LoadError, StandardError => e
|
|
60
|
+
warn(
|
|
61
|
+
"[decidim-user_fields] CustomizationKeysScanner: failed to boot Rails " \
|
|
62
|
+
"(#{e.class}: #{e.message}); registry keys skipped."
|
|
63
|
+
)
|
|
64
|
+
@registry_ready = false
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def synthetic_occurrence(key)
|
|
68
|
+
::I18n::Tasks::Scanners::Results::Occurrence.new(
|
|
69
|
+
path: "lib/decidim/custom_user_fields/i18n/customization_keys.rb",
|
|
70
|
+
pos: 0,
|
|
71
|
+
line_num: 1,
|
|
72
|
+
line_pos: 1,
|
|
73
|
+
line: "# registry:#{key}",
|
|
74
|
+
raw_key: key
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Host apps: add to config/i18n-tasks.yml —
|
|
4
|
+
# <% require "decidim/custom_user_fields/i18n/tasks" %>
|
|
5
|
+
require "decidim/custom_user_fields/i18n/customization_keys_scanner"
|
|
6
|
+
|
|
7
|
+
I18n::Tasks.add_scanner "Decidim::CustomUserFields::I18n::CustomizationKeysScanner"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module AuthorizationsController
|
|
6
|
+
def onboarding_pending
|
|
7
|
+
return super if pending_onboarding_action?(current_user)
|
|
8
|
+
|
|
9
|
+
unless RegistrationFields.prompt_authorization_on_first_login?(current_organization)
|
|
10
|
+
redirect_to decidim.account_path
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "active_support/concern"
|
|
4
4
|
|
|
5
5
|
module Decidim
|
|
6
6
|
module CustomUserFields
|
|
@@ -12,37 +12,39 @@ module Decidim
|
|
|
12
12
|
|
|
13
13
|
def create_user
|
|
14
14
|
user_payload = {
|
|
15
|
-
email:
|
|
16
|
-
name:
|
|
17
|
-
nickname:
|
|
18
|
-
password:
|
|
19
|
-
|
|
20
|
-
organization:
|
|
21
|
-
tos_agreement:
|
|
22
|
-
newsletter_notifications_at:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
extended_data: extended_data
|
|
15
|
+
email: form.email,
|
|
16
|
+
name: form.name,
|
|
17
|
+
nickname: form.nickname,
|
|
18
|
+
password: form.password,
|
|
19
|
+
password_updated_at: Time.current,
|
|
20
|
+
organization: form.current_organization,
|
|
21
|
+
tos_agreement: form.tos_agreement,
|
|
22
|
+
newsletter_notifications_at: form.newsletter_at,
|
|
23
|
+
accepted_tos_version: form.current_organization.tos_version,
|
|
24
|
+
locale: form.current_locale,
|
|
25
|
+
extended_data:
|
|
27
26
|
}
|
|
28
27
|
@user = User.create!(user_payload)
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
def update_personal_data
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
current_user.locale = @form.locale
|
|
32
|
+
current_user.name = @form.name
|
|
33
|
+
current_user.nickname = @form.nickname
|
|
34
|
+
current_user.email = @form.email
|
|
35
|
+
current_user.personal_url = @form.personal_url
|
|
36
|
+
current_user.about = @form.about
|
|
37
|
+
current_user.extended_data = extended_data
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def extended_data
|
|
41
|
+
org = @form.try(:current_organization)
|
|
41
42
|
custom_data = {}
|
|
42
|
-
|
|
43
|
+
RegistrationFields.active_registration_fields(org).each do |field_def|
|
|
43
44
|
custom_data[field_def.name] = @form[field_def.name]
|
|
44
45
|
end
|
|
45
|
-
|
|
46
|
+
source_user = try(:current_user) || @user
|
|
47
|
+
@extended_data ||= (source_user&.extended_data || {}).merge(custom_data)
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module CustomUserFields
|
|
5
|
+
module ConfirmationsController
|
|
6
|
+
def after_confirmation_path_for(resource_name, resource)
|
|
7
|
+
sign_in(resource)
|
|
8
|
+
store_onboarding_cookie_data!(resource)
|
|
9
|
+
return decidim_verifications.onboarding_pending_authorizations_path if pending_onboarding_action?(resource)
|
|
10
|
+
|
|
11
|
+
prompt_first_login_path(resource) || super
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|