decidim-toggle 0.1.3 → 0.1.4
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/.gitlab-ci.yml +10 -8
- data/.rspec +1 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/CONTRIBUTING.md +2 -1
- data/Gemfile +13 -10
- data/Gemfile.lock +502 -388
- data/README.md +3 -1
- data/Rakefile +56 -5
- data/app/forms/decidim/toggle/update_authorizations_form.rb +116 -11
- data/app/forms/decidim/toggle/update_file_upload_settings_form.rb +1 -1
- data/app/forms/decidim/toggle/update_locale_form.rb +5 -1
- data/app/forms/decidim/toggle/update_name_form.rb +6 -2
- data/app/forms/decidim/toggle/update_security_form.rb +2 -2
- data/app/helpers/decidim/toggle/system_settings_tab_helper.rb +8 -7
- data/app/packs/src/decidim/toggle/organization_settings_tabs.js +31 -0
- data/app/packs/stylesheets/decidim/toggle/organization_settings.scss +47 -7
- data/app/views/decidim_toggle/system/organizations/_default_form_tab.html.erb +1 -2
- data/app/views/decidim_toggle/system/organizations/_encryption_not_configured_callout.html.erb +1 -0
- data/app/views/decidim_toggle/system/organizations/_settings_tab_active_tab_field.html.erb +1 -0
- data/app/views/decidim_toggle/system/organizations/_settings_tab_submit.html.erb +1 -0
- data/app/views/decidim_toggle/system/organizations/_settings_tabs.html.erb +2 -2
- data/app/views/decidim_toggle/system/organizations/tabs/_authorizations_tab.html.erb +27 -3
- data/app/views/decidim_toggle/system/organizations/tabs/_emails_tab.html.erb +1 -2
- data/app/views/decidim_toggle/system/organizations/tabs/_file_upload_tab.html.erb +1 -2
- data/app/views/decidim_toggle/system/organizations/tabs/_language_tab.html.erb +4 -7
- data/app/views/decidim_toggle/system/organizations/tabs/_omniauth_tab.html.erb +1 -2
- data/app/views/decidim_toggle/system/organizations/tabs/_security_tab.html.erb +1 -3
- data/app/views/layouts/decidim/toggle/_javascript_config.html.erb +1 -0
- data/bin/check +2 -2
- data/bin/ci-setup +24 -0
- data/config/assets.rb +5 -2
- data/config/locales/decidim_toggle_en.yml +5 -0
- data/decidim-toggle.gemspec +1 -1
- data/docker-compose.ci.yml +46 -0
- data/docker-compose.yml +11 -7
- data/lib/decidim/toggle/authorization_workflows.rb +33 -0
- data/lib/decidim/toggle/engine.rb +1 -1
- data/lib/decidim/toggle/field_conditions.rb +35 -0
- data/lib/decidim/toggle/javascript_config.rb +1 -1
- data/lib/decidim/toggle/organization_settings_tabs.rb +5 -6
- data/lib/decidim/toggle/settings_form_builder.rb +126 -22
- data/lib/decidim/toggle/settings_tab_registry.rb +1 -1
- data/lib/decidim/toggle/settings_tabs.rb +4 -5
- data/lib/decidim/toggle/tab_form.rb +1 -0
- data/lib/decidim/toggle/version.rb +1 -1
- data/lib/decidim/toggle.rb +17 -0
- data/package.json +2 -2
- data/spec/commands/decidim/toggle/update_authorizations_command_spec.rb +28 -0
- data/spec/commands/decidim/toggle/update_emails_command_spec.rb +1 -17
- data/spec/commands/decidim/toggle/update_omniauth_command_spec.rb +1 -17
- data/spec/forms/decidim/toggle/update_authorizations_form_spec.rb +87 -0
- data/spec/forms/decidim/toggle/update_omniauth_form_spec.rb +3 -3
- data/spec/lib/decidim/toggle/settings_form_builder_spec.rb +114 -18
- data/spec/requests/decidim_toggle/system/settings_tab_spec.rb +54 -0
- data/website/docs/developer/contribute.md +2 -1
- data/website/docs/developer/view-customization.md +1 -1
- data/website/docs/index.md +1 -1
- data/website/docs/integrate/attributes.md +65 -4
- data/website/docs/integrate/quickstart.md +2 -0
- data/yarn.lock +4 -4
- metadata +8 -4
- /data/{.erb-lint.yml → .erb_lint.yml} +0 -0
data/bin/check
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# RuboCop +
|
|
2
|
+
# RuboCop + erb_lint + RSpec (matches CI ruby::rubocop, ruby::erb, ruby::rspec).
|
|
3
3
|
# Does not run Prettier or Crowdin — see README / CONTRIBUTING "bin/check vs CI".
|
|
4
4
|
set -euo pipefail
|
|
5
5
|
cd "$(dirname "$0")/.."
|
|
6
6
|
unset DATABASE_URL
|
|
7
7
|
export RAILS_ENV=test
|
|
8
8
|
bundle exec rubocop .
|
|
9
|
-
bundle exec
|
|
9
|
+
bundle exec erb_lint --lint-all --enable-all-linters
|
|
10
10
|
bundle exec rspec "$@"
|
data/bin/ci-setup
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Mirrors GitLab CI ruby::rspec before_script. Runs inside ruby:3.4.7.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
cd "$(dirname "$0")/.."
|
|
5
|
+
|
|
6
|
+
git config --global --add safe.directory "$(pwd)" || true
|
|
7
|
+
|
|
8
|
+
: "${NODE_MAJOR:=22}"
|
|
9
|
+
|
|
10
|
+
apt-get update -qq && apt-get install -y ca-certificates curl gnupg wget libvips42
|
|
11
|
+
wget -q -O /tmp/google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
|
12
|
+
apt-get install -y /tmp/google-chrome.deb || (apt-get -f install -y && apt-get install -y /tmp/google-chrome.deb)
|
|
13
|
+
rm -f /tmp/google-chrome.deb
|
|
14
|
+
|
|
15
|
+
mkdir -p /etc/apt/keyrings
|
|
16
|
+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
|
17
|
+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
|
18
|
+
apt-get update && apt-get install -y -qq nodejs
|
|
19
|
+
npm install -g yarn --force
|
|
20
|
+
|
|
21
|
+
gem install bundler
|
|
22
|
+
bundle config set path 'vendor'
|
|
23
|
+
RAILS_ENV=development bundle install -j "$(nproc)"
|
|
24
|
+
bundle exec rake test_app
|
data/config/assets.rb
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
base_path = File.expand_path("..", __dir__)
|
|
4
4
|
|
|
5
|
-
Decidim
|
|
6
|
-
Decidim::Webpacker
|
|
5
|
+
# Decidim 0.29 uses Webpacker; 0.32+ uses Shakapacker.
|
|
6
|
+
registry = defined?(Decidim::Shakapacker) ? Decidim::Shakapacker : Decidim::Webpacker
|
|
7
|
+
|
|
8
|
+
registry.register_path("#{base_path}/app/packs")
|
|
9
|
+
registry.register_entrypoints(
|
|
7
10
|
decidim_toggle: "#{base_path}/app/packs/entrypoints/decidim_toggle.js"
|
|
8
11
|
)
|
|
@@ -24,6 +24,10 @@ en:
|
|
|
24
24
|
authorizations_tab:
|
|
25
25
|
legend: "Verification workflows"
|
|
26
26
|
hint: "Choose which verification methods participants can use in this organization."
|
|
27
|
+
ephemeral_hint: "Optionally pick one ephemerable workflow that allows participation without registering (decidim-ephemeral_participation)."
|
|
28
|
+
workflow: "Workflow"
|
|
29
|
+
enabled: "Enabled"
|
|
30
|
+
ephemeral: "Ephemeral"
|
|
27
31
|
language_tab:
|
|
28
32
|
legend: "Available and default locale"
|
|
29
33
|
locale: "Locale"
|
|
@@ -47,6 +51,7 @@ en:
|
|
|
47
51
|
activemodel:
|
|
48
52
|
attributes:
|
|
49
53
|
organization:
|
|
54
|
+
ephemeral_participation_authorization: "Ephemeral participation authorization"
|
|
50
55
|
helptext:
|
|
51
56
|
"default-src": "Fallback directive used when no other *-src directive matches. Mostly used to set a secure baseline for all resource types. Examples: 'self' https: ; 'none' ; 'self' https: data:"
|
|
52
57
|
"img-src": "Sources allowed to load images (e.g. <img>, favicons, CSS background images). Use for image CDNs or when you need data/blob URIs. Examples: 'self' https: data: blob: ; https://*.fbcdn.net https://*.instagram.com"
|
data/decidim-toggle.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.email = ["hadrien@octree.ch"]
|
|
11
11
|
s.license = "AGPL-3.0"
|
|
12
12
|
s.homepage = "https://octree-gva.github.io/decidim-toggle"
|
|
13
|
-
s.required_ruby_version = ">= 3.2"
|
|
13
|
+
s.required_ruby_version = ">= 3.2.2"
|
|
14
14
|
s.name = "decidim-toggle"
|
|
15
15
|
s.summary = "Feature toggle for Decidim system administration"
|
|
16
16
|
s.description = "Tabbed System organization settings (OmniAuth, emails, language, security, other) " \
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Reproduces GitLab CI ruby::rspec: ruby:3.4.7 + postgres:17 + redis.
|
|
2
|
+
# Usage:
|
|
3
|
+
# docker compose -f docker-compose.ci.yml run --rm rspec
|
|
4
|
+
# docker compose -f docker-compose.ci.yml run --rm rspec bundle exec rspec spec/lib
|
|
5
|
+
services:
|
|
6
|
+
postgres:
|
|
7
|
+
image: postgres:17
|
|
8
|
+
environment:
|
|
9
|
+
POSTGRES_DB: decidim_test
|
|
10
|
+
POSTGRES_USER: decidim
|
|
11
|
+
POSTGRES_PASSWORD: "TEST-insecure_password"
|
|
12
|
+
healthcheck:
|
|
13
|
+
test: ["CMD-SHELL", "pg_isready -U decidim -d decidim_test"]
|
|
14
|
+
interval: 2s
|
|
15
|
+
timeout: 5s
|
|
16
|
+
retries: 10
|
|
17
|
+
|
|
18
|
+
redis:
|
|
19
|
+
image: redis:latest
|
|
20
|
+
|
|
21
|
+
rspec:
|
|
22
|
+
image: ruby:3.4.7
|
|
23
|
+
working_dir: /app
|
|
24
|
+
volumes:
|
|
25
|
+
- .:/app
|
|
26
|
+
shm_size: "2gb"
|
|
27
|
+
environment:
|
|
28
|
+
DATABASE_HOST: postgres
|
|
29
|
+
DATABASE_PASSWORD: "TEST-insecure_password"
|
|
30
|
+
DATABASE_USERNAME: decidim
|
|
31
|
+
DISABLED_DOCKER_COMPOSE: "true"
|
|
32
|
+
TRAEFIK_REDIS_URL: "redis://redis:6379/1"
|
|
33
|
+
NODE_MAJOR: "22"
|
|
34
|
+
SIMPLECOV: "1"
|
|
35
|
+
CI: "1"
|
|
36
|
+
DISABLE_SPRING: "1"
|
|
37
|
+
depends_on:
|
|
38
|
+
postgres:
|
|
39
|
+
condition: service_healthy
|
|
40
|
+
redis:
|
|
41
|
+
condition: service_started
|
|
42
|
+
entrypoint: []
|
|
43
|
+
command:
|
|
44
|
+
- /bin/bash
|
|
45
|
+
- -c
|
|
46
|
+
- bin/ci-setup && unset DATABASE_URL && RAILS_ENV=test bundle exec rspec
|
data/docker-compose.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
services:
|
|
2
2
|
toggle:
|
|
3
3
|
command: bash -c "sleep infinity"
|
|
4
|
-
image: octree/decidim-dev:0.
|
|
4
|
+
image: octree/decidim-dev:0.32
|
|
5
5
|
entrypoint: ""
|
|
6
6
|
working_dir: /home/module
|
|
7
7
|
volumes:
|
|
@@ -10,8 +10,8 @@ services:
|
|
|
10
10
|
- node_modules:/home/decidim/node_modules
|
|
11
11
|
environment:
|
|
12
12
|
- PORT=3000
|
|
13
|
-
- DATABASE_URL=postgresql://decidim:pleaseChangeMe@
|
|
14
|
-
- DATABASE_HOST=
|
|
13
|
+
- DATABASE_URL=postgresql://decidim:pleaseChangeMe@toggledb:5432/decidim
|
|
14
|
+
- DATABASE_HOST=toggledb
|
|
15
15
|
- DATABASE_USERNAME=decidim
|
|
16
16
|
- DATABASE_PASSWORD=pleaseChangeMe
|
|
17
17
|
- DEV_MODULE=decidim-toggle
|
|
@@ -20,13 +20,12 @@ services:
|
|
|
20
20
|
- DECIDIM_FORCE_SSL=false
|
|
21
21
|
- RAILS_FORCE_SSL=false
|
|
22
22
|
depends_on:
|
|
23
|
-
|
|
23
|
+
toggledb:
|
|
24
|
+
condition: service_healthy
|
|
24
25
|
ports:
|
|
25
26
|
- 3000:3000
|
|
26
|
-
links:
|
|
27
|
-
- toggle_db
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
toggledb:
|
|
30
29
|
image: postgres:17
|
|
31
30
|
volumes:
|
|
32
31
|
- toggle-pg-data:/var/lib/postgresql/data
|
|
@@ -34,6 +33,11 @@ services:
|
|
|
34
33
|
- POSTGRES_DATABASE=decidim
|
|
35
34
|
- POSTGRES_USER=decidim
|
|
36
35
|
- POSTGRES_PASSWORD=pleaseChangeMe
|
|
36
|
+
healthcheck:
|
|
37
|
+
test: ["CMD-SHELL", "pg_isready -U decidim"]
|
|
38
|
+
interval: 10s
|
|
39
|
+
timeout: 5s
|
|
40
|
+
retries: 5
|
|
37
41
|
|
|
38
42
|
volumes:
|
|
39
43
|
node_modules: {}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Toggle
|
|
5
|
+
# Lets other gems hide verification workflows on the System authorizations tab
|
|
6
|
+
# without prepending {UpdateAuthorizationsForm}.
|
|
7
|
+
module AuthorizationWorkflows
|
|
8
|
+
class << self
|
|
9
|
+
def filters
|
|
10
|
+
@filters ||= []
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add_filter(&block)
|
|
14
|
+
filters << block
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def reset_filters!
|
|
18
|
+
@filters = []
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def for(organization)
|
|
22
|
+
Decidim.authorization_workflows.select do |workflow|
|
|
23
|
+
allowed?(workflow, organization)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def allowed?(workflow, organization)
|
|
28
|
+
filters.all? { |filter| filter.call(workflow, organization) }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -50,7 +50,7 @@ module Decidim
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
config.to_prepare do
|
|
53
|
-
Decidim::Toggle::ExposeAttributesToJsValidator.validate! if Rails.env.
|
|
53
|
+
Decidim::Toggle::ExposeAttributesToJsValidator.validate! if Rails.env.local?
|
|
54
54
|
|
|
55
55
|
ActiveSupport.on_load(:action_view) do
|
|
56
56
|
include Decidim::Toggle::SystemSettingsTabHelper
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Toggle
|
|
5
|
+
# Declare trivial field disable rules on settings tab forms.
|
|
6
|
+
#
|
|
7
|
+
# class MyForm < Decidim::Form
|
|
8
|
+
# include Decidim::Toggle::FieldConditions
|
|
9
|
+
#
|
|
10
|
+
# attribute :enabled, :boolean
|
|
11
|
+
# attribute :api_key, :string
|
|
12
|
+
#
|
|
13
|
+
# disable :api_key, if_unchecked: :enabled
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# When +enabled+ is unchecked, +api_key+ is disabled (server-side on render,
|
|
17
|
+
# and live in the browser via data attributes).
|
|
18
|
+
module FieldConditions
|
|
19
|
+
extend ActiveSupport::Concern
|
|
20
|
+
|
|
21
|
+
class_methods do
|
|
22
|
+
def field_disable_conditions
|
|
23
|
+
@field_disable_conditions ||= {}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Disables +attribute+ while the boolean +if_unchecked+ attribute is false.
|
|
27
|
+
def disable(attribute, if_unchecked:)
|
|
28
|
+
raise ArgumentError, "disable requires if_unchecked:" if if_unchecked.blank?
|
|
29
|
+
|
|
30
|
+
field_disable_conditions[attribute.to_sym] = { if_unchecked: if_unchecked.to_sym }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -75,7 +75,7 @@ module Decidim
|
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def warn_unsupported_type(value)
|
|
78
|
-
return unless Rails.env.
|
|
78
|
+
return unless Rails.env.local?
|
|
79
79
|
|
|
80
80
|
Rails.logger.warn(
|
|
81
81
|
"[decidim-toggle] Skipping unsupported JavaScript config value #{value.class}"
|
|
@@ -5,12 +5,11 @@ module Decidim
|
|
|
5
5
|
# Registers default system organization settings tabs.
|
|
6
6
|
#
|
|
7
7
|
# Extension contract: the authorizations tab uses the stable identifier
|
|
8
|
-
# +:authorizations
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
# wins; see {Decidim::Toggle::SettingsTabRegistry#register_form_tab}.
|
|
8
|
+
# +:authorizations+. Vanilla Decidim persists a string array of workflow names.
|
|
9
|
+
# When +decidim-ephemeral_participation+ is loaded, the tab shows enabled
|
|
10
|
+
# checkboxes plus one ephemeral radio per ephemerable workflow, and persists
|
|
11
|
+
# a Hash with +allow_ephemeral_participation+.
|
|
12
|
+
# Another engine may still +remove_tab(:authorizations)+ then +add_tab+ to replace it.
|
|
14
13
|
class OrganizationSettingsTabs
|
|
15
14
|
def self.register!
|
|
16
15
|
scope = "decidim_toggle.system.organizations.settings_tabs"
|
|
@@ -4,6 +4,8 @@ module Decidim
|
|
|
4
4
|
module Toggle
|
|
5
5
|
# Form builder for add_tab form tabs. Renders all form attributes via #all_fields.
|
|
6
6
|
# Form classes can define class method collection_for_<attribute> to return [[value, label], ...] for collection inputs.
|
|
7
|
+
# Use select_for_<attribute> for a dropdown, cols_for_<attribute> for text areas,
|
|
8
|
+
# and FieldConditions#disable for "disabled when unchecked" rules.
|
|
7
9
|
# Loaded from the engine after +require "decidim/core"+ so +Decidim::FormBuilder+ autoload works.
|
|
8
10
|
class SettingsFormBuilder < Decidim::FormBuilder
|
|
9
11
|
CALLOUT_CLASS_BY_TYPE = {
|
|
@@ -12,6 +14,8 @@ module Decidim
|
|
|
12
14
|
danger: "alert"
|
|
13
15
|
}.freeze
|
|
14
16
|
|
|
17
|
+
OPTION_LABEL_CLASS = "form__wrapper-checkbox-label"
|
|
18
|
+
|
|
15
19
|
def informative_callouts
|
|
16
20
|
return "".html_safe unless object.class.include?(InformativeCallouts)
|
|
17
21
|
|
|
@@ -31,7 +35,7 @@ module Decidim
|
|
|
31
35
|
|
|
32
36
|
def all_fields
|
|
33
37
|
fields = attribute_names.map do |name|
|
|
34
|
-
|
|
38
|
+
field_wrapper(name, input_field(name))
|
|
35
39
|
end
|
|
36
40
|
safe_join(fields)
|
|
37
41
|
end
|
|
@@ -42,13 +46,22 @@ module Decidim
|
|
|
42
46
|
fields = names.filter_map do |name|
|
|
43
47
|
next unless object.class.respond_to?(:attribute_types) && object.class.attribute_types.has_key?(name)
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
field_wrapper(name, input_field(name.to_sym))
|
|
46
50
|
end
|
|
47
51
|
safe_join(fields)
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
private
|
|
51
55
|
|
|
56
|
+
def field_wrapper(name, content)
|
|
57
|
+
@template.content_tag(
|
|
58
|
+
:div,
|
|
59
|
+
content,
|
|
60
|
+
class: field_wrapper_classes(name),
|
|
61
|
+
data: field_wrapper_data(name)
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
52
65
|
def input_field(name)
|
|
53
66
|
name = name.to_sym
|
|
54
67
|
input_html =
|
|
@@ -61,8 +74,7 @@ module Decidim
|
|
|
61
74
|
helptext = helptext_for_attribute(name)
|
|
62
75
|
return input_html if helptext.blank?
|
|
63
76
|
|
|
64
|
-
#
|
|
65
|
-
# typically renders the label inside the field HTML returned above).
|
|
77
|
+
# Help text sits under the control (no negative translate — that overlapped selects).
|
|
66
78
|
@template.safe_join(
|
|
67
79
|
[
|
|
68
80
|
input_html,
|
|
@@ -72,28 +84,50 @@ module Decidim
|
|
|
72
84
|
end
|
|
73
85
|
|
|
74
86
|
def build_input_field(name)
|
|
75
|
-
|
|
87
|
+
options = field_html_options_for(name)
|
|
88
|
+
|
|
89
|
+
if (select_collection = select_collection_for(name))
|
|
90
|
+
return select(
|
|
91
|
+
name,
|
|
92
|
+
select_collection.map { |(value, label)| [label, value] },
|
|
93
|
+
{},
|
|
94
|
+
options
|
|
95
|
+
)
|
|
96
|
+
end
|
|
76
97
|
|
|
77
98
|
if (collection = collection_for(name))
|
|
99
|
+
type = attribute_type(name)
|
|
78
100
|
if type == :array
|
|
79
|
-
collection_check_boxes(name, collection, :first, :last) do |b|
|
|
80
|
-
@template.content_tag(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
return collection_check_boxes(name, collection, :first, :last, {}, {}) do |b|
|
|
102
|
+
@template.content_tag(
|
|
103
|
+
:div,
|
|
104
|
+
b.label(for: nil, class: OPTION_LABEL_CLASS) { b.check_box(id: nil) + b.text },
|
|
105
|
+
class: "checkbox-field"
|
|
106
|
+
)
|
|
85
107
|
end
|
|
86
108
|
end
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
else text_field(name, options)
|
|
109
|
+
|
|
110
|
+
return collection_radio_buttons(name, collection, :first, :last, {}, {}) do |b|
|
|
111
|
+
@template.content_tag(
|
|
112
|
+
:div,
|
|
113
|
+
b.label(for: nil, class: OPTION_LABEL_CLASS) { b.radio_button(id: nil) + b.text },
|
|
114
|
+
class: "radio-field"
|
|
115
|
+
)
|
|
95
116
|
end
|
|
96
117
|
end
|
|
118
|
+
|
|
119
|
+
type = attribute_type(name)
|
|
120
|
+
case type
|
|
121
|
+
when :string
|
|
122
|
+
if textarea?(name)
|
|
123
|
+
text_area(name, options.merge(textarea_html_options_for(name)))
|
|
124
|
+
else
|
|
125
|
+
text_field(name, options)
|
|
126
|
+
end
|
|
127
|
+
when :integer then number_field(name, options)
|
|
128
|
+
when :boolean then check_box(name, options)
|
|
129
|
+
else text_field(name, options)
|
|
130
|
+
end
|
|
97
131
|
end
|
|
98
132
|
|
|
99
133
|
def field_html_options_for(name)
|
|
@@ -101,7 +135,39 @@ module Decidim
|
|
|
101
135
|
end
|
|
102
136
|
|
|
103
137
|
def field_wrapper_classes(name)
|
|
104
|
-
|
|
138
|
+
[
|
|
139
|
+
"field",
|
|
140
|
+
"field--#{name.to_s.underscore}",
|
|
141
|
+
field_type_modifier(name),
|
|
142
|
+
("is-disabled" if attribute_disabled?(name))
|
|
143
|
+
].compact.join(" ")
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def field_type_modifier(name)
|
|
147
|
+
return "field--select" if select_collection_for(name)
|
|
148
|
+
return collection_field_modifier(name) if collection_for(name)
|
|
149
|
+
return "field--checkbox" if attribute_type(name) == :boolean
|
|
150
|
+
return "field--textarea" if textarea?(name)
|
|
151
|
+
|
|
152
|
+
"field--text"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Collection checkboxes/radios belong on the wrapper, not inputs
|
|
156
|
+
# (Rails collection_* html_options attach to each input).
|
|
157
|
+
def collection_field_modifier(name)
|
|
158
|
+
attribute_type(name) == :array ? "field--checkboxes" : "field--radios"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def field_wrapper_data(name)
|
|
162
|
+
condition = disable_condition_for(name)
|
|
163
|
+
return {} if condition.blank?
|
|
164
|
+
|
|
165
|
+
controller = condition[:if_unchecked]
|
|
166
|
+
{ disabled_if_unchecked: "#{sanitized_object_name}_#{controller}" }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def sanitized_object_name
|
|
170
|
+
object_name.to_s.gsub(/[\[\]]+/, "_").gsub(/_+\z/, "")
|
|
105
171
|
end
|
|
106
172
|
|
|
107
173
|
def attribute_disabled?(name)
|
|
@@ -111,14 +177,52 @@ module Decidim
|
|
|
111
177
|
|
|
112
178
|
return object.attribute_disabled?(name) if object.respond_to?(:attribute_disabled?)
|
|
113
179
|
|
|
114
|
-
|
|
180
|
+
condition_disabled?(name)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def condition_disabled?(name)
|
|
184
|
+
condition = disable_condition_for(name)
|
|
185
|
+
return false if condition.blank?
|
|
186
|
+
|
|
187
|
+
controller = condition[:if_unchecked]
|
|
188
|
+
return false unless object.respond_to?(controller)
|
|
189
|
+
|
|
190
|
+
!ActiveModel::Type::Boolean.new.cast(object.public_send(controller))
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def disable_condition_for(name)
|
|
194
|
+
return nil unless object.class.respond_to?(:field_disable_conditions)
|
|
195
|
+
|
|
196
|
+
object.class.field_disable_conditions[name.to_sym]
|
|
115
197
|
end
|
|
116
198
|
|
|
117
199
|
def collection_for(attribute)
|
|
118
|
-
|
|
200
|
+
invoke_collection_method(:"collection_for_#{attribute}")
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def select_collection_for(attribute)
|
|
204
|
+
invoke_collection_method(:"select_for_#{attribute}")
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def invoke_collection_method(method)
|
|
208
|
+
return object.public_send(method) if object.respond_to?(method)
|
|
209
|
+
|
|
119
210
|
object.class.respond_to?(method) ? object.class.public_send(method) : nil
|
|
120
211
|
end
|
|
121
212
|
|
|
213
|
+
def textarea?(name)
|
|
214
|
+
return true if name.to_s == "secondary_hosts"
|
|
215
|
+
|
|
216
|
+
object.class.respond_to?(:"cols_for_#{name}")
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def textarea_html_options_for(name)
|
|
220
|
+
cols_method = :"cols_for_#{name}"
|
|
221
|
+
return {} unless object.class.respond_to?(cols_method)
|
|
222
|
+
|
|
223
|
+
{ cols: object.class.public_send(cols_method) }
|
|
224
|
+
end
|
|
225
|
+
|
|
122
226
|
def attribute_names
|
|
123
227
|
return [] unless object.class.respond_to?(:attribute_types)
|
|
124
228
|
|
|
@@ -98,7 +98,7 @@ module Decidim
|
|
|
98
98
|
private
|
|
99
99
|
|
|
100
100
|
def duplicate_tab_registration?(tid, form_class, command_class)
|
|
101
|
-
return false unless Rails.env.
|
|
101
|
+
return false unless Rails.env.local?
|
|
102
102
|
return false unless @form_tabs[tid]
|
|
103
103
|
|
|
104
104
|
existing = @form_tabs[tid]
|
|
@@ -12,11 +12,11 @@ module Decidim
|
|
|
12
12
|
@removed_items = []
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def build_for(context, **
|
|
15
|
+
def build_for(context, **)
|
|
16
16
|
raise "Settings tabs #{@name} is not registered" if registry.blank?
|
|
17
17
|
|
|
18
18
|
registry.configurations.each do |configuration|
|
|
19
|
-
context.instance_exec(self,
|
|
19
|
+
context.instance_exec(self, **, &configuration)
|
|
20
20
|
end
|
|
21
21
|
registry.mark_configurations_applied!
|
|
22
22
|
end
|
|
@@ -26,10 +26,9 @@ module Decidim
|
|
|
26
26
|
# @param label [String] Tab button label
|
|
27
27
|
# @param form [Class] Decidim::Form subclass (must respond to .from_model(organization))
|
|
28
28
|
# @param command [Class] Decidim::Command that receives (organization, form)
|
|
29
|
-
# @param options [Hash] :position, :if, :open,
|
|
29
|
+
# @param options [Hash] :position, :if, :open, :module_name,
|
|
30
30
|
# :form_layout_partial (optional full tab layout partial)
|
|
31
|
-
def add_tab(identifier, label, form:, **options)
|
|
32
|
-
command = options.fetch(:command)
|
|
31
|
+
def add_tab(identifier, label, form:, command:, **options)
|
|
33
32
|
options = { position: (1 + @items.length) }.merge(options)
|
|
34
33
|
|
|
35
34
|
module_name = options[:module_name]
|
data/lib/decidim/toggle.rb
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
require "decidim/toggle/version"
|
|
4
4
|
require "decidim/toggle/gem_registry"
|
|
5
|
+
require "decidim/toggle/authorization_workflows"
|
|
5
6
|
require "decidim/toggle/settings_tab_registry"
|
|
6
7
|
require "decidim/toggle/settings_tab_item"
|
|
7
8
|
require "decidim/toggle/settings_tabs"
|
|
8
9
|
require "decidim/toggle/module_config"
|
|
9
10
|
require "decidim/toggle/informative_callouts"
|
|
11
|
+
require "decidim/toggle/field_conditions"
|
|
10
12
|
require "decidim/toggle/module_config_i18n"
|
|
11
13
|
require "decidim/toggle/module_config_form"
|
|
12
14
|
require "decidim/toggle/tab_form"
|
|
@@ -20,12 +22,27 @@ module Decidim
|
|
|
20
22
|
SettingsTabRegistry.register(name, &)
|
|
21
23
|
end
|
|
22
24
|
|
|
25
|
+
def self.filter_authorization_workflows(&)
|
|
26
|
+
AuthorizationWorkflows.add_filter(&)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.authorization_workflows_for(organization)
|
|
30
|
+
AuthorizationWorkflows.for(organization)
|
|
31
|
+
end
|
|
32
|
+
|
|
23
33
|
# @param gem_name [String, Symbol] Bundler gem name (e.g. +"decidim-space_page"+)
|
|
24
34
|
# @return [Boolean]
|
|
25
35
|
def self.gem_present?(gem_name)
|
|
26
36
|
GemRegistry.present?(gem_name)
|
|
27
37
|
end
|
|
28
38
|
|
|
39
|
+
# True when +decidim-ephemeral_participation+ is in the bundle.
|
|
40
|
+
# Prefer Bundler over +const_defined?+ (Zeitwerk may not have defined the
|
|
41
|
+
# constant yet when System settings render).
|
|
42
|
+
def self.ephemeral_participation?
|
|
43
|
+
gem_present?("decidim-ephemeral_participation")
|
|
44
|
+
end
|
|
45
|
+
|
|
29
46
|
# @param organization [Decidim::Organization, nil]
|
|
30
47
|
# @param registry_name [Symbol] settings tab registry (default +:organization_settings+)
|
|
31
48
|
# @return [Hash{String => Object}] flat keys like +"decidim_geo.enabled"+
|
data/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decidim-toggle",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "Decidim system settings tabbed UI",
|
|
6
6
|
"devDependencies": {
|
|
7
|
-
"@decidim/prettier-config": "0.
|
|
7
|
+
"@decidim/prettier-config": "0.32",
|
|
8
8
|
"prettier": "^2.3.2"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
@@ -36,6 +36,34 @@ module Decidim
|
|
|
36
36
|
expect(outcomes).to eq([:invalid])
|
|
37
37
|
expect(organization.reload.available_authorizations).to eq([])
|
|
38
38
|
end
|
|
39
|
+
|
|
40
|
+
context "when ephemeral participation is loaded" do
|
|
41
|
+
before do
|
|
42
|
+
allow(Decidim::Toggle).to receive(:ephemeral_participation?).and_return(true)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "persists the Hash shape with allow_ephemeral_participation" do
|
|
46
|
+
form = UpdateAuthorizationsForm.from_params(
|
|
47
|
+
organization: {
|
|
48
|
+
available_authorizations: %w(dummy_authorization_handler),
|
|
49
|
+
ephemeral_participation_authorization: "dummy_authorization_handler"
|
|
50
|
+
}
|
|
51
|
+
).with_context(current_organization: organization)
|
|
52
|
+
|
|
53
|
+
allow(organization).to receive(:available_authorizations=)
|
|
54
|
+
allow(organization).to receive(:save!).and_return(true)
|
|
55
|
+
|
|
56
|
+
outcomes = []
|
|
57
|
+
cmd = described_class.new(organization, form)
|
|
58
|
+
cmd.on(:ok) { outcomes << :ok }
|
|
59
|
+
cmd.call
|
|
60
|
+
|
|
61
|
+
expect(outcomes).to eq([:ok])
|
|
62
|
+
expect(organization).to have_received(:available_authorizations=).with(
|
|
63
|
+
"dummy_authorization_handler" => { "allow_ephemeral_participation" => true }
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
39
67
|
end
|
|
40
68
|
end
|
|
41
69
|
end
|