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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +320 -55
  3. data/Rakefile +253 -0
  4. data/app/forms/decidim/custom_user_fields/admin/customizations_config_form.rb +67 -0
  5. data/app/forms/decidim/custom_user_fields/verifications/verification_form.rb +85 -0
  6. data/app/overrides/decidim/admin/officializations/index/_export_users_dropdown.html.erb.deface +1 -3
  7. data/app/overrides/decidim/devise/invitations/edit/extra_user_fields_form.html.erb.deface +2 -2
  8. data/app/overrides/decidim/devise/omniauth_registrations/new/extra_user_fields.html.erb.deface +3 -0
  9. data/app/overrides/invitation_override.rb +31 -0
  10. data/app/packs/entrypoints/decidim_custom_user_fields.js +0 -0
  11. data/app/packs/stylesheets/decidim/custom_user_fields/_decidim_custom_user_fields.scss +48 -0
  12. data/app/views/decidim/custom_user_fields/_profile_form.html.erb +2 -2
  13. data/app/views/decidim/custom_user_fields/_registration_form.html.erb +2 -2
  14. data/app/views/decidim/custom_user_fields/_verification_form.erb +4 -0
  15. data/app/views/decidim/custom_user_fields/system/_customizations_tab.html.erb +15 -0
  16. data/config/assets.rb +9 -0
  17. data/config/i18n-tasks.yml +22 -0
  18. data/config/locales/decidim_custom_user_fields_scenarios.en.yml +50 -0
  19. data/config/locales/decidim_custom_user_fields_scenarios.fr.yml +48 -0
  20. data/config/locales/decidim_toggle.en.yml +13 -0
  21. data/config/locales/decidim_toggle.fr.yml +13 -0
  22. data/config/locales/decidim_user_fields.en.yml +25 -0
  23. data/config/locales/decidim_user_fields.fr.yml +25 -0
  24. data/lib/decidim/custom_user_fields/custom_user_fields.rb +10 -14
  25. data/lib/decidim/custom_user_fields/customization_field_naming.rb +17 -0
  26. data/lib/decidim/custom_user_fields/customizations/builder.rb +48 -0
  27. data/lib/decidim/custom_user_fields/customizations/customization.rb +29 -0
  28. data/lib/decidim/custom_user_fields/customizations.rb +42 -0
  29. data/lib/decidim/custom_user_fields/decidim_integrations.rb +52 -0
  30. data/lib/decidim/custom_user_fields/definition_guidance.rb +109 -0
  31. data/lib/decidim/custom_user_fields/dev/bootstrap.rb +102 -0
  32. data/lib/decidim/custom_user_fields/dev/local_oidc_seeder.rb +150 -0
  33. data/lib/decidim/custom_user_fields/dev/omniauth_providers_patcher.rb +68 -0
  34. data/lib/decidim/custom_user_fields/dev/openid_connect_setup.rb +110 -0
  35. data/lib/decidim/custom_user_fields/dev/scenario_customizations.rb +72 -0
  36. data/lib/decidim/custom_user_fields/engine.rb +59 -26
  37. data/lib/decidim/custom_user_fields/extended_data.rb +52 -0
  38. data/lib/decidim/custom_user_fields/field_definition.rb +28 -6
  39. data/lib/decidim/custom_user_fields/fields/boolean_field.rb +51 -0
  40. data/lib/decidim/custom_user_fields/fields/date_field.rb +91 -22
  41. data/lib/decidim/custom_user_fields/fields/dummy_field.rb +40 -0
  42. data/lib/decidim/custom_user_fields/fields/extra_field_ref_field.rb +118 -0
  43. data/lib/decidim/custom_user_fields/fields/generic_field.rb +99 -6
  44. data/lib/decidim/custom_user_fields/fields/text_area_field.rb +51 -27
  45. data/lib/decidim/custom_user_fields/fields/text_field.rb +47 -6
  46. data/lib/decidim/custom_user_fields/i18n/customization_keys.rb +55 -0
  47. data/lib/decidim/custom_user_fields/i18n/customization_keys_scanner.rb +80 -0
  48. data/lib/decidim/custom_user_fields/i18n/tasks.rb +7 -0
  49. data/lib/decidim/custom_user_fields/overrides/authorizations_controller.rb +18 -0
  50. data/lib/decidim/custom_user_fields/overrides/command.rb +23 -21
  51. data/lib/decidim/custom_user_fields/overrides/confirmations_controller.rb +15 -0
  52. data/lib/decidim/custom_user_fields/overrides/devise_authentication_methods.rb +68 -0
  53. data/lib/decidim/custom_user_fields/overrides/form_definition.rb +27 -8
  54. data/lib/decidim/custom_user_fields/overrides/invitations_controller.rb +109 -0
  55. data/lib/decidim/custom_user_fields/overrides/omniauth_command.rb +40 -0
  56. data/lib/decidim/custom_user_fields/overrides/omniauth_registrations_controller.rb +93 -0
  57. data/lib/decidim/custom_user_fields/overrides/user.rb +16 -0
  58. data/lib/decidim/custom_user_fields/registration_fields.rb +99 -0
  59. data/lib/decidim/custom_user_fields/update_customizations_config_command.rb +39 -0
  60. data/lib/decidim/custom_user_fields/upgrade/migrate_toggle_config.rb +74 -0
  61. data/lib/decidim/custom_user_fields/verifications/builder.rb +100 -0
  62. data/lib/decidim/custom_user_fields/verifications/verifications.rb +82 -0
  63. data/lib/decidim/custom_user_fields/version.rb +4 -2
  64. data/lib/decidim/user_fields.rb +46 -13
  65. data/lib/tasks/decidim/custom_user_fields/custom_user_fields_upgrade.rake +16 -0
  66. data/lib/tasks/decidim/custom_user_fields/custom_user_fields_webpacker.rake +59 -0
  67. data/lib/tasks/decidim/custom_user_fields/decidim_custom_user_fields_upgrade_tasks.rake +16 -0
  68. data/lib/tasks/decidim/custom_user_fields/dev/local_setup.rake +16 -0
  69. metadata +81 -16
  70. data/app/overrides/decidim/devise/invitations/edit/extra_user_fields.html.erb.deface +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d7b7ee3b6215fc3fb95f7d1501369650d051fe38e731492fc9ce5628ad75577
