decidim-skin 0.0.1
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 +7 -0
- data/.erb_lint.yml +44 -0
- data/.gitignore +12 -0
- data/.gitlab-ci.yml +137 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/.simplecov +24 -0
- data/Appraisals +28 -0
- data/CONTRIBUTING.md +77 -0
- data/Gemfile +46 -0
- data/Gemfile.lock +977 -0
- data/LICENSE.md +661 -0
- data/README.md +105 -0
- data/Rakefile +80 -0
- data/app/controllers/decidim/skin/homepage_controller.rb +25 -0
- data/app/overrides/add_component_dropdown_require.rb +21 -0
- data/app/overrides/admin_body_data_attributes.rb +27 -0
- data/app/overrides/admin_item_show_wrapper_data.rb +11 -0
- data/app/overrides/admin_static_page_space_help.rb +35 -0
- data/app/overrides/assemblies_form_processes_field.rb +12 -0
- data/app/overrides/breadcrumb_home_require.rb +55 -0
- data/app/overrides/conferences_form_related_spaces.rb +21 -0
- data/app/overrides/content_block_cell_space_require.rb +13 -0
- data/app/overrides/content_blocks_dropdown_space_require.rb +12 -0
- data/app/overrides/help_sections_space_require.rb +13 -0
- data/app/overrides/insert_hide_css.rb +19 -0
- data/app/overrides/public_body_data_attributes.rb +11 -0
- data/app/overrides/public_content_data.rb +11 -0
- data/app/overrides/search_filters_space_require.rb +14 -0
- data/app/overrides/search_resources_filter_block_space_require.rb +14 -0
- data/app/overrides/search_section_resource_type.rb +16 -0
- data/app/overrides/space_require_attributes.rb +106 -0
- data/app/overrides/statistic_require.rb +13 -0
- data/app/views/decidim/skin/deface_partials/_hide_css.html.erb +4 -0
- data/app/views/decidim/skin/deface_partials/_public_content.html.erb +10 -0
- data/bin/check +10 -0
- data/bin/ci-setup +65 -0
- data/bin/postversion +21 -0
- data/config/i18n-tasks.yml +17 -0
- data/config/locales/de.yml +45 -0
- data/config/locales/en.yml +45 -0
- data/config/locales/fr.yml +45 -0
- data/config/locales/it.yml +45 -0
- data/decidim-skin.gemspec +37 -0
- data/docker-compose.ci.yml +128 -0
- data/docker-compose.yml +53 -0
- data/gemfiles/.gitignore +1 -0
- data/gemfiles/decidim_0.29.gemfile +35 -0
- data/gemfiles/decidim_0.32.gemfile +35 -0
- data/lib/decidim/skin/admin/config_form.rb +135 -0
- data/lib/decidim/skin/body_data_attributes.rb +49 -0
- data/lib/decidim/skin/component_hide_css.rb +17 -0
- data/lib/decidim/skin/component_presence.rb +38 -0
- data/lib/decidim/skin/components.rb +114 -0
- data/lib/decidim/skin/disabled_state.rb +59 -0
- data/lib/decidim/skin/engine.rb +101 -0
- data/lib/decidim/skin/hide_css.rb +76 -0
- data/lib/decidim/skin/homepage_dispatcher.rb +64 -0
- data/lib/decidim/skin/homepage_options.rb +71 -0
- data/lib/decidim/skin/homepage_resolver.rb +67 -0
- data/lib/decidim/skin/layout_data_attributes.rb +48 -0
- data/lib/decidim/skin/migrate_from_space_page.rb +139 -0
- data/lib/decidim/skin/organization_extensions.rb +16 -0
- data/lib/decidim/skin/overrides/breadcrumb_helper.rb +36 -0
- data/lib/decidim/skin/overrides/layout_helper.rb +19 -0
- data/lib/decidim/skin/overrides/menu_item_presenter.rb +74 -0
- data/lib/decidim/skin/overrides/menu_presenter.rb +23 -0
- data/lib/decidim/skin/overrides/meta_tags_helper.rb +40 -0
- data/lib/decidim/skin/overrides/searches_controller.rb +36 -0
- data/lib/decidim/skin/participatory_spaces.rb +130 -0
- data/lib/decidim/skin/search_filters.rb +44 -0
- data/lib/decidim/skin/seeds.rb +363 -0
- data/lib/decidim/skin/settings_tab.rb +21 -0
- data/lib/decidim/skin/space_hide_css.rb +17 -0
- data/lib/decidim/skin/stored_config.rb +28 -0
- data/lib/decidim/skin/toggle_defaults.rb +36 -0
- data/lib/decidim/skin/ui_hides.rb +27 -0
- data/lib/decidim/skin/version.rb +14 -0
- data/lib/decidim/skin.rb +61 -0
- data/lib/tasks/decidim/skin/migrate_from_space_page.rake +14 -0
- data/package.json +23 -0
- data/requests/decidim/skin/homepage_controller_spec.rb +24 -0
- data/spec/decidim/skin/body_data_attributes_spec.rb +98 -0
- data/spec/decidim/skin/components_spec.rb +96 -0
- data/spec/decidim/skin/hide_css_spec.rb +110 -0
- data/spec/decidim/skin/homepage_dispatcher_spec.rb +34 -0
- data/spec/decidim/skin/homepage_options_spec.rb +42 -0
- data/spec/decidim/skin/homepage_resolver_spec.rb +73 -0
- data/spec/decidim/skin/layout_data_attributes_spec.rb +48 -0
- data/spec/decidim/skin/migrate_from_space_page_spec.rb +121 -0
- data/spec/decidim/skin/overrides/breadcrumb_helper_spec.rb +59 -0
- data/spec/decidim/skin/overrides/layout_helper_spec.rb +25 -0
- data/spec/decidim/skin/overrides/menu_item_presenter_spec.rb +77 -0
- data/spec/decidim/skin/overrides/menu_presenter_spec.rb +49 -0
- data/spec/decidim/skin/overrides/meta_tags_helper_spec.rb +108 -0
- data/spec/decidim/skin/participatory_spaces_spec.rb +83 -0
- data/spec/decidim/skin/search_filters_spec.rb +56 -0
- data/spec/decidim/skin/seeds_spec.rb +81 -0
- data/spec/decidim/skin/settings_tab_spec.rb +22 -0
- data/spec/decidim/skin.rb +3 -0
- data/spec/decidim_skin_overrides/space_require_spec.rb +25 -0
- data/spec/forms/decidim/skin/admin/config_form_spec.rb +160 -0
- data/spec/requests/decidim/skin/homepage_controller_spec.rb +33 -0
- data/spec/spec_helper.rb +36 -0
- data/spec/system/decidim/skin/admin_add_component_require_attributes_spec.rb +28 -0
- data/spec/system/decidim/skin/admin_assembly_form_require_attributes_spec.rb +24 -0
- data/spec/system/decidim/skin/admin_help_sections_space_require_spec.rb +27 -0
- data/spec/system/decidim/skin/admin_layout_data_attributes_spec.rb +60 -0
- data/spec/system/decidim/skin/admin_organization_homepage_menu_spec.rb +39 -0
- data/spec/system/decidim/skin/public_breadcrumb_spec.rb +82 -0
- data/spec/system/decidim/skin/public_layout_data_attributes_spec.rb +131 -0
- data/system/decidim/skin/homepage_controller_spec.rb +24 -0
- data/views/decidim/skin/system/_homepage_tab.html.erb +15 -0
- metadata +246 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Space registry: enabled flags, content-block names, search type, hide kebab.
|
|
6
|
+
# Touch when a new participatory space should toggle, hide, or filter search.
|
|
7
|
+
module ParticipatorySpaces
|
|
8
|
+
# Manifests on by default (others default off).
|
|
9
|
+
DEFAULT_ENABLED = {
|
|
10
|
+
"participatory_processes" => true,
|
|
11
|
+
"assemblies" => true
|
|
12
|
+
}.freeze
|
|
13
|
+
# Manifest name → public URL segment when it differs (processes vs participatory_processes).
|
|
14
|
+
PUBLIC_SEGMENTS = { "participatory_processes" => "processes" }.freeze
|
|
15
|
+
# Manifest name → homepage content-block names that mention that space.
|
|
16
|
+
# Missing keys fall back to highlighted_<name> and related_<name>.
|
|
17
|
+
CONTENT_BLOCKS = {
|
|
18
|
+
"participatory_processes" => %w(related_processes highlighted_processes),
|
|
19
|
+
"assemblies" => %w(related_assemblies highlighted_assemblies),
|
|
20
|
+
"conferences" => %w(highlighted_conferences),
|
|
21
|
+
"initiatives" => %w(highlighted_initiatives)
|
|
22
|
+
}.freeze
|
|
23
|
+
# Manifest name → related-space form field for stamping data-require-*.
|
|
24
|
+
LINK_FIELDS = {
|
|
25
|
+
"participatory_processes" => "participatory_processes_ids",
|
|
26
|
+
"assemblies" => "assemblies_ids"
|
|
27
|
+
}.freeze
|
|
28
|
+
# Old Toggle module_name for space flags (pre-decidim_skin).
|
|
29
|
+
LEGACY_MODULE = "spaces"
|
|
30
|
+
|
|
31
|
+
module_function
|
|
32
|
+
|
|
33
|
+
def manifests
|
|
34
|
+
Decidim.participatory_space_manifests
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def names
|
|
38
|
+
manifests.map { |manifest| manifest.name.to_s }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def kebab(name)
|
|
42
|
+
name.to_s.tr("_", "-")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def require_data(identifier)
|
|
46
|
+
name = identifier.to_s
|
|
47
|
+
return {} unless names.include?(name)
|
|
48
|
+
|
|
49
|
+
{ "data-require-#{kebab(name)}" => "true" }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def enabled_attribute_names
|
|
53
|
+
names.map { |name| :"#{name}_enabled" }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def default_enabled?(name)
|
|
57
|
+
DEFAULT_ENABLED.fetch(name.to_s, false)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def public_segment(name)
|
|
61
|
+
PUBLIC_SEGMENTS.fetch(name.to_s, name.to_s)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def content_blocks(name)
|
|
65
|
+
CONTENT_BLOCKS.fetch(name.to_s, ["highlighted_#{name}", "related_#{name}"])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def link_field(name)
|
|
69
|
+
LINK_FIELDS[name.to_s]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def search_resource_type(name)
|
|
73
|
+
manifest_for(name)&.model_class_name
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def enabled?(organization, name)
|
|
77
|
+
return false if organization.blank?
|
|
78
|
+
return false unless manifest_for(name)
|
|
79
|
+
return true unless Decidim::Skin.enabled_for?(organization)
|
|
80
|
+
|
|
81
|
+
stored_or_default(organization, name)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def stored_or_default(organization, name)
|
|
85
|
+
flag = stored_flag(organization, name)
|
|
86
|
+
return flag unless flag.nil?
|
|
87
|
+
|
|
88
|
+
default_enabled?(name)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def existing?(organization, name)
|
|
92
|
+
collection = space_collection(organization, name)
|
|
93
|
+
return false if collection.blank?
|
|
94
|
+
return collection.exists? if collection.respond_to?(:exists?)
|
|
95
|
+
|
|
96
|
+
collection.any?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def label_for(name)
|
|
100
|
+
class_name = manifest_for(name)&.model_class_name
|
|
101
|
+
return name.to_s.humanize unless class_name
|
|
102
|
+
|
|
103
|
+
class_name.constantize.model_name.human(count: 2)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def name_for_model(model_class)
|
|
107
|
+
manifests.find { |manifest| manifest.model_class_name == model_class.name }&.name&.to_s
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def manifest_for(name)
|
|
111
|
+
Decidim.find_participatory_space_manifest(name.to_s)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def stored_flag(organization, name)
|
|
115
|
+
key = "#{name}_enabled"
|
|
116
|
+
skin = StoredConfig.boolean_for(organization, MODULE_NAME, key)
|
|
117
|
+
return skin unless skin.nil?
|
|
118
|
+
|
|
119
|
+
StoredConfig.boolean_for(organization, LEGACY_MODULE, key)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def space_collection(organization, name)
|
|
123
|
+
manifest = manifest_for(name)
|
|
124
|
+
return nil unless manifest && organization
|
|
125
|
+
|
|
126
|
+
manifest.participatory_spaces.call(organization)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Strips disabled space/component resource types from Search results hashes.
|
|
6
|
+
# Touch when a new searchable model must disappear with its parent toggle.
|
|
7
|
+
module SearchFilters
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def filter_results(results, organization)
|
|
11
|
+
disabled = disabled_resource_types(organization)
|
|
12
|
+
return results if disabled.empty?
|
|
13
|
+
|
|
14
|
+
results.except(*disabled)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def disabled_resource_types(organization)
|
|
18
|
+
return [] if organization.blank?
|
|
19
|
+
|
|
20
|
+
disabled_space_types(organization) + disabled_component_types(organization)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# participatory_processes also includes Decidim::ParticipatoryProcessGroup as a resource
|
|
24
|
+
# it is neither a space nor a component
|
|
25
|
+
def disabled_space_types(organization)
|
|
26
|
+
ParticipatorySpaces.names.filter_map do |name|
|
|
27
|
+
next if ParticipatorySpaces.enabled?(organization, name)
|
|
28
|
+
|
|
29
|
+
return [ParticipatorySpaces.search_resource_type(name), "Decidim::ParticipatoryProcessGroup"] if name == "participatory_processes"
|
|
30
|
+
|
|
31
|
+
ParticipatorySpaces.search_resource_type(name)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def disabled_component_types(organization)
|
|
36
|
+
Components.names.flat_map do |name|
|
|
37
|
+
next [] if Components.enabled?(organization, name)
|
|
38
|
+
|
|
39
|
+
Components.search_resource_types(name)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "decidim/seeds"
|
|
4
|
+
require "decidim/faker/localized"
|
|
5
|
+
|
|
6
|
+
module Decidim
|
|
7
|
+
module Skin
|
|
8
|
+
# Extra tenants created at the end of Decidim.seed! / db:seed.
|
|
9
|
+
# Touch TENANTS when adding a dummy org for a space gem.
|
|
10
|
+
class Seeds < Decidim::Seeds
|
|
11
|
+
# Dummy orgs: one host per space gem, used by Seeds#call after Decidim.seed!.
|
|
12
|
+
TENANTS = [
|
|
13
|
+
{
|
|
14
|
+
host: "process-skin.localhost",
|
|
15
|
+
name: "Climate Action Plan 2026",
|
|
16
|
+
subtitle: "Neighborhood proposals for a carbon-neutral city",
|
|
17
|
+
blurb: "Residents choose mobility, housing, and food measures for the next budget.",
|
|
18
|
+
description: "A city-wide process with public workshops, blog updates, and open proposals.",
|
|
19
|
+
gem: "decidim-participatory_processes",
|
|
20
|
+
space: "participatory_processes",
|
|
21
|
+
prefix: "CAP",
|
|
22
|
+
colors: { primary: "#09780e", secondary: "#4448bb", tertiary: "#da565b" }
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
host: "assembly-skin.localhost",
|
|
26
|
+
name: "North District Council",
|
|
27
|
+
subtitle: "Standing assembly for the northern neighborhoods",
|
|
28
|
+
blurb: "The district assembly follows local services, meetings, and resident proposals.",
|
|
29
|
+
description: "A permanent participatory assembly with hearings, a public blog, and an open proposal board.",
|
|
30
|
+
gem: "decidim-assemblies",
|
|
31
|
+
space: "assemblies",
|
|
32
|
+
prefix: "NDC",
|
|
33
|
+
colors: { primary: "#155abf", secondary: "#e02d2d", tertiary: "#ebc34b" }
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
host: "conference-skin.localhost",
|
|
37
|
+
name: "Civic Tech Days",
|
|
38
|
+
subtitle: "Annual gathering of civic technologists and officials",
|
|
39
|
+
blurb: "Talks, working sessions, and a call for session proposals.",
|
|
40
|
+
description: "A three-day conference with a public program, a blog, and an open CFP.",
|
|
41
|
+
gem: "decidim-conferences",
|
|
42
|
+
space: "conferences",
|
|
43
|
+
prefix: "CTD",
|
|
44
|
+
colors: { primary: "#5340bf", secondary: "#a82c2c", tertiary: "#40bf53" }
|
|
45
|
+
}
|
|
46
|
+
].freeze
|
|
47
|
+
|
|
48
|
+
COMPONENT_SEEDS = [
|
|
49
|
+
{ gem: "decidim-meetings", class_name: "Decidim::Meetings::Seeds", manifest: :meetings },
|
|
50
|
+
{ gem: "decidim-blogs", class_name: "Decidim::Blogs::Seeds", manifest: :blogs },
|
|
51
|
+
{ gem: "decidim-proposals", class_name: "Decidim::Proposals::Seeds", manifest: :proposals }
|
|
52
|
+
].freeze
|
|
53
|
+
|
|
54
|
+
SPACE_SEEDS = {
|
|
55
|
+
"participatory_processes" => "Decidim::ParticipatoryProcesses::Seeds",
|
|
56
|
+
"assemblies" => "Decidim::Assemblies::Seeds",
|
|
57
|
+
"conferences" => "Decidim::Conferences::Seeds"
|
|
58
|
+
}.freeze
|
|
59
|
+
|
|
60
|
+
def call
|
|
61
|
+
puts "Creating Skin showcase tenants..." unless Rails.env.test? # rubocop:disable Rails/Output
|
|
62
|
+
TENANTS.each { |tenant| seed_tenant(tenant) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
attr_reader :organization
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def seed_tenant(tenant)
|
|
70
|
+
return unless Gem.loaded_specs.has_key?(tenant[:gem])
|
|
71
|
+
|
|
72
|
+
@organization = find_or_create_organization!(tenant)
|
|
73
|
+
Decidim::System::CreateDefaultPages.call(organization)
|
|
74
|
+
create_users!
|
|
75
|
+
space = find_or_create_space!(tenant)
|
|
76
|
+
seed_components!(space, tenant)
|
|
77
|
+
save_skin!(space, tenant)
|
|
78
|
+
announce(tenant)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def find_or_create_organization!(tenant)
|
|
82
|
+
Decidim::Organization.find_by(host: tenant[:host]) || create_organization!(tenant)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def create_organization!(tenant)
|
|
86
|
+
org = Decidim::Organization.create!(organization_params(tenant))
|
|
87
|
+
Decidim::ContentBlocksCreator.new(org).create_default!
|
|
88
|
+
org
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def organization_params(tenant)
|
|
92
|
+
organization_identity(tenant).merge(organization_settings)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def organization_identity(tenant)
|
|
96
|
+
{
|
|
97
|
+
name: localized(tenant[:name]),
|
|
98
|
+
host: tenant[:host],
|
|
99
|
+
reference_prefix: tenant[:prefix],
|
|
100
|
+
description: html_paragraph(tenant[:description]),
|
|
101
|
+
colors: tenant[:colors]
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def organization_settings
|
|
106
|
+
{
|
|
107
|
+
default_locale: Decidim.default_locale,
|
|
108
|
+
available_locales: Decidim.available_locales,
|
|
109
|
+
time_zone: "UTC",
|
|
110
|
+
tos_version: Time.current,
|
|
111
|
+
users_registration_mode: :enabled,
|
|
112
|
+
badges_enabled: true,
|
|
113
|
+
send_welcome_notification: true,
|
|
114
|
+
file_upload_settings: Decidim::OrganizationSettings.default(:upload)
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def create_users!
|
|
119
|
+
create_user!("admin@example.org", admin: true, admin_terms_accepted_at: Time.current)
|
|
120
|
+
create_user!("user@example.org")
|
|
121
|
+
create_user_groups!
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def create_user_groups!
|
|
125
|
+
return unless user_groups_seedable?
|
|
126
|
+
|
|
127
|
+
create_user_group!(find_org_user("user@example.org"))
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def user_groups_seedable?
|
|
131
|
+
spec = Gem.loaded_specs["decidim-core"]
|
|
132
|
+
spec.present? && spec.version < Gem::Version.new("0.31")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def create_user_group!(user)
|
|
136
|
+
return if org_user_groups.exists?
|
|
137
|
+
|
|
138
|
+
group = Decidim::UserGroup.create!(user_group_attrs(user))
|
|
139
|
+
Decidim::UserGroupMembership.create!(user:, role: "creator", user_group: group)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def org_user_groups
|
|
143
|
+
Decidim::UserGroup.where(decidim_organization_id: organization.id)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def user_group_attrs(user)
|
|
147
|
+
{
|
|
148
|
+
name: ::Faker::Company.unique.name,
|
|
149
|
+
nickname: user_group_nickname,
|
|
150
|
+
email: ::Faker::Internet.email,
|
|
151
|
+
confirmed_at: Time.current,
|
|
152
|
+
extended_data: user_group_extended_data,
|
|
153
|
+
decidim_organization_id: user.organization.id
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def user_group_nickname
|
|
158
|
+
"#{::Faker::X.unique.screen_name}-#{rand(10_000)}"[0...20]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def user_group_extended_data
|
|
162
|
+
{
|
|
163
|
+
document_number: ::Faker::Number.number(digits: 10).to_s,
|
|
164
|
+
phone: ::Faker::PhoneNumber.phone_number,
|
|
165
|
+
verified_at: Time.current
|
|
166
|
+
}
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def create_user!(email, extra = {})
|
|
170
|
+
user = find_org_user(email)
|
|
171
|
+
return user if user.persisted?
|
|
172
|
+
|
|
173
|
+
user.update!(user_identity.merge(user_flags).merge(extra))
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def find_org_user(email)
|
|
177
|
+
Decidim::User.find_or_initialize_by(email:, organization:)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def user_identity
|
|
181
|
+
{
|
|
182
|
+
name: ::Faker::Name.name,
|
|
183
|
+
nickname: "#{::Faker::X.unique.screen_name}-#{rand(10_000)}"[0...20],
|
|
184
|
+
password: "decidim123456789",
|
|
185
|
+
organization:
|
|
186
|
+
}
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def user_flags
|
|
190
|
+
{
|
|
191
|
+
confirmed_at: Time.current,
|
|
192
|
+
locale: I18n.default_locale,
|
|
193
|
+
accepted_tos_version: organization.tos_version + 1.hour,
|
|
194
|
+
tos_agreement: true,
|
|
195
|
+
password_updated_at: Time.current
|
|
196
|
+
}
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def find_or_create_space!(tenant)
|
|
200
|
+
existing_space(tenant) || create_space!(tenant)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def existing_space(tenant)
|
|
204
|
+
collection = ParticipatorySpaces.space_collection(organization, tenant[:space])
|
|
205
|
+
return if collection.blank?
|
|
206
|
+
|
|
207
|
+
collection.respond_to?(:published) ? collection.published.first : collection.first
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
def create_space!(tenant)
|
|
211
|
+
send(:"create_#{space_builder(tenant)}_space!", tenant)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def space_builder(tenant)
|
|
215
|
+
{
|
|
216
|
+
"participatory_processes" => "process",
|
|
217
|
+
"assemblies" => "assembly",
|
|
218
|
+
"conferences" => "conference"
|
|
219
|
+
}.fetch(tenant[:space].to_s)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def create_process_space!(tenant)
|
|
223
|
+
process = Decidim::ParticipatoryProcess.create!(process_attrs(tenant))
|
|
224
|
+
space_helper(tenant).create_process_step!(process:)
|
|
225
|
+
finish_space!(process, tenant)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def create_assembly_space!(tenant)
|
|
229
|
+
finish_space!(Decidim::Assembly.create!(assembly_attrs(tenant)), tenant)
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def create_conference_space!(tenant)
|
|
233
|
+
finish_space!(Decidim::Conference.create!(conference_attrs(tenant)), tenant)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def process_attrs(tenant)
|
|
237
|
+
space_attrs(tenant).merge(
|
|
238
|
+
subtitle: localized(tenant[:subtitle]),
|
|
239
|
+
start_date: Date.current,
|
|
240
|
+
end_date: 2.months.from_now
|
|
241
|
+
)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def assembly_attrs(tenant)
|
|
245
|
+
space_attrs(tenant).merge(subtitle: localized(tenant[:subtitle]))
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def conference_attrs(tenant)
|
|
249
|
+
space_attrs(tenant).merge(
|
|
250
|
+
slogan: localized(tenant[:subtitle]),
|
|
251
|
+
objectives: html_paragraph(tenant[:description]),
|
|
252
|
+
start_date: Time.current,
|
|
253
|
+
end_date: 2.months.from_now
|
|
254
|
+
)
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def space_attrs(tenant)
|
|
258
|
+
{
|
|
259
|
+
organization:,
|
|
260
|
+
slug: "#{tenant[:prefix].downcase}-#{SecureRandom.hex(3)}",
|
|
261
|
+
title: localized(tenant[:name]),
|
|
262
|
+
short_description: html_paragraph(tenant[:blurb]),
|
|
263
|
+
description: html_paragraph(tenant[:description]),
|
|
264
|
+
promoted: true,
|
|
265
|
+
published_at: 2.weeks.ago
|
|
266
|
+
}
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def finish_space!(space, _tenant)
|
|
270
|
+
create_space_blocks!(space)
|
|
271
|
+
index_space!(space)
|
|
272
|
+
space.reload
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def index_space!(space)
|
|
276
|
+
return unless space.respond_to?(:add_to_index_as_search_resource)
|
|
277
|
+
|
|
278
|
+
space.add_to_index_as_search_resource
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def create_space_blocks!(space)
|
|
282
|
+
return if space.try(:manifest)&.content_blocks_scope_name.blank?
|
|
283
|
+
|
|
284
|
+
Decidim::ContentBlocksCreator.new(space).create_default!
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def space_helper(tenant)
|
|
288
|
+
require "#{tenant[:gem].tr("-", "/")}/seeds"
|
|
289
|
+
helper = SPACE_SEEDS.fetch(tenant[:space].to_s).constantize.new
|
|
290
|
+
org = organization
|
|
291
|
+
helper.define_singleton_method(:organization) { org }
|
|
292
|
+
helper
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
def seed_components!(space, tenant)
|
|
296
|
+
space.reload
|
|
297
|
+
COMPONENT_SEEDS.each { |config| seed_component!(config, space) }
|
|
298
|
+
seed_conference_extras!(space.reload, tenant)
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def seed_component!(config, space)
|
|
302
|
+
return unless Gem.loaded_specs.has_key?(config[:gem])
|
|
303
|
+
return if space.components.exists?(manifest_name: config[:manifest])
|
|
304
|
+
|
|
305
|
+
require "#{config[:gem].tr("-", "/")}/seeds"
|
|
306
|
+
config[:class_name].constantize.new(participatory_space: space).call
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def seed_conference_extras!(conference, tenant)
|
|
310
|
+
return unless tenant[:space] == "conferences" && conference.speakers.none?
|
|
311
|
+
|
|
312
|
+
helper = space_helper(tenant)
|
|
313
|
+
return unless helper.respond_to?(:create_conference_speaker!) && helper.respond_to?(:create_conference_meeting!)
|
|
314
|
+
|
|
315
|
+
3.times { helper.create_conference_speaker!(conference:) }
|
|
316
|
+
helper.create_conference_meeting!(conference:)
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def save_skin!(space, tenant)
|
|
320
|
+
Decidim::Toggle.save_config!(organization, MODULE_NAME, skin_config(space, tenant), merge: false)
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def skin_config(space, tenant)
|
|
324
|
+
space_flags(tenant[:space]).merge(
|
|
325
|
+
"enabled" => true,
|
|
326
|
+
"homepage" => space.to_global_id.to_s,
|
|
327
|
+
"meetings_enabled" => true,
|
|
328
|
+
"blogs_enabled" => true,
|
|
329
|
+
"proposals_enabled" => true
|
|
330
|
+
)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
def space_flags(enabled_space)
|
|
334
|
+
ParticipatorySpaces.names.to_h do |name|
|
|
335
|
+
["#{name}_enabled", name == enabled_space.to_s]
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def localized(text)
|
|
340
|
+
Decidim::Faker::Localized.literal(text)
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def html_paragraph(text)
|
|
344
|
+
Decidim::Faker::Localized.wrapped("<p>", "</p>") { localized(text) }
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
def announce(tenant)
|
|
348
|
+
return if Rails.env.test?
|
|
349
|
+
|
|
350
|
+
puts " Skin tenant: http://#{tenant[:host]} — #{tenant[:name]}" # rubocop:disable Rails/Output
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# Runs Skin tenants after core, component, and space seeds.
|
|
355
|
+
# Prepended onto Decidim; touch if seed order relative to space gems changes.
|
|
356
|
+
module SeedHook
|
|
357
|
+
def seed!
|
|
358
|
+
super
|
|
359
|
+
Seeds.new.call
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Registers the Skin tab on Toggle organization settings.
|
|
6
|
+
# Touch when the form class, command, or tab partial path changes.
|
|
7
|
+
class SettingsTab
|
|
8
|
+
def self.register!
|
|
9
|
+
Decidim::Toggle.settings_tabs :organization_settings do |tabs|
|
|
10
|
+
tabs.add_tab :decidim_skin,
|
|
11
|
+
I18n.t("decidim_toggle.system.decidim_skin.tab"),
|
|
12
|
+
form: Decidim::Skin::Admin::ConfigForm,
|
|
13
|
+
command: Decidim::Toggle::UpdateModuleConfigCommand,
|
|
14
|
+
module_name: MODULE_NAME,
|
|
15
|
+
form_layout_partial: "decidim/skin/system/homepage_tab",
|
|
16
|
+
position: 20
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Hide CSS for one space when that type is off for the organization.
|
|
6
|
+
# Touch when the selector must change; keep =true (Deface may emit false).
|
|
7
|
+
module SpaceHideCss
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def rules_for(name, organization)
|
|
11
|
+
return "" if ParticipatorySpaces.enabled?(organization, name)
|
|
12
|
+
|
|
13
|
+
HideCss.require_hide(ParticipatorySpaces.kebab(name))
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Reads raw JSON rows from Toggle without applying form defaults.
|
|
6
|
+
# Touch when flag lookup must ignore ConfigForm defaults or read a legacy module_name.
|
|
7
|
+
module StoredConfig
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def hash_for(organization, module_name)
|
|
11
|
+
return {} if organization.blank?
|
|
12
|
+
|
|
13
|
+
record = Decidim::Toggle::OrganizationModuleConfig.find_by(
|
|
14
|
+
decidim_organization_id: organization.id,
|
|
15
|
+
module_name: module_name.to_s
|
|
16
|
+
)
|
|
17
|
+
(record&.config || {}).stringify_keys
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def boolean_for(organization, module_name, key)
|
|
21
|
+
raw = hash_for(organization, module_name)
|
|
22
|
+
return nil unless raw.has_key?(key.to_s)
|
|
23
|
+
|
|
24
|
+
ActiveModel::Type::Boolean.new.cast(raw[key.to_s])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Fills missing Skin tab flags from stored/legacy/default values.
|
|
6
|
+
# Touch when a new *_enabled or UI hide attribute must appear without a stored row.
|
|
7
|
+
module ToggleDefaults
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
def merge(organization, raw)
|
|
11
|
+
raw = raw.stringify_keys
|
|
12
|
+
fill_flags(raw, organization, ParticipatorySpaces)
|
|
13
|
+
fill_flags(raw, organization, Components)
|
|
14
|
+
fill_ui_hides(raw)
|
|
15
|
+
raw
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fill_ui_hides(raw)
|
|
19
|
+
UiHides.names.each do |name|
|
|
20
|
+
next if raw.has_key?(name)
|
|
21
|
+
|
|
22
|
+
raw[name] = false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fill_flags(raw, organization, registry)
|
|
27
|
+
registry.names.each do |name|
|
|
28
|
+
key = "#{name}_enabled"
|
|
29
|
+
next if raw.has_key?(key)
|
|
30
|
+
|
|
31
|
+
raw[key] = registry.enabled?(organization, name)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Skin
|
|
5
|
+
# Org-wide UI chrome hide flags (default off). Touch when adding a Skin UI toggle.
|
|
6
|
+
module UiHides
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
FLAGS = %w(hide_reference_footer hide_secondary_navigation).freeze
|
|
10
|
+
|
|
11
|
+
def names
|
|
12
|
+
FLAGS
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def kebab(name)
|
|
16
|
+
name.to_s.tr("_", "-")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def on?(organization, name)
|
|
20
|
+
return false unless Decidim::Skin.enabled_for?(organization)
|
|
21
|
+
|
|
22
|
+
raw = StoredConfig.hash_for(organization, MODULE_NAME)[name.to_s]
|
|
23
|
+
ActiveModel::Type::Boolean.new.cast(raw) == true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
# Gem version and compatible Decidim range for the gemspec.
|
|
5
|
+
module Skin
|
|
6
|
+
def self.version
|
|
7
|
+
"0.0.1" # DO NOT UPDATE MANUALLY
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.decidim_version
|
|
11
|
+
[">= 0.29", "< 0.33"].freeze
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|