decidim-generators 0.20.1 → 0.23.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 +4 -4
- data/Gemfile +4 -1
- data/Gemfile.lock +282 -254
- data/lib/decidim/generators/app_generator.rb +29 -9
- data/lib/decidim/generators/app_templates/budgets_initializer.rb +4 -0
- data/lib/decidim/generators/app_templates/budgets_workflow_random.en.yml +8 -0
- data/lib/decidim/generators/app_templates/budgets_workflow_random.rb +33 -0
- data/lib/decidim/generators/app_templates/bullet_initializer.rb +10 -0
- data/lib/decidim/generators/app_templates/dummy_authorization_handler.rb +53 -9
- data/lib/decidim/generators/app_templates/initializer.rb +165 -8
- data/lib/decidim/generators/app_templates/rack_profiler_initializer.rb +8 -0
- data/lib/decidim/generators/app_templates/secrets.yml.erb +14 -2
- data/lib/decidim/generators/app_templates/verifications_initializer.rb +6 -3
- data/lib/decidim/generators/component_templates/Gemfile.erb +2 -1
- data/lib/decidim/generators/component_templates/README.md.erb +1 -1
- data/lib/decidim/generators/component_templates/decidim-component.gemspec.erb +1 -1
- data/lib/decidim/generators/install_generator.rb +25 -0
- data/lib/decidim/generators/version.rb +1 -1
- metadata +11 -6
@@ -61,6 +61,10 @@ module Decidim
|
|
61
61
|
default: false,
|
62
62
|
desc: "Generate demo authorization handlers"
|
63
63
|
|
64
|
+
class_option :profiling, type: :boolean,
|
65
|
+
default: false,
|
66
|
+
desc: "Add the necessary gems to profile the app"
|
67
|
+
|
64
68
|
def database_yml
|
65
69
|
template "database.yml.erb", "config/database.yml", force: true
|
66
70
|
end
|
@@ -111,14 +115,12 @@ module Decidim
|
|
111
115
|
if current_gem == "decidim"
|
112
116
|
gsub_file "Gemfile", /gem "decidim-dev".*/, "gem \"decidim-dev\", #{gem_modifier}"
|
113
117
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
gsub_file "Gemfile", /gem "decidim-initiatives".*/, "# gem \"decidim-initiatives\", #{gem_modifier}"
|
121
|
-
gsub_file "Gemfile", /gem "decidim-conferences".*/, "# gem \"decidim-conferences\", #{gem_modifier}"
|
118
|
+
%w(conferences consultations elections initiatives templates).each do |component|
|
119
|
+
if options[:demo]
|
120
|
+
gsub_file "Gemfile", /gem "decidim-#{component}".*/, "gem \"decidim-#{component}\", #{gem_modifier}"
|
121
|
+
else
|
122
|
+
gsub_file "Gemfile", /gem "decidim-#{component}".*/, "# gem \"decidim-#{component}\", #{gem_modifier}"
|
123
|
+
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -172,6 +174,15 @@ module Decidim
|
|
172
174
|
"config.sms_gateway_service = 'Decidim::Verifications::Sms::ExampleGateway'"
|
173
175
|
end
|
174
176
|
|
177
|
+
def budgets_workflows
|
178
|
+
return unless options[:demo]
|
179
|
+
|
180
|
+
copy_file "budgets_workflow_random.rb", "lib/budgets_workflow_random.rb"
|
181
|
+
copy_file "budgets_workflow_random.en.yml", "config/locales/budgets_workflow_random.en.yml"
|
182
|
+
|
183
|
+
copy_file "budgets_initializer.rb", "config/initializers/decidim_budgets.rb"
|
184
|
+
end
|
185
|
+
|
175
186
|
def timestamp_service
|
176
187
|
return unless options[:demo]
|
177
188
|
|
@@ -188,13 +199,22 @@ module Decidim
|
|
188
199
|
"config.pdf_signature_service = \"Decidim::Initiatives::PdfSignatureExample\""
|
189
200
|
end
|
190
201
|
|
202
|
+
def machine_translation_service
|
203
|
+
return unless options[:demo]
|
204
|
+
|
205
|
+
gsub_file "config/initializers/decidim.rb",
|
206
|
+
/# config.machine_translation_service = \"MyTranslationService\"/,
|
207
|
+
"config.machine_translation_service = 'Decidim::Dev::DummyTranslator'"
|
208
|
+
end
|
209
|
+
|
191
210
|
def install
|
192
211
|
Decidim::Generators::InstallGenerator.start(
|
193
212
|
[
|
194
213
|
"--recreate_db=#{options[:recreate_db]}",
|
195
214
|
"--seed_db=#{options[:seed_db]}",
|
196
215
|
"--skip_gemfile=#{options[:skip_gemfile]}",
|
197
|
-
"--app_name=#{app_name}"
|
216
|
+
"--app_name=#{app_name}",
|
217
|
+
"--profiling=#{options[:profiling]}"
|
198
218
|
]
|
199
219
|
)
|
200
220
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This Workflow allows users to vote only in one budget, selected randomly.
|
4
|
+
#
|
5
|
+
# Note: random selection should be deterministic for the same user and the same budgets component.
|
6
|
+
# As the budget resources list could change and affect the random selection, it also allows to finish orders created on other budgets.
|
7
|
+
class BudgetsWorkflowRandom < Decidim::Budgets::Workflows::Base
|
8
|
+
# Highlight the resource if the user didn't vote and is allowed to vote on it.
|
9
|
+
def highlighted?(resource)
|
10
|
+
vote_allowed?(resource)
|
11
|
+
end
|
12
|
+
|
13
|
+
# User can vote in the resource where they have an order in progress or in the randomly selected resource.
|
14
|
+
def vote_allowed?(resource, consider_progress = true)
|
15
|
+
return false if voted.any?
|
16
|
+
|
17
|
+
if consider_progress
|
18
|
+
progress?(resource) || (progress.none? && resource == random_resource)
|
19
|
+
else
|
20
|
+
resource == random_resource
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def discardable
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def random_resource
|
31
|
+
@random_resource ||= budgets.reorder(id: :asc).to_a[user.id % budgets.count] if user
|
32
|
+
end
|
33
|
+
end
|
@@ -23,9 +23,11 @@ class DummyAuthorizationHandler < Decidim::AuthorizationHandler
|
|
23
23
|
# Define the attributes you need for this authorization handler. Attributes
|
24
24
|
# are defined using Virtus.
|
25
25
|
#
|
26
|
+
attribute :name_and_surname, String
|
26
27
|
attribute :document_number, String
|
27
28
|
attribute :postal_code, String
|
28
29
|
attribute :birthday, Decidim::Attributes::LocalizedDate
|
30
|
+
attribute :scope_id, Integer
|
29
31
|
|
30
32
|
# You can (and should) also define validations on each attribute:
|
31
33
|
#
|
@@ -34,6 +36,7 @@ class DummyAuthorizationHandler < Decidim::AuthorizationHandler
|
|
34
36
|
# You can also define custom validations:
|
35
37
|
#
|
36
38
|
validate :valid_document_number
|
39
|
+
validate :valid_scope_id
|
37
40
|
|
38
41
|
# The only method that needs to be implemented for an authorization handler.
|
39
42
|
# Here you can add your business logic to check if the authorization should
|
@@ -53,6 +56,12 @@ class DummyAuthorizationHandler < Decidim::AuthorizationHandler
|
|
53
56
|
document_number
|
54
57
|
end
|
55
58
|
|
59
|
+
# The user scope
|
60
|
+
#
|
61
|
+
def scope
|
62
|
+
user.organization.scopes.find_by(id: scope_id) if scope_id
|
63
|
+
end
|
64
|
+
|
56
65
|
# If you need to store any of the defined attributes in the authorization you
|
57
66
|
# can do it here.
|
58
67
|
#
|
@@ -60,7 +69,7 @@ class DummyAuthorizationHandler < Decidim::AuthorizationHandler
|
|
60
69
|
# it's created, and available though authorization.metadata
|
61
70
|
#
|
62
71
|
def metadata
|
63
|
-
super.merge(document_number: document_number, postal_code: postal_code)
|
72
|
+
super.merge(document_number: document_number, postal_code: postal_code, scope_id: scope_id)
|
64
73
|
end
|
65
74
|
|
66
75
|
private
|
@@ -69,19 +78,25 @@ class DummyAuthorizationHandler < Decidim::AuthorizationHandler
|
|
69
78
|
errors.add(:document_number, :invalid) unless document_number.to_s.end_with?("X")
|
70
79
|
end
|
71
80
|
|
81
|
+
def valid_scope_id
|
82
|
+
errors.add(:scope_id, :invalid) if scope_id && !scope
|
83
|
+
end
|
84
|
+
|
72
85
|
# If you need custom authorization logic, you can implement your own action
|
73
86
|
# authorizer. In this case, it allows to set a list of valid postal codes for
|
74
87
|
# an authorization.
|
75
88
|
class DummyActionAuthorizer < Decidim::Verifications::DefaultActionAuthorizer
|
76
|
-
attr_reader :allowed_postal_codes
|
89
|
+
attr_reader :allowed_postal_codes, :allowed_scope_id
|
77
90
|
|
78
91
|
# Overrides the parent class method, but it still uses it to keep the base behavior
|
79
92
|
def authorize
|
80
93
|
# Remove the additional setting from the options hash to avoid to be considered missing.
|
81
|
-
@allowed_postal_codes ||= options.delete("allowed_postal_codes")
|
94
|
+
@allowed_postal_codes ||= options.delete("allowed_postal_codes")&.split(/[\W,;]+/)
|
95
|
+
@allowed_scope_id ||= options.delete("allowed_scope_id")&.to_i
|
82
96
|
|
83
97
|
status_code, data = *super
|
84
98
|
|
99
|
+
extra_explanations = []
|
85
100
|
if allowed_postal_codes.present?
|
86
101
|
# Does not authorize users with different postal codes
|
87
102
|
if status_code == :ok && !allowed_postal_codes.member?(authorization.metadata["postal_code"])
|
@@ -90,18 +105,47 @@ class DummyAuthorizationHandler < Decidim::AuthorizationHandler
|
|
90
105
|
end
|
91
106
|
|
92
107
|
# Adds an extra message for inform the user the additional restriction for this authorization
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
108
|
+
extra_explanations << { key: "extra_explanation.postal_codes",
|
109
|
+
params: { scope: "decidim.verifications.dummy_authorization",
|
110
|
+
count: allowed_postal_codes.count,
|
111
|
+
postal_codes: allowed_postal_codes.join(", ") } }
|
112
|
+
end
|
113
|
+
|
114
|
+
if allowed_scope.present?
|
115
|
+
# Does not authorize users with different scope
|
116
|
+
if status_code == :ok && allowed_scope_id != user_scope_id
|
117
|
+
status_code = :unauthorized
|
118
|
+
data[:fields] = { "scope_id" => user_scope.name[I18n.locale.to_s] }
|
119
|
+
end
|
120
|
+
|
121
|
+
# Adds an extra message to inform the user about additional restrictions for this authorization
|
122
|
+
extra_explanations << { key: "extra_explanation.scope",
|
123
|
+
params: { scope: "decidim.verifications.dummy_authorization",
|
124
|
+
scope_name: allowed_scope.name[I18n.locale.to_s] } }
|
97
125
|
end
|
98
126
|
|
127
|
+
data[:extra_explanation] = extra_explanations if extra_explanations.any?
|
128
|
+
|
99
129
|
[status_code, data]
|
100
130
|
end
|
101
131
|
|
102
|
-
# Adds the list of allowed postal codes to the redirect URL, to allow forms to inform about it
|
132
|
+
# Adds the list of allowed postal codes and scope to the redirect URL, to allow forms to inform about it
|
103
133
|
def redirect_params
|
104
|
-
{ "postal_codes" => allowed_postal_codes&.join("
|
134
|
+
{ "postal_codes" => allowed_postal_codes&.join(","), "scope" => allowed_scope_id }
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def allowed_scope
|
140
|
+
@allowed_scope ||= Decidim::Scope.find(allowed_scope_id) if allowed_scope_id
|
141
|
+
end
|
142
|
+
|
143
|
+
def user_scope
|
144
|
+
@user_scope ||= Decidim::Scope.find(user_scope_id) if user_scope_id
|
145
|
+
end
|
146
|
+
|
147
|
+
def user_scope_id
|
148
|
+
@user_scope_id ||= authorization.metadata["scope_id"]&.to_i
|
105
149
|
end
|
106
150
|
end
|
107
151
|
end
|
@@ -1,20 +1,105 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
Decidim.configure do |config|
|
4
|
+
# The name of the application
|
4
5
|
config.application_name = "My Application Name"
|
5
|
-
config.mailer_sender = "change-me@domain.org"
|
6
6
|
|
7
|
-
#
|
8
|
-
config.
|
7
|
+
# The email that will be used as sender in all emails from Decidim
|
8
|
+
config.mailer_sender = "change-me@example.org"
|
9
|
+
|
10
|
+
# Sets the list of available locales for the whole application.
|
11
|
+
#
|
12
|
+
# When an organization is created through the System area, system admins will
|
13
|
+
# be able to choose the available languages for that organization. That list
|
14
|
+
# of languages will be equal or a subset of the list in this file.
|
9
15
|
config.available_locales = [:en, :ca, :es]
|
10
16
|
|
11
|
-
#
|
17
|
+
# Sets the default locale for new organizations. When creating a new
|
18
|
+
# organization from the System area, system admins will be able to overwrite
|
19
|
+
# this value for that specific organization.
|
20
|
+
config.default_locale = :en
|
21
|
+
|
22
|
+
# Restrict access to the system part with an authorized ip list.
|
23
|
+
# You can use a single ip like ("1.2.3.4"), or an ip subnet like ("1.2.3.4/24")
|
24
|
+
# You may specify multiple ip in an array ["1.2.3.4", "1.2.3.4/24"]
|
25
|
+
# config.system_accesslist_ips = ["127.0.0.1"]
|
26
|
+
|
27
|
+
# Defines a list of custom content processors. They are used to parse and
|
28
|
+
# render specific tags inside some user-provided content. Check the docs for
|
29
|
+
# more info.
|
30
|
+
# config.content_processors = []
|
31
|
+
|
32
|
+
# Whether SSL should be enabled or not.
|
33
|
+
# config.force_ssl = true
|
34
|
+
|
35
|
+
# Map and Geocoder configuration
|
36
|
+
#
|
37
|
+
# == HERE Maps ==
|
38
|
+
# config.maps = {
|
39
|
+
# provider: :here,
|
40
|
+
# api_key: Rails.application.secrets.maps[:api_key],
|
41
|
+
# static: { url: "https://image.maps.ls.hereapi.com/mia/1.6/mapview" }
|
42
|
+
# }
|
43
|
+
#
|
44
|
+
# == OpenStreetMap (OSM) services ==
|
45
|
+
# To use the OSM map service providers, you will need a service provider for
|
46
|
+
# the following map servers or host all of them yourself:
|
47
|
+
# - A tile server for the dynamic maps
|
48
|
+
# (https://wiki.openstreetmap.org/wiki/Tile_servers)
|
49
|
+
# - A Nominatim geocoding server for the geocoding functionality
|
50
|
+
# (https://wiki.openstreetmap.org/wiki/Nominatim)
|
51
|
+
# - A static map server for static map images
|
52
|
+
# (https://github.com/jperelli/osm-static-maps)
|
53
|
+
#
|
54
|
+
# When used, please read carefully the terms of service for your service
|
55
|
+
# provider.
|
56
|
+
#
|
57
|
+
# config.maps = {
|
58
|
+
# provider: :osm,
|
59
|
+
# api_key: Rails.application.secrets.maps[:api_key],
|
60
|
+
# dynamic: {
|
61
|
+
# tile_layer: {
|
62
|
+
# url: "https://tiles.example.org/{z}/{x}/{y}.png?key={apiKey}&{foo}",
|
63
|
+
# api_key: true,
|
64
|
+
# foo: "bar=baz",
|
65
|
+
# attribution: %(
|
66
|
+
# <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap</a> contributors
|
67
|
+
# ).strip
|
68
|
+
# # Translatable attribution:
|
69
|
+
# # attribution: -> { I18n.t("tile_layer_attribution") }
|
70
|
+
# }
|
71
|
+
# },
|
72
|
+
# static: { url: "https://staticmap.example.org/" },
|
73
|
+
# geocoding: { host: "nominatim.example.org", use_https: true }
|
74
|
+
# }
|
75
|
+
#
|
76
|
+
# == Combination (OpenStreetMap default + HERE Maps dynamic map tiles) ==
|
77
|
+
# config.maps = {
|
78
|
+
# provider: :osm,
|
79
|
+
# api_key: Rails.application.secrets.maps[:api_key],
|
80
|
+
# dynamic: {
|
81
|
+
# provider: :here,
|
82
|
+
# api_key: Rails.application.secrets.maps[:here_api_key]
|
83
|
+
# },
|
84
|
+
# static: { url: "https://staticmap.example.org/" },
|
85
|
+
# geocoding: { host: "nominatim.example.org", use_https: true }
|
86
|
+
# }
|
87
|
+
|
88
|
+
# Geocoder configurations if you want to customize the default geocoding
|
89
|
+
# settings. The maps configuration will manage which geocoding service to use,
|
90
|
+
# so that does not need any additional configuration here. Use this only for
|
91
|
+
# the global geocoder preferences.
|
12
92
|
# config.geocoder = {
|
13
|
-
#
|
14
|
-
#
|
93
|
+
# # geocoding service request timeout, in seconds (default 3):
|
94
|
+
# timeout: 5,
|
95
|
+
# # set default units to kilometers:
|
96
|
+
# units: :km,
|
97
|
+
# # caching (see https://github.com/alexreisner/geocoder#caching for details):
|
98
|
+
# cache: Redis.new,
|
99
|
+
# cache_prefix: "..."
|
15
100
|
# }
|
16
101
|
|
17
|
-
# Custom resource reference generator method
|
102
|
+
# Custom resource reference generator method. Check the docs for more info.
|
18
103
|
# config.reference_generator = lambda do |resource, component|
|
19
104
|
# # Implement your custom method to generate resources references
|
20
105
|
# "1234-#{resource.id}"
|
@@ -23,7 +108,11 @@ Decidim.configure do |config|
|
|
23
108
|
# Currency unit
|
24
109
|
# config.currency_unit = "€"
|
25
110
|
|
26
|
-
#
|
111
|
+
# Defines the quality of image uploads after processing. Image uploads are
|
112
|
+
# processed by Decidim, this value helps reduce the size of the files.
|
113
|
+
# config.image_uploader_quality = 80
|
114
|
+
|
115
|
+
# The number of reports which a resource can receive before hiding it
|
27
116
|
# config.max_reports_before_hiding = 3
|
28
117
|
|
29
118
|
# Custom HTML Header snippets
|
@@ -41,6 +130,29 @@ Decidim.configure do |config|
|
|
41
130
|
#
|
42
131
|
config.enable_html_header_snippets = false
|
43
132
|
|
133
|
+
# Allow organizations admins to track newsletter links.
|
134
|
+
# config.track_newsletter_links = true
|
135
|
+
|
136
|
+
# Amount of time that the data portability files will be available in the server.
|
137
|
+
# config.data_portability_expiry_time = 7.days
|
138
|
+
|
139
|
+
# Max requests in a time period to prevent DoS attacks. Only applied on production.
|
140
|
+
# config.throttling_max_requests = 100
|
141
|
+
|
142
|
+
# Time window in which the throttling is applied.
|
143
|
+
# config.throttling_period = 1.minute
|
144
|
+
|
145
|
+
# Time window were users can access the website even if their email is not confirmed.
|
146
|
+
# config.unconfirmed_access_for = 2.days
|
147
|
+
|
148
|
+
# A base path for the uploads. If set, make sure it ends in a slash.
|
149
|
+
# Uploads will be set to `<base_path>/uploads/`. This can be useful if you
|
150
|
+
# want to use the same uploads place for both staging and production
|
151
|
+
# environments, but in different folders.
|
152
|
+
#
|
153
|
+
# If not set, it will be ignored.
|
154
|
+
# config.base_uploads_path = nil
|
155
|
+
|
44
156
|
# SMS gateway configuration
|
45
157
|
#
|
46
158
|
# If you want to verify your users by sending a verification code via
|
@@ -121,6 +233,51 @@ Decidim.configure do |config|
|
|
121
233
|
# api_key: Rails.application.secrets.etherpad[:api_key],
|
122
234
|
# api_version: Rails.application.secrets.etherpad[:api_version]
|
123
235
|
# }
|
236
|
+
|
237
|
+
# Sets Decidim::Exporters::CSV's default column separator
|
238
|
+
# config.default_csv_col_sep = ";"
|
239
|
+
|
240
|
+
# The list of roles a user can have, not considering the space-specific roles.
|
241
|
+
# config.user_roles = %w(admin user_manager)
|
242
|
+
|
243
|
+
# The list of visibility options for amendments. An Array of Strings that
|
244
|
+
# serve both as locale keys and values to construct the input collection in
|
245
|
+
# Decidim::Amendment::VisibilityStepSetting::options.
|
246
|
+
#
|
247
|
+
# This collection is used in Decidim::Admin::SettingsHelper to generate a
|
248
|
+
# radio buttons collection input field form for a Decidim::Component
|
249
|
+
# step setting :amendments_visibility.
|
250
|
+
# config.amendments_visibility_options = %w(all participants)
|
251
|
+
|
252
|
+
# Machine Translation Configuration
|
253
|
+
#
|
254
|
+
# Enable machine translations
|
255
|
+
config.enable_machine_translations = false
|
256
|
+
#
|
257
|
+
# If you want to enable machine translation you can create your own service
|
258
|
+
# to interact with third party service to translate the user content.
|
259
|
+
#
|
260
|
+
# An example class would be something like:
|
261
|
+
#
|
262
|
+
# class MyTranslationService
|
263
|
+
# attr_reader :text, :original_locale, :target_locale
|
264
|
+
#
|
265
|
+
# def initialize(text, original_locale, target_locale)
|
266
|
+
# @text = text
|
267
|
+
# @original_locale = original_locale
|
268
|
+
# @target_locale = target_locale
|
269
|
+
# end
|
270
|
+
#
|
271
|
+
# def translate
|
272
|
+
# # Actual code to translate the text
|
273
|
+
# end
|
274
|
+
# end
|
275
|
+
#
|
276
|
+
# config.machine_translation_service = "MyTranslationService"
|
277
|
+
|
278
|
+
# Defines the name of the cookie used to check if the user allows Decidim to
|
279
|
+
# set cookies.
|
280
|
+
# config.consent_cookie_name = "decidim-cc"
|
124
281
|
end
|
125
282
|
|
126
283
|
Rails.application.config.i18n.available_locales = Decidim.available_locales
|