4
- data.tar.gz: c4d1e5eb6e11d01ea3a61196a73ad107c34b96c43c52c6ab388ba733e98ad00d
3
+ metadata.gz: 24006b3a04eeb2d3236a31ed29ccbd834fc0cb2f99794c4d38dcba978c1d75c1
4
+ data.tar.gz: 94c451d2d5ff60e16cf14afb8f0efaed037e763f19b305170415b0fd5e496845
5
5
  SHA512:
6
- metadata.gz: 8adddf951a431b592d6062f04b31478c0ddeef718b492b78ddadaf995b1bf2b208f2fa8937a47bad2009f4410b4518845d264fff123477ab72c6622719a4b5d7
7
- data.tar.gz: cfda033cd73225d2834d8617f8898f248a97ddae6a4f8d32a7997315340a2dec0bd133ba065c62b277a2806ddf96a31eafa082b10b1ef7a83ba815a644d3bb37
6
+ metadata.gz: 7e833154273a50cfb23d7b3529b04d9241750199be3d2095c564c1ae31974c38c60c4894f4610afd3ccf095e5dce1da0de1475b19f91120a1ba55348a25adbf6
7
+ data.tar.gz: 75d66d356e14ffd771423d3b4dd7bcac4b3f843e7c7c7fcff0ee1da3666af3015f9e696f5a0f50df375bf976535583a9894d54cfa468ab2e1f15382762d0aa44
data/README.md CHANGED
@@ -1,60 +1,230 @@
1
- <h1 align="center"><img src="https://github.com/octree-gva/meta/blob/main/decidim/static/header.png?raw=true" alt="Decidim - Octree Participatory democracy on a robust and open source solution" /></h1>
1
+ <h1 align="center"><img src="https://github.com/octree-gva/meta/blob/main/decidim/static/header.png?raw=true" alt="Decidim - Octree: Participatory Democracy on a Robust and Open Source Solution" /></h1>
2
2
  <h4 align="center">
3
3
  <a href="https://www.octree.ch">Octree</a> |
4
4
  <a href="https://octree.ch/en/contact-us/">Contact Us</a> |
5
5
  <a href="https://blog.octree.ch">Our Blog (FR)</a><br/><br/>
6
6
  <a href="https://decidim.org">Decidim</a> |
7
7
  <a href="https://docs.decidim.org/en/">Decidim Docs</a> |
8
- <a href="https://meta.decidim.org">Participatory Governance (meta decidim)</a><br/><br/>
8
+ <a href="https://meta.decidim.org">Participatory Governance (Meta Decidim)</a><br/><br/>
9
9
  <a href="https://matrix.to/#/+decidim:matrix.org">Decidim Community (Matrix+Element.io)</a>
10
10
  </h4>
11
11
  <p align="center">
12
12
  <a href="https://participe.gland.ch">
13
13
  <img
14
14
  src="https://github.com/octree-gva/meta/blob/main/decidim/static/participe_gland.png?raw=true"
15
- alt="Participe Gland — Donnez vie à vos idées avec le budget participatif" />
15
+ alt="Participe Gland — Give Life to Your Ideas with the Participatory Budget" />
16
16
  </a>
17
- <a href="https://mkutano.community"><img src="https://github.com/octree-gva/decidim-module-mkutano_custom_registration_flow/blob/main/mkutano-logo.png?raw=true" alt="MKUTANO is a participatory platform where black canadians can effectively & democratically organize at scale" /></a>
17
+ <a href="https://mkutano.community"><img src="https://github.com/octree-gva/decidim-module-mkutano_custom_registration_flow/blob/main/mkutano-logo.png?raw=true" alt="MKUTANO is a participatory platform where Black Canadians can effectively & democratically organize at scale" /></a>
18
18
  <a href="https://opencollective.com/voca">
19
19
  <img
20
20
  src="https://github.com/octree-gva/meta/blob/main/decidim/static/opencollective_chip.png?raw=true"
21
- alt="Voca – Open-Source SaaS platform for Decidim" />
21
+ alt="Voca – Open-Source SaaS Platform for Decidim" />
22
22
  </a>
23
23
  </p>
24
24
 
25
-
26
25
  # Decidim User Fields
27
- Add custom user fields, through configuration file and without migration.
28
- This module aims to configure in a blast new fields for subscription and profile edition. It supports:
26
+ This Decidim module adds custom user fields through a configuration file and without migration. This module aims to configure in a blast new fields for subscription and profile editing. It supports:
29
27
 
30
28
  - User registration
31
29
  - User profiles
32
- - User invitations.
30
+ - User invitations
31
+ - Omniauth registration (OIDC profile completion after IdP sign-in)
33
32
 
34
- ⚠️ It **does not support**:
33
+ > Are you on GitHub ? Please use the reference repository on [GitLab for issues and pull requests](https://git.octree.ch/decidim/vocacity/decidim-modules/decidim-user_fields).
35
34
 
36
- - Omniauth registrations
35
+ All the information to use the gem is on our [documentation website](https://octree-gva.github.io/decidim-user_fields)
37
36
 
38
- ## Setup the module
39
- Add the gem to your gemfile
40
- ```
37
+ ## Install the module
38
+ Add the gems to your Gemfile
39
+ ```ruby
41
40
  gem "decidim-user_fields"
41
+ gem "decidim-toggle",
42
+ git: "https://git.octree.ch/decidim/vocacity/decidim-modules/decidim-toggle",
43
+ branch: "main"
42
44
  ```
43
45
 
44
- Run bundle
45
- ```
46
+ Run bundle and install toggle migrations:
47
+ ```bash
46
48
  bundle install
49
+ rails decidim_toggle:install:migrations
50
+ rails db:migrate
51
+ ```
52
+
53
+ ## Customizations (per organization)
54
+
55
+ Register named customizations in an initializer. Each customization bundles registration/profile fields and authorization workflows. Sysadmins enable them per organization in **System → Organizations → User field customizations** (via decidim-toggle).
56
+
57
+ ```ruby
58
+ Decidim::CustomUserFields.register_customization :community do |customization|
59
+ customization.registration_fields do |set|
60
+ set.add_field :social_media_url, type: :text, required: false
61
+ end
62
+ end
63
+
64
+ Decidim::CustomUserFields.register_customization :ngos do |customization|
65
+ customization.registration_fields do |set|
66
+ set.add_field :organization_name, type: :text, required: true
67
+ set.add_field :organization_email, type: :text, required: true
68
+ end
69
+
70
+ customization.authorization "NgoVerify" do |config|
71
+ config.add_field :organization_name, type: :extra_field_ref, ref: :organization_name, required: true
72
+ end
73
+ end
74
+ ```
75
+
76
+ Admin toggle radio labels: `decidim_toggle.system.custom_user_fields.<name>_enabled`. The none option uses `decidim_toggle.system.custom_user_fields.none`.
77
+ Customization display labels (`Customization#label`): `decidim.custom_user_fields.customizations.<name>`.
78
+
79
+ Full key list and how to run `i18n-tasks missing` (customization registry scanner): see the [Translate](https://octree-gva.github.io/decidim-user_fields/dev_documentation/locales) docs page.
80
+
81
+ Sysadmins enable at most one customization per organization (radio). Bundled authorization workflows appear under **System → Authorizations** only while that customization is enabled; switching or choosing none also unselects those handlers.
82
+
83
+ ## Upgrading from field sets to customizations
84
+
85
+ User values in `extended_data` and existing authorization grants are unchanged when field and handler names stay the same.
86
+
87
+ Toggle config migrates from `{ "active_field_set": "default" }` to `{ "enabled_customization": "default" }`.
88
+
89
+ On deploy, `bin/rails decidim:upgrade` (or `decidim:update`) runs `decidim_custom_user_fields:upgrade:migrate_toggle_config` automatically.
90
+
91
+ Until that runs, the module still reads `active_field_set` and legacy `{name}_enabled` flags when `enabled_customization` is absent.
92
+
93
+ Manual run:
94
+
95
+ ```bash
96
+ bin/rails decidim_custom_user_fields:upgrade:migrate_toggle_config
97
+ DRY_RUN=1 bin/rails decidim_custom_user_fields:upgrade:migrate_toggle_config
98
+ ```
99
+
100
+ Refactor your initializer from `register_field_set` to `register_customization`, keeping the same customization name as the former field set (e.g. `:default`). Unknown or removed DSL calls (`custom_fields`, `register_field_set`, `configure { add_field }`, typos) raise `Decidim::CustomUserFields::Error` with a migration or DidYouMean hint.
101
+
102
+ ## Try Omniauth locally (Zitadel + Docker)
103
+
104
+ Local review of this gem (clone this repo). Integrators adding the gem to an existing Decidim app: see **Install the module** above.
105
+
106
+ **Prerequisite:** Docker and Docker Compose.
107
+
108
+ ### Quick start
109
+
110
+ 1. Clone this repository.
111
+ 2. `./bin/dev-oidc-up`
112
+ 3. Wait (~5–10 min the first time).
113
+ 4. Open http://localhost:3000.
114
+
115
+ Unlike `spam_signal` / `voca`, default `docker compose up` does **not** start a Decidim process; do not use `docker compose up -d decidim` for first success.
116
+
117
+ Idempotent: safe to re-run when the stack is already up.
118
+
119
+ ### What `./bin/dev-oidc-up` does
120
+
121
+ | Step | Action | Output |
122
+ |------|--------|--------|
123
+ | 1 | Start Zitadel stack | Zitadel on :8080, admin PAT in `docker/zitadel/bootstrap/admin.pat` |
124
+ | 2 | Configure Zitadel SMTP + OIDC app | `docker/zitadel/oidc.env` (gitignored) |
125
+ | 3 | `rake test_app` (first time only) | Dummy app in `spec/decidim_dummy_app` |
126
+ | 4 | `dev:prepare_secrets`, `db:drop db:create db:migrate` | Empty Decidim schema |
127
+ | 5 | `dev:seed` | Minimal org + admin + Zitadel provider + **association** scenario |
128
+ | 6 | `docker compose --profile dev run --rm --service-ports decidim … rails s` | Rails on http://localhost:3000 (foreground) |
129
+
130
+ ### URLs and credentials
131
+
132
+ | URL | Purpose |
133
+ |-----|---------|
134
+ | http://localhost:3000 | Decidim dummy app |
135
+ | http://localhost:8080 | Zitadel console |
136
+ | http://localhost:1080 | MailCatcher (emails) |
137
+
138
+ | Account | Login |
139
+ |---------|-------|
140
+ | Decidim admin | `admin@example.org` / `decidim123456789` |
141
+ | Zitadel admin | `admin@zitadel.localhost` / `Password1!` |
142
+
143
+ ### Experiment: OIDC sign-in → custom fields
144
+
145
+ 1. Open http://localhost:8080, sign in as Zitadel admin.
146
+ 2. **Users → New** — create a test user (email + password).
147
+ 3. Open http://localhost:3000/users/sign_in, click **Zitadel**, sign in with that user.
148
+ 4. Complete the profile form — the association demo shows the “I represent an association” checkbox.
149
+ 5. Optional: verify authorization at http://localhost:3000/account/authorizations/new?handler=association_only (after checking the boolean on registration).
150
+
151
+ Change the seeded scenario (e.g. optional birthdate + age authorizations):
152
+
153
+ ```bash
154
+ DEV_CUSTOMIZATION=birthdate_age_gates ./bin/dev-oidc-up
155
+ ```
156
+
157
+ ### Environment variables (local OIDC)
158
+
159
+ | Variable | Default | Required | Purpose |
160
+ |----------|---------|----------|---------|
161
+ | `DEV_CUSTOMIZATION` | `association` | no | Scenario customization enabled by `dev:seed` (`association`, `birthdate_age_gates`, `location_validation`) |
162
+ | `DECIDIM_HOST` | `localhost` | no | Organization host matched by `dev:seed` |
163
+ | `ZITADEL_OIDC_ENABLED` | set in compose | no | Loads dev OIDC middleware + scenario customizations |
164
+ | `ZITADEL_URL` | `http://localhost:8080` | no | Zitadel API base URL used by `dev-oidc-up` |
165
+ | `OIDC_ISSUER` | `http://localhost:8080` | no | Public issuer written to `oidc.env` |
166
+ | `OIDC_REDIRECT_URI` | `http://localhost:3000/users/auth/openid_connect/callback` | no | OIDC redirect URI for the Zitadel app |
167
+
168
+ Generated at setup time (do not commit): `docker/zitadel/oidc.env` — see `docker/zitadel/oidc.env.example`.
169
+
170
+ ### Troubleshooting
171
+
172
+ | Symptom | Fix |
173
+ |---------|-----|
174
+ | No **Zitadel** button on sign-in | Re-run `./bin/dev-oidc-up` |
175
+ | `Missing docker/zitadel/oidc.env` | Re-run `./bin/dev-oidc-up` (Zitadel must be ready first) |
176
+ | `Missing PAT at docker/zitadel/bootstrap/admin.pat` | `docker compose down -v` then `./bin/dev-oidc-up` |
177
+ | Zitadel not ready yet | Wait 1–2 min on first boot; check http://localhost:8080/debug/ready |
178
+ | `connection refused` to `localhost:8080` on Zitadel login | Re-run `./bin/dev-oidc-up` — token/userinfo must use `zitadel:8080` inside Docker |
179
+ | Zitadel login fails with `"Unknown"` / `Instance not found` | Ensure `ZITADEL_PUBLIC_HOST=localhost:8080` on the Decidim container (Host header for internal calls) |
180
+ | OIDC completes custom fields but asks for email confirmation | Re-run `./bin/dev-oidc-up` after updating the gem — OpenID Connect verified emails should sign you in directly |
181
+ | Port 3000 empty | Do not use plain `docker compose up` or `docker compose up -d decidim` — use `./bin/dev-oidc-up` |
182
+ | `cd: spec/decidim_dummy_app: No such file or directory` (or missing `config/application.rb`) | Optional `docker compose down -v`, then `./bin/dev-oidc-up` (script runs `rake test_app` before any dummy `cd`) |
183
+ | `network … not found` when starting Rails | Stale compose network after one-shots — re-run `./bin/dev-oidc-up` (script no longer uses `profile web up`) |
184
+ | `decidim_users already exists` on setup | Re-run `docker compose down -v && ./bin/dev-oidc-up` (script runs `db:drop db:create db:migrate`) |
185
+ | `A server is already running` / stale `server.pid` | `rm -f spec/decidim_dummy_app/tmp/pids/server.pid` then re-run `./bin/dev-oidc-up` |
186
+
187
+ Reset all local data: `docker compose down -v` then `./bin/dev-oidc-up`.
188
+
189
+ ## How to add a custom user field
190
+
191
+ Create an initializer `config/initializers/custom_user_fields.rb`:
192
+
193
+ ```ruby
194
+ Decidim::CustomUserFields.register_customization :default do |customization|
195
+ customization.registration_fields do |set|
196
+ set.add_field :birthdate, type: :date, required: true
197
+ set.add_field :address, type: :textarea, required: false, rows: 10
198
+ set.add_field :purpose, type: :text, required: false
199
+ end
200
+ end
201
+ ```
202
+ ## Renewable verifications
203
+ To set an authorization as renewable, register it inside a customization and use `renewable!(time_between_renew)`:
47
204
  ```
205
+ Decidim::CustomUserFields.register_customization :pb2024 do |customization|
206
+ customization.registration_fields { |set| set.add_field :foo, type: :text }
207
+ customization.authorization "PB2024" do |config|
208
+ config.renewable!(2.days) # Will need to renew authorization after 2 days.
209
+ end
210
+ end
211
+ ```
212
+ This will have no effect under < 30, or without the `decidim-ephemerable` gem.
213
+
48
214
 
49
- Create an initializer `config/initializers/custom_user_fields.rb`
215
+
216
+ ## Ephemerable verifications
217
+ To set an authorization as ephemerable, register it inside a customization and use `ephemerable!`:
50
218
  ```
51
- Decidim::CustomUserFields.configure do |config|
52
- config.add_field :birthdate, type: :date, required: true
53
- config.add_field :province, type: :select, options: [:vd, :vs, :ar], default: :vd, required: true
54
- config.add_field :adress, type: :textarea, required: false, rows: 10
55
- config.add_field :purpose, type: :text, required: false
219
+ Decidim::CustomUserFields.register_customization :pb2024 do |customization|
220
+ customization.registration_fields { |set| set.add_field :foo, type: :text }
221
+ customization.authorization "PB2024" do |config|
222
+ config.ephemerable!
223
+ config.renewable!(1.day) # The ephemerable will be valid for a day
224
+ end
56
225
  end
57
226
  ```
227
+ This will have no effect under < 30, or without the `decidim-ephemerable` gem.
58
228
 
59
229
  ### Available field types
60
230
 
@@ -62,60 +232,155 @@ end
62
232
 
63
233
  parameters:
64
234
  * `required`: must choose a date
65
- * `min`: date in ISO8601 where the user can not select before
66
- * `max`: date in ISO8601 where the user can not select after
235
+ * `not_before`: date in ISO8601 where the user cannot select before
236
+ * `not_after`: date in ISO8601 where the user cannot select after
237
+ * `skip_hashing`: Do not hash the field result (watch out privacy concerns)
67
238
 
68
239
  **`:textarea`**
240
+ a textarea field, which the content will be trimmed (no whitespaces before and after).
69
241
 
70
242
  parameters:
71
243
  * `required`: if the field is required
72
- * `min`: minimal length
73
- * `max`: maximal length
74
- * `rows`: how much rows the field should display
244
+ * `min`: minimal text length
245
+ * `max`: maximal text length
246
+ * `skip_hashing`: Do not hash the field result (watch out privacy concerns)
247
+ * `ui.rows`: how many rows the field should display
75
248
 
76
249
  **`:text`**
250
+ a text field, which the content will be trimmed (no whitespaces before and after).
77
251
 
78
252
  parameters:
79
253
  * `required`: if the field is required
254
+ * `values_in`: restrict the values accepted for the field
255
+ * `format`: a regex (like `format: /\A[A-z0-9]*\z/)
256
+ * `skip_hashing`: Do not hash the field result (watch out privacy concerns)
257
+
258
+ **`:extra_field_ref` (Authorization only)**
259
+ > This field is a quiet special one, it allows workflows where
260
+ > the extra_field on registration is optional, but get required on authorization.
261
+ > Warning: this field can be use only in authorization configuration
262
+
263
+ parameters:
264
+ * `ref`: the extra_field reference name
265
+ * `hide_if_value`: hide the extra field if there is already a value.
266
+ * `skip_hashing`: Do not hash the field result (watch out privacy concerns)
267
+ * `skip_update_on_verified`: Do not update the extra_field reference when verified
268
+ * `...`: any other parameters to override the reference option
269
+
80
270
 
81
271
  ### Labels
82
- Labels are translated, and are under the traduction scope `decidim.custom_user_fields`.
83
- Example of a `fr.yml` file:
272
+ Labels are translated and are under the translation scope `decidim.custom_user_fields`.
273
+ Example of a `config/locales/fr.yml` file:
84
274
 
85
275
  ```yml
86
276
  fr:
87
- activemodel:
88
- attributes:
89
- user:
90
- birthday: "Birthday"
91
- adress: "Addresse"
92
- purpose: "Raison d'être ici"
93
- province: "Canton"
94
277
  decidim:
278
+ authorization_handlers:
279
+ pb2024:
280
+ name: "Données de rescencement pour le Budget Participatif 2024"
281
+ explanation: "Donnée récoltée pour participer au BP 2024"
95
282
  custom_user_fields:
96
- province:
97
- options:
98
- vd: "Vaud"
99
- vs: "Valais"
100
- ar: "Aarau"
283
+ extended_data:
284
+ first_name:
285
+ label: "Prénoms"
286
+ last_name:
287
+ label: "Nom de famille"
288
+ pb2024:
289
+ birthdate:
290
+ label: "Date de naissance"
291
+ help_text: "La participation est réservée aux personnes de plus de 18ans"
292
+ postal_code:
293
+ label: "Code postal"
294
+ help_text: "La participation est réservée aux habitants de MaCommune.
101
295
  ```
102
296
 
103
- ## Run locally
104
- To run this module locally, we use docker-compose:
297
+ # Create an authorization with custom fields
298
+
299
+ ```ruby
300
+ Decidim::CustomUserFields.register_customization :pb2024 do |customization|
301
+ customization.registration_fields do |set|
302
+ set.add_field :first_name, type: :text, required: false
303
+ set.add_field :last_name, type: :text, required: false
304
+ end
305
+
306
+ customization.authorization "PB2024" do |config|
307
+ config.ephemerable!
308
+ config.add_field :first_name, type: :extra_field_ref, required: true, skip_hashing: true, hide_if_value: true
309
+ config.add_field :last_name, type: :extra_field_ref, required: true, skip_hashing: true, hide_if_value: true
310
+ config.add_field :birthdate, type: :date, required: true, not_after: 18.years.ago.to_date.iso8601
311
+ config.add_field :postal_code, type: :text, required: true, format: /\A[\-0-9]*\z/, values_in: ["2000", "2001", "2002"]
312
+ end
313
+ end
314
+ ```
315
+
316
+ Then, add locales for this flow:
317
+ ```yml
318
+ fr:
319
+ decidim:
320
+ authorization_handlers:
321
+ pb2024:
322
+ name: "Participer au BP 2024"
323
+ explanation: "Valider votre compte"
324
+ custom_user_fields:
325
+ first_name:
326
+ label: Prénoms
327
+ help_text: Ce champs est requis pour participer aux budgets participatif.
328
+ last_name:
329
+ label: Nom de famille
330
+ pb2024:
331
+ birthdate:
332
+ label: Date de naissance
333
+ bad_not_after: Seul les > 18 peuvent participer
334
+ postal_code:
335
+ label: Code postal
336
+ bad_values: Ce code postal est inconu dans maCommune
337
+ help_text: Seul les communies prêt de maCommune peux être acceptée
338
+ ```
339
+
340
+ ## Module development (specs, shell)
341
+
342
+ For **OIDC experimentation**, use [Try Omniauth locally](#try-omniauth-locally-zitadel--docker) above.
343
+
344
+ The `decidim` compose service is the OIDC/dev container (shell or Rails). `./bin/dev-oidc-up` starts Rails with `compose run --service-ports`.
345
+
346
+ ```bash
347
+ # Interactive shell in the dev container
348
+ docker compose --profile dev run --rm decidim bash
349
+
350
+ # CI-shaped specs (default Gemfile, no ephemeral gem)
351
+ docker compose -f docker-compose.ci.yml run --rm rspec
352
+
353
+ # Same specs with decidim-ephemeral_participation (Appraisal `with_ephemeral`)
354
+ docker compose -f docker-compose.ci.yml run --rm -e BUNDLE_GEMFILE=/app/gemfiles/with_ephemeral.gemfile rspec
105
355
  ```
106
- docker-compose up
356
+
357
+ ### Advanced — dummy already generated
358
+
359
+ Use these only after `spec/decidim_dummy_app/config/application.rb` exists (`./bin/dev-oidc-up` or `rake test_app`).
360
+
361
+ ```bash
362
+ # Rails only (infra must already be up — e.g. after a partial setup)
363
+ docker compose --profile dev run --rm --service-ports decidim bash -c \
364
+ "cd /home/module/spec/decidim_dummy_app && rm -f tmp/pids/server.pid && bundle exec rails server -b 0.0.0.0 -p 3000"
365
+
366
+ # Specs (from repo root, dummy app Gemfile)
367
+ docker compose --profile dev run --rm decidim bash -c \
368
+ "cd /home/module && BUNDLE_GEMFILE=spec/decidim_dummy_app/Gemfile bundle exec rspec"
107
369
  ```
108
- This will run a `decidim-user_fields` container, which sleeps.
109
- You can run any command you want in the running container, like:
110
370
 
111
- - `docker-compose exec -it decidim-user_fields bundle exec rails db:seed`: seed the database (run on [`localhost:3000`](https://localhost:3000))
112
- - `docker-compose exec -it decidim-user_fields bin/webpack-dev-server`: compile assets and watch for changes
113
- - `docker-compose exec -it decidim-user_fields bin/rails s -b 0.0.0.0`: run rails server in development
114
- - `docker-compose exec -it decidim-user_fields bundle exec rspec /home/decidim/module/spec`: run tests for the module
115
- - `docker-compose exec -it decidim-user_fields bundle exec rubocop -a /home/decidim/module`: correct lint error with rubocop
116
- - `docker-compose exec -it decidim-user_fields bash`: navigate your container in bash
371
+ Regenerate the dummy app when switching `BUNDLE_GEMFILE` (`rake test_app` in that bundle). Default CI has no ephemeral gem; `ruby::rspec-ephemeral` installs `decidim-ephemeral_participation` `v0.0.9`.
372
+
373
+ Useful paths inside the container:
374
+
375
+ | Path | Purpose |
376
+ |------|---------|
377
+ | `/home/module` | This gem (mounted from the repo) |
378
+ | `/home/module/spec/decidim_dummy_app` | Dummy Decidim app used for local OIDC + specs |
117
379
 
118
- While developping locally, you have two environments variables that can help you:
119
- - `ROOT`: the root of the application using the module
120
- - `MODULE_ROOT`: the place where your gem code is.
380
+ Environment variables in the dev image:
121
381
 
382
+ | Variable | Purpose |
383
+ |----------|---------|
384
+ | `DEV_MODULE` | Gem under development (`decidim-user_fields`) |
385
+ | `DECIDIM_VERSION` | Decidim release used by the dummy app |
386
+ | `BUNDLE_GEMFILE` | Bundler gemfile. Empty uses `./Gemfile` (no ephemeral). `gemfiles/with_ephemeral.gemfile` adds `decidim-ephemeral_participation`. |