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
|
@@ -50,23 +50,7 @@ module Decidim
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "broadcasts invalid when saving fails" do
|
|
53
|
-
|
|
54
|
-
invalid_record_class = Class.new do
|
|
55
|
-
def initialize(record_errors)
|
|
56
|
-
@errors = record_errors
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def errors
|
|
60
|
-
@errors
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def self.i18n_scope
|
|
64
|
-
"fake_scope"
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
invalid_record = invalid_record_class.new(errors)
|
|
69
|
-
allow(organization).to receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(invalid_record))
|
|
53
|
+
allow(organization).to receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(create(:organization)))
|
|
70
54
|
|
|
71
55
|
form = instance_double(UpdateEmailsForm, invalid?: false, encrypted_smtp_settings: { "host" => "smtp.example" })
|
|
72
56
|
|
|
@@ -47,23 +47,7 @@ module Decidim
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
it "broadcasts invalid when saving fails" do
|
|
50
|
-
|
|
51
|
-
invalid_record_class = Class.new do
|
|
52
|
-
def initialize(record_errors)
|
|
53
|
-
@errors = record_errors
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def errors
|
|
57
|
-
@errors
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def self.i18n_scope
|
|
61
|
-
"fake_scope"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
invalid_record = invalid_record_class.new(errors)
|
|
66
|
-
allow(organization).to receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(invalid_record))
|
|
50
|
+
allow(organization).to receive(:save!).and_raise(ActiveRecord::RecordInvalid.new(create(:organization)))
|
|
67
51
|
|
|
68
52
|
form = instance_double(UpdateOmniauthForm, invalid?: false, encrypted_omniauth_settings: { "foo" => "bar" })
|
|
69
53
|
|
|
@@ -15,6 +15,31 @@ module Decidim
|
|
|
15
15
|
|
|
16
16
|
expect(form.available_authorizations).to eq(%w(dummy_authorization_handler))
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
context "when ephemeral participation is loaded" do
|
|
20
|
+
before do
|
|
21
|
+
allow(Decidim::Toggle).to receive(:ephemeral_participation?).and_return(true)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "loads enabled names and the ephemeral workflow from a Hash" do
|
|
25
|
+
org = create(:organization, available_authorizations: [])
|
|
26
|
+
allow(org).to receive(:read_attribute).and_call_original
|
|
27
|
+
allow(org).to receive(:read_attribute).with(:available_authorizations).and_return(
|
|
28
|
+
{
|
|
29
|
+
"dummy_authorization_handler" => { "allow_ephemeral_participation" => true },
|
|
30
|
+
"another_dummy_authorization_handler" => { "allow_ephemeral_participation" => false }
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
form = described_class.from_model(org)
|
|
35
|
+
|
|
36
|
+
expect(form.available_authorizations).to contain_exactly(
|
|
37
|
+
"dummy_authorization_handler",
|
|
38
|
+
"another_dummy_authorization_handler"
|
|
39
|
+
)
|
|
40
|
+
expect(form.ephemeral_participation_authorization).to eq("dummy_authorization_handler")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
18
43
|
end
|
|
19
44
|
|
|
20
45
|
describe ".from_params" do
|
|
@@ -25,6 +50,50 @@ module Decidim
|
|
|
25
50
|
end
|
|
26
51
|
end
|
|
27
52
|
|
|
53
|
+
describe "#clean_available_authorizations" do
|
|
54
|
+
it "returns a string array in vanilla mode" do
|
|
55
|
+
form = described_class.from_params(
|
|
56
|
+
organization: { available_authorizations: %w(dummy_authorization_handler) }
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
expect(form.clean_available_authorizations).to eq(%w(dummy_authorization_handler))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "when ephemeral participation is loaded" do
|
|
63
|
+
before do
|
|
64
|
+
allow(Decidim::Toggle).to receive(:ephemeral_participation?).and_return(true)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "returns a Hash with the ephemeral flag" do
|
|
68
|
+
form = described_class.from_params(
|
|
69
|
+
organization: {
|
|
70
|
+
available_authorizations: %w(dummy_authorization_handler another_dummy_authorization_handler),
|
|
71
|
+
ephemeral_participation_authorization: "dummy_authorization_handler"
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
expect(form.clean_available_authorizations).to eq(
|
|
76
|
+
"dummy_authorization_handler" => { "allow_ephemeral_participation" => true },
|
|
77
|
+
"another_dummy_authorization_handler" => { "allow_ephemeral_participation" => false }
|
|
78
|
+
)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "#collection_for_available_authorizations" do
|
|
84
|
+
after { Decidim::Toggle::AuthorizationWorkflows.reset_filters! }
|
|
85
|
+
|
|
86
|
+
it "hides workflows rejected by a registered filter" do
|
|
87
|
+
Decidim::Toggle.filter_authorization_workflows do |workflow, _organization|
|
|
88
|
+
workflow.name != "dummy_authorization_handler"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
names = described_class.from_model(organization).collection_for_available_authorizations.map(&:first)
|
|
92
|
+
|
|
93
|
+
expect(names).not_to include("dummy_authorization_handler")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
28
97
|
describe "validations" do
|
|
29
98
|
it "rejects authorization names that are not registered workflows" do
|
|
30
99
|
form = described_class.from_params(
|
|
@@ -34,6 +103,24 @@ module Decidim
|
|
|
34
103
|
expect(form).not_to be_valid
|
|
35
104
|
expect(form.errors[:available_authorizations]).to be_present
|
|
36
105
|
end
|
|
106
|
+
|
|
107
|
+
context "when ephemeral participation is loaded" do
|
|
108
|
+
before do
|
|
109
|
+
allow(Decidim::Toggle).to receive(:ephemeral_participation?).and_return(true)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "rejects an ephemeral workflow that is not enabled" do
|
|
113
|
+
form = described_class.from_params(
|
|
114
|
+
organization: {
|
|
115
|
+
available_authorizations: %w(dummy_authorization_handler),
|
|
116
|
+
ephemeral_participation_authorization: "another_dummy_authorization_handler"
|
|
117
|
+
}
|
|
118
|
+
).with_context(current_organization: organization)
|
|
119
|
+
|
|
120
|
+
expect(form).not_to be_valid
|
|
121
|
+
expect(form.errors[:ephemeral_participation_authorization]).to be_present
|
|
122
|
+
end
|
|
123
|
+
end
|
|
37
124
|
end
|
|
38
125
|
end
|
|
39
126
|
end
|
|
@@ -16,11 +16,11 @@ module Decidim
|
|
|
16
16
|
|
|
17
17
|
it "builds omniauth encrypted settings from params[:organization]" do
|
|
18
18
|
provider = Decidim::OmniauthProvider.available.keys.first
|
|
19
|
-
|
|
19
|
+
omniauth_settings = Decidim.omniauth_providers[provider] || {}
|
|
20
20
|
|
|
21
21
|
# Pick the first setting other than :enabled. For `developer` this is typically :icon.
|
|
22
|
-
setting_key = (
|
|
23
|
-
skip "No omniauth provider settings found
|
|
22
|
+
setting_key = (omniauth_settings.keys.map(&:to_sym) - [:enabled]).first
|
|
23
|
+
skip "No omniauth provider settings found" if provider.blank? || setting_key.blank?
|
|
24
24
|
|
|
25
25
|
params = {
|
|
26
26
|
organization: {
|
|
@@ -7,13 +7,15 @@ module Decidim
|
|
|
7
7
|
describe SettingsFormBuilder do
|
|
8
8
|
include ActionView::TestCase::Behavior
|
|
9
9
|
|
|
10
|
+
def build_builder(form)
|
|
11
|
+
template = ActionView::Base.with_empty_template_cache.new(ActionView::LookupContext.new([]), {}, nil)
|
|
12
|
+
described_class.new(:organization, form, template, {})
|
|
13
|
+
end
|
|
14
|
+
|
|
10
15
|
it "renders fields_for_names subset" do
|
|
11
16
|
organization = create(:organization)
|
|
12
17
|
form = UpdateLocaleForm.from_model(organization)
|
|
13
|
-
|
|
14
|
-
builder = described_class.new(:organization, form, template, {})
|
|
15
|
-
|
|
16
|
-
html = builder.fields_for_names(:enable_machine_translations)
|
|
18
|
+
html = build_builder(form).fields_for_names(:enable_machine_translations)
|
|
17
19
|
expect(html).to be_present
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -43,8 +45,7 @@ module Decidim
|
|
|
43
45
|
it "renders i18n helptext under the field when present" do
|
|
44
46
|
organization = create(:organization)
|
|
45
47
|
form = UpdateSecurityForm.from_model(organization)
|
|
46
|
-
|
|
47
|
-
builder = described_class.new(:organization, form, template, {})
|
|
48
|
+
builder = build_builder(form)
|
|
48
49
|
|
|
49
50
|
helptext = "Spec helptext for users_registration_mode"
|
|
50
51
|
model_key = form.class.model_name.i18n_key.to_s
|
|
@@ -82,33 +83,128 @@ module Decidim
|
|
|
82
83
|
end
|
|
83
84
|
end
|
|
84
85
|
form = form_class.from_params(organization: { enabled: true, locked: false })
|
|
85
|
-
|
|
86
|
-
builder = described_class.new(:organization, form, template, {})
|
|
87
|
-
|
|
88
|
-
html = builder.all_fields
|
|
86
|
+
html = build_builder(form).all_fields
|
|
89
87
|
expect(html).to include('name="organization[enabled]"')
|
|
90
88
|
expect(html).not_to include('organization[enabled]" disabled')
|
|
91
89
|
expect(html).to include('name="organization[locked]" disabled="disabled"')
|
|
92
|
-
expect(html).to include('class="field is-disabled"')
|
|
90
|
+
expect(html).to include('class="field field--locked field--checkbox is-disabled"')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "disables fields with disable if_unchecked and exposes data for JS" do
|
|
94
|
+
form_class = Class.new(Decidim::Form) do
|
|
95
|
+
include FieldConditions
|
|
96
|
+
|
|
97
|
+
attribute :enabled, :boolean
|
|
98
|
+
attribute :api_key, :string
|
|
99
|
+
|
|
100
|
+
disable :api_key, if_unchecked: :enabled
|
|
101
|
+
end
|
|
102
|
+
form = form_class.from_params(organization: { enabled: false, api_key: "secret" })
|
|
103
|
+
html = build_builder(form).all_fields
|
|
104
|
+
|
|
105
|
+
expect(html).to include('name="organization[api_key]"')
|
|
106
|
+
expect(html).to include('disabled="disabled"')
|
|
107
|
+
expect(html).to include('data-disabled-if-unchecked="organization_enabled"')
|
|
108
|
+
expect(html).to include('class="field field--api_key field--text is-disabled"')
|
|
93
109
|
end
|
|
94
110
|
|
|
95
111
|
it "renders boolean fields, text areas, and collection inputs" do
|
|
96
112
|
organization = create(:organization, secondary_hosts: %w(extra.example.org))
|
|
97
|
-
template = ActionView::Base.with_empty_template_cache.new(ActionView::LookupContext.new([]), {}, nil)
|
|
98
113
|
|
|
99
114
|
security_form = UpdateSecurityForm.from_model(organization)
|
|
100
|
-
security_builder =
|
|
115
|
+
security_builder = build_builder(security_form)
|
|
101
116
|
security_html = security_builder.all_fields
|
|
102
117
|
expect(security_html).to include('type="checkbox"')
|
|
103
|
-
|
|
118
|
+
select_html = security_builder.fields_for_names(:users_registration_mode)
|
|
119
|
+
expect(select_html).to include("<select")
|
|
120
|
+
expect(select_html).to include('name="organization[users_registration_mode]"')
|
|
121
|
+
expect(select_html).not_to include('type="radio"')
|
|
104
122
|
|
|
105
123
|
name_form = UpdateNameForm.from_model(organization)
|
|
106
|
-
|
|
107
|
-
expect(
|
|
124
|
+
name_html = build_builder(name_form).all_fields
|
|
125
|
+
expect(name_html).to include("extra.example.org")
|
|
126
|
+
expect(name_html).to include('cols="55"')
|
|
108
127
|
|
|
109
128
|
authorizations_form = UpdateAuthorizationsForm.from_model(organization)
|
|
110
|
-
|
|
111
|
-
|
|
129
|
+
expect(build_builder(authorizations_form).all_fields).to include('type="checkbox"')
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "prefers instance collection methods over class methods" do
|
|
133
|
+
form_class = Class.new(Decidim::Form) do
|
|
134
|
+
attribute :tags, [String]
|
|
135
|
+
|
|
136
|
+
def self.collection_for_tags
|
|
137
|
+
[%w(class ClassLabel)]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def collection_for_tags
|
|
141
|
+
[%w(instance InstanceLabel)]
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
html = build_builder(form_class.from_params(organization: { tags: ["instance"] })).all_fields
|
|
145
|
+
|
|
146
|
+
expect(html).to include("InstanceLabel")
|
|
147
|
+
expect(html).not_to include("ClassLabel")
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "renders select_for collections as select dropdowns" do
|
|
151
|
+
form_class = Class.new(Decidim::Form) do
|
|
152
|
+
attribute :mode, :string
|
|
153
|
+
|
|
154
|
+
def self.select_for_mode
|
|
155
|
+
[%w(live Live), %w(draft Draft)]
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
form = form_class.from_params(organization: { mode: "live" })
|
|
159
|
+
html = build_builder(form).all_fields
|
|
160
|
+
|
|
161
|
+
expect(html).to include("<select")
|
|
162
|
+
expect(html).to include("Live")
|
|
163
|
+
expect(html).to include("Draft")
|
|
164
|
+
expect(html).not_to include('type="radio"')
|
|
165
|
+
expect(html).to include('class="field field--mode field--select"')
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "puts field--radios / field--checkboxes on the wrapper, not inputs" do
|
|
169
|
+
radio_form_class = Class.new(Decidim::Form) do
|
|
170
|
+
attribute :priority, :string
|
|
171
|
+
|
|
172
|
+
def self.collection_for_priority
|
|
173
|
+
[%w(original Original), %w(translation Translation)]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
radio_html = build_builder(radio_form_class.from_params(organization: { priority: "original" })).all_fields
|
|
177
|
+
expect(radio_html).to include('class="field field--priority field--radios"')
|
|
178
|
+
expect(radio_html).to include('class="radio-field"')
|
|
179
|
+
expect(radio_html).not_to match(/<input[^>]*class="[^"]*field--radios/)
|
|
180
|
+
|
|
181
|
+
checkbox_form_class = Class.new(Decidim::Form) do
|
|
182
|
+
attribute :tags, [String]
|
|
183
|
+
|
|
184
|
+
def self.collection_for_tags
|
|
185
|
+
[%w(a A), %w(b B)]
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
checkbox_html = build_builder(checkbox_form_class.from_params(organization: { tags: ["a"] })).all_fields
|
|
189
|
+
expect(checkbox_html).to include('class="field field--tags field--checkboxes"')
|
|
190
|
+
expect(checkbox_html).to include('class="checkbox-field"')
|
|
191
|
+
expect(checkbox_html).not_to match(/<input[^>]*class="[^"]*field--checkboxes/)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "applies cols_for as textarea cols" do
|
|
195
|
+
form_class = Class.new(Decidim::Form) do
|
|
196
|
+
attribute :notes, :string
|
|
197
|
+
|
|
198
|
+
def self.cols_for_notes
|
|
199
|
+
40
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
form = form_class.from_params(organization: { notes: "hello" })
|
|
203
|
+
html = build_builder(form).all_fields
|
|
204
|
+
|
|
205
|
+
expect(html).to include("<textarea")
|
|
206
|
+
expect(html).to include('cols="40"')
|
|
207
|
+
expect(html).to include('class="field field--notes field--textarea"')
|
|
112
208
|
end
|
|
113
209
|
end
|
|
114
210
|
end
|
|
@@ -65,6 +65,60 @@ describe "DecidimToggle::System::SettingsTabController" do
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
describe "GET system organization edit authorizations tab" do
|
|
69
|
+
it "renders ephemeral radios when the gem is present" do
|
|
70
|
+
allow(Decidim::Toggle).to receive(:ephemeral_participation?).and_return(true)
|
|
71
|
+
|
|
72
|
+
get decidim_system.edit_organization_path(organization)
|
|
73
|
+
|
|
74
|
+
expect(response).to have_http_status(:ok)
|
|
75
|
+
panel = Nokogiri::HTML(response.body).at_css("#settings_tab_form_authorizations") ||
|
|
76
|
+
Nokogiri::HTML(response.body).at_css("#panel-toggle-authorizations")
|
|
77
|
+
expect(panel).to be_present
|
|
78
|
+
html = panel.to_html
|
|
79
|
+
expect(html).to include("Workflow")
|
|
80
|
+
expect(html).to include("Enabled")
|
|
81
|
+
expect(html).to include("Ephemeral")
|
|
82
|
+
expect(html).to include('name="organization[ephemeral_participation_authorization]"')
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "renders only workflows from the form collection" do
|
|
86
|
+
allow(Decidim::Toggle).to receive(:ephemeral_participation?).and_return(true)
|
|
87
|
+
workflow = Decidim::Verifications.find_workflow_manifest(:dummy_authorization_handler)
|
|
88
|
+
allow(workflow).to receive(:description).and_return("Only dummy")
|
|
89
|
+
allow(Decidim::Toggle).to receive(:authorization_workflows_for).and_return([workflow])
|
|
90
|
+
|
|
91
|
+
get decidim_system.edit_organization_path(organization)
|
|
92
|
+
|
|
93
|
+
panel = Nokogiri::HTML(response.body).at_css("#settings_tab_form_authorizations") ||
|
|
94
|
+
Nokogiri::HTML(response.body).at_css("#panel-toggle-authorizations")
|
|
95
|
+
html = panel.to_html
|
|
96
|
+
expect(html).to include("Only dummy")
|
|
97
|
+
expect(html).to include('value="dummy_authorization_handler"')
|
|
98
|
+
expect(html).not_to include("another_dummy_authorization_handler")
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe "PATCH authorizations tab" do
|
|
103
|
+
let(:path) { "/decidim_toggle/system/organizations/#{organization.id}/settings_tab/authorizations" }
|
|
104
|
+
let(:update_params) do
|
|
105
|
+
{
|
|
106
|
+
organization: {
|
|
107
|
+
available_authorizations: %w(dummy_authorization_handler),
|
|
108
|
+
ephemeral_participation_authorization: "dummy_authorization_handler"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "persists handler names as a string array" do
|
|
114
|
+
patch path, params: update_params
|
|
115
|
+
|
|
116
|
+
expect(response).to redirect_to(decidim_system.edit_organization_path(organization))
|
|
117
|
+
expect(flash[:notice]).to eq(I18n.t("decidim_toggle.system.organizations.form_tab.success"))
|
|
118
|
+
expect(organization.reload.available_authorizations).to eq(%w(dummy_authorization_handler))
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
68
122
|
describe "PATCH name tab" do
|
|
69
123
|
let(:path) { "/decidim_toggle/system/organizations/#{organization.id}/settings_tab/name" }
|
|
70
124
|
let(:valid_params) do
|
|
@@ -29,8 +29,9 @@ cd website && yarn build
|
|
|
29
29
|
|
|
30
30
|
| Check | Command |
|
|
31
31
|
|-------|---------|
|
|
32
|
-
| All | `./bin/check` (RuboCop,
|
|
32
|
+
| All | `./bin/check` (RuboCop, erb_lint, RSpec) |
|
|
33
33
|
| RSpec | `unset DATABASE_URL && RAILS_ENV=test bundle exec rspec` |
|
|
34
|
+
| CI-parity RSpec | `docker compose -f docker-compose.ci.yml run --rm rspec` |
|
|
34
35
|
| Docs | `cd website && yarn build` |
|
|
35
36
|
|
|
36
37
|
## Deep dives
|
|
@@ -25,7 +25,7 @@ Internal templates for decidim-toggle. Integrators customize **their** tab via `
|
|
|
25
25
|
| `_encryption_not_configured_callout.html.erb` | Shown when `encryption_configured?` is false |
|
|
26
26
|
| `tabs/_language_tab.html.erb` | Built-in locale table layout |
|
|
27
27
|
| `tabs/_security_tab.html.erb` | Built-in security layout |
|
|
28
|
-
| `tabs/_authorizations_tab.html.erb` | Built-in authorizations layout |
|
|
28
|
+
| `tabs/_authorizations_tab.html.erb` | Built-in authorizations layout. With `decidim-ephemeral_participation` loaded, shows enabled checkboxes and ephemeral radios and persists a Hash with `allow_ephemeral_participation`. |
|
|
29
29
|
| `tabs/_file_upload_tab.html.erb` | Built-in file upload layout |
|
|
30
30
|
|
|
31
31
|
## Helpers
|
data/website/docs/index.md
CHANGED
|
@@ -15,6 +15,7 @@ Declare attributes on your `Decidim::Form`. `Decidim::Toggle::SettingsFormBuilde
|
|
|
15
15
|
```ruby
|
|
16
16
|
module MyModule
|
|
17
17
|
class AdminConfigForm < Decidim::Form
|
|
18
|
+
include Decidim::Toggle::TabForm
|
|
18
19
|
include Decidim::Toggle::ModuleConfigForm
|
|
19
20
|
|
|
20
21
|
self.module_config_name = "my_module"
|
|
@@ -24,11 +25,22 @@ module MyModule
|
|
|
24
25
|
attribute :api_key, :string
|
|
25
26
|
attribute :max_items, :integer
|
|
26
27
|
attribute :mode, :string
|
|
28
|
+
attribute :notes, :string
|
|
27
29
|
attribute :tags, [String]
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
disable :api_key, if_unchecked: :enabled
|
|
32
|
+
|
|
33
|
+
def self.select_for_mode
|
|
30
34
|
[%w[live Live], %w[draft Draft]]
|
|
31
35
|
end
|
|
36
|
+
|
|
37
|
+
def self.cols_for_notes
|
|
38
|
+
55
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.collection_for_tags
|
|
42
|
+
[%w[a Alpha], %w[b Beta]]
|
|
43
|
+
end
|
|
32
44
|
end
|
|
33
45
|
end
|
|
34
46
|
```
|
|
@@ -38,16 +50,31 @@ end
|
|
|
38
50
|
| Declaration | Widget | Notes |
|
|
39
51
|
|-------------|--------|-------|
|
|
40
52
|
| `attribute :x, :boolean` | Checkbox | |
|
|
41
|
-
| `attribute :x, :string` | Text field | `
|
|
53
|
+
| `attribute :x, :string` | Text field | Max width `55rem` in the settings UI |
|
|
42
54
|
| `attribute :x, :integer` | Number field | |
|
|
55
|
+
| `cols_for_x` | Text area | Declaring cols opts the string attribute into a textarea |
|
|
56
|
+
| `secondary_hosts` (string) | Text area | Built-in exception; use `cols_for_secondary_hosts` for width |
|
|
43
57
|
| Other scalar types | Text field | Fallback when no collection |
|
|
44
58
|
| `attribute :x, [String]` + `collection_for_x` | Check boxes | Multi-select |
|
|
45
59
|
| Scalar + `collection_for_x` | Radio buttons | Single choice |
|
|
60
|
+
| Scalar + `select_for_x` | Dropdown (`<select>`) | Prefer over `collection_for_x` when both exist |
|
|
46
61
|
| `translatable_attribute :x, String` | Translated field | Requires `Decidim::TranslatableAttributes`; locale keys hidden from `all_fields` |
|
|
47
62
|
| `translatable_attribute :x, Decidim::Attributes::RichText` | Translated editor | Rich text per locale |
|
|
48
63
|
|
|
49
64
|
`id` and per-locale keys (e.g. `name_en`) are excluded from `all_fields` when they belong to a translatable hash.
|
|
50
65
|
|
|
66
|
+
## Filter authorization workflows
|
|
67
|
+
|
|
68
|
+
Do not prepend `Decidim::Toggle::UpdateAuthorizationsForm`. Register a filter so the System authorizations tab only lists workflows your module allows:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
Decidim::Toggle.filter_authorization_workflows do |workflow, organization|
|
|
72
|
+
MyModule.workflow_allowed?(workflow, organization)
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Instance `collection_for_available_authorizations` (and the ephemeral picker collection) uses `Decidim::Toggle.authorization_workflows_for(organization)`.
|
|
77
|
+
|
|
51
78
|
## Collections
|
|
52
79
|
|
|
53
80
|
Add `collection_for_<attribute_name>` returning `[[value, label], ...]`:
|
|
@@ -65,6 +92,26 @@ end
|
|
|
65
92
|
- **Scalar attribute** → radio buttons
|
|
66
93
|
- **Array attribute** (`[String]`, etc.) → check boxes
|
|
67
94
|
|
|
95
|
+
### Dropdowns
|
|
96
|
+
|
|
97
|
+
Use `select_for_<attribute_name>` (same `[[value, label], ...]` shape) for a compact `<select>`:
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
def self.select_for_mode
|
|
101
|
+
[%w[live Live], %w[draft Draft]]
|
|
102
|
+
end
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Text areas
|
|
106
|
+
|
|
107
|
+
Declare `cols_for_<attribute>` to render a string attribute as a textarea:
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
def self.cols_for_notes
|
|
111
|
+
55
|
|
112
|
+
end
|
|
113
|
+
```
|
|
114
|
+
|
|
68
115
|
## Field helptext
|
|
69
116
|
|
|
70
117
|
Optional copy under a field — see [Labels](./labels.md).
|
|
@@ -84,7 +131,21 @@ en:
|
|
|
84
131
|
Disable a field in the default builder by implementing either:
|
|
85
132
|
|
|
86
133
|
- `#attribute_disabled?(attribute)` on the form instance, or
|
|
87
|
-
- `#disabled_for_<attribute>?` per attribute
|
|
134
|
+
- `#disabled_for_<attribute>?` per attribute, or
|
|
135
|
+
- `disable :field, if_unchecked: :boolean_attr` (via `TabForm` / `FieldConditions`)
|
|
136
|
+
|
|
137
|
+
### Disable when a checkbox is unchecked
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
include Decidim::Toggle::TabForm # or FieldConditions
|
|
141
|
+
|
|
142
|
+
attribute :enabled, :boolean
|
|
143
|
+
attribute :api_key, :string
|
|
144
|
+
|
|
145
|
+
disable :api_key, if_unchecked: :enabled
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
That is enough: the builder marks the field disabled on render, and the settings-tab JS toggles it live when the checkbox changes.
|
|
88
149
|
|
|
89
150
|
```ruby
|
|
90
151
|
def attribute_disabled?(attribute)
|
|
@@ -94,7 +155,7 @@ end
|
|
|
94
155
|
|
|
95
156
|
Disabled inputs are not submitted; keep your command aligned (ignore or reject unknown params).
|
|
96
157
|
|
|
97
|
-
The field wrapper
|
|
158
|
+
The field wrapper is BEM: `field field--<attribute> field--<type>` (`--checkbox`, `--checkboxes`, `--radios`, `--text`, `--textarea`, `--select`). Disabled fields also get `is-disabled` (Decidim convention) so you can style muted labels/inputs in CSS.
|
|
98
159
|
|
|
99
160
|
## Builder methods
|
|
100
161
|
|
|
@@ -69,6 +69,8 @@ Decidim::Toggle.save_config!(organization, :my_module, { "enabled" => true })
|
|
|
69
69
|
|
|
70
70
|
When settings live on `Decidim::Organization` (SMTP, host, locales, …), use a custom `Decidim::Form` + custom `Decidim::Command` with the same `add_tab` contract. See built-in tabs in `lib/decidim/toggle/organization_settings_tabs.rb`.
|
|
71
71
|
|
|
72
|
+
To hide verification workflows on the Authorizations tab, register `Decidim::Toggle.filter_authorization_workflows` — see [Filter authorization workflows](./attributes.md#filter-authorization-workflows). Do not prepend `UpdateAuthorizationsForm`.
|
|
73
|
+
|
|
72
74
|
## See also
|
|
73
75
|
|
|
74
76
|
- [Integrate](./index.md)
|
data/yarn.lock
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# yarn lockfile v1
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
"@decidim/prettier-config@0.
|
|
6
|
-
version "0.
|
|
7
|
-
resolved "https://registry.yarnpkg.com/@decidim/prettier-config/-/prettier-config-0.
|
|
8
|
-
integrity sha512-
|
|
5
|
+
"@decidim/prettier-config@0.32":
|
|
6
|
+
version "0.32.0"
|
|
7
|
+
resolved "https://registry.yarnpkg.com/@decidim/prettier-config/-/prettier-config-0.32.0.tgz#21ac30028d41b9ef3a6d54b685ff0ef9456aa418"
|
|
8
|
+
integrity sha512-adspO8Ka6rAAHkyxzKLLm+y1qMQ+xt9pUpzknFZ/Z/4DAjdQp6X7Kg6Ztp2S6t7rYZgy7SidGOyVV9PhhPnP8w==
|
|
9
9
|
|
|
10
10
|
prettier@^2.3.2:
|
|
11
11
|
version "2.8.8"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: decidim-toggle
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- hadrien@octree.ch
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: decidim-core
|
|
@@ -73,7 +73,7 @@ executables: []
|
|
|
73
73
|
extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
|
75
75
|
files:
|
|
76
|
-
- ".
|
|
76
|
+
- ".erb_lint.yml"
|
|
77
77
|
- ".github/workflows/website.yml"
|
|
78
78
|
- ".gitignore"
|
|
79
79
|
- ".gitlab-ci.yml"
|
|
@@ -126,6 +126,7 @@ files:
|
|
|
126
126
|
- app/views/decidim_toggle/system/organizations/tabs/_security_tab.html.erb
|
|
127
127
|
- app/views/layouts/decidim/toggle/_javascript_config.html.erb
|
|
128
128
|
- bin/check
|
|
129
|
+
- bin/ci-setup
|
|
129
130
|
- bin/i18n-tasks
|
|
130
131
|
- bin/postversion
|
|
131
132
|
- config/assets.rb
|
|
@@ -133,11 +134,14 @@ files:
|
|
|
133
134
|
- crowdin.yml
|
|
134
135
|
- db/migrate/20260321120000_create_decidim_toggle_organization_module_configs.rb
|
|
135
136
|
- decidim-toggle.gemspec
|
|
137
|
+
- docker-compose.ci.yml
|
|
136
138
|
- docker-compose.yml
|
|
137
139
|
- lib/decidim/toggle.rb
|
|
140
|
+
- lib/decidim/toggle/authorization_workflows.rb
|
|
138
141
|
- lib/decidim/toggle/engine.rb
|
|
139
142
|
- lib/decidim/toggle/expose_attributes_to_js.rb
|
|
140
143
|
- lib/decidim/toggle/expose_attributes_to_js_validator.rb
|
|
144
|
+
- lib/decidim/toggle/field_conditions.rb
|
|
141
145
|
- lib/decidim/toggle/gem_registry.rb
|
|
142
146
|
- lib/decidim/toggle/informative_callouts.rb
|
|
143
147
|
- lib/decidim/toggle/javascript_config.rb
|
|
@@ -235,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
235
239
|
requirements:
|
|
236
240
|
- - ">="
|
|
237
241
|
- !ruby/object:Gem::Version
|
|
238
|
-
version:
|
|
242
|
+
version: 3.2.2
|
|
239
243
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
244
|
requirements:
|
|
241
245
|
- - ">="
|
|
File without changes
|