decidim-generators 0.22.0 → 0.23.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,7 +115,7 @@ module Decidim
111
115
  if current_gem == "decidim"
112
116
  gsub_file "Gemfile", /gem "decidim-dev".*/, "gem \"decidim-dev\", #{gem_modifier}"
113
117
 
114
- %w(conferences consultations elections initiatives).each do |component|
118
+ %w(conferences consultations elections initiatives templates).each do |component|
115
119
  if options[:demo]
116
120
  gsub_file "Gemfile", /gem "decidim-#{component}".*/, "gem \"decidim-#{component}\", #{gem_modifier}"
117
121
  else
@@ -170,6 +174,15 @@ module Decidim
170
174
  "config.sms_gateway_service = 'Decidim::Verifications::Sms::ExampleGateway'"
171
175
  end
172
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
+
173
186
  def timestamp_service
174
187
  return unless options[:demo]
175
188
 
@@ -186,13 +199,22 @@ module Decidim
186
199
  "config.pdf_signature_service = \"Decidim::Initiatives::PdfSignatureExample\""
187
200
  end
188
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
+
189
210
  def install
190
211
  Decidim::Generators::InstallGenerator.start(
191
212
  [
192
213
  "--recreate_db=#{options[:recreate_db]}",
193
214
  "--seed_db=#{options[:seed_db]}",
194
215
  "--skip_gemfile=#{options[:skip_gemfile]}",
195
- "--app_name=#{app_name}"
216
+ "--app_name=#{app_name}",
217
+ "--profiling=#{options[:profiling]}"
196
218
  ]
197
219
  )
198
220
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "budgets_workflow_random"
4
+ Decidim::Budgets.workflows[:random] = BudgetsWorkflowRandom
@@ -0,0 +1,8 @@
1
+ en:
2
+ decidim:
3
+ components:
4
+ budgets:
5
+ settings:
6
+ global:
7
+ workflow_choices:
8
+ random: "Vote in a random component: allows participants to vote only in one budget, selected randomly."
@@ -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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined?(Bullet)
4
+ Rails.application.config.after_initialize do
5
+ Bullet.enable = true
6
+ Bullet.bullet_logger = true
7
+ Bullet.rails_logger = true
8
+ Bullet.stacktrace_includes = %w(decidim-)
9
+ end
10
+ 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
- data[:extra_explanation] = { key: "extra_explanation",
94
- params: { scope: "decidim.verifications.dummy_authorization",
95
- count: allowed_postal_codes.count,
96
- postal_codes: allowed_postal_codes.join(", ") } }
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
@@ -5,7 +5,7 @@ Decidim.configure do |config|
5
5
  config.application_name = "My Application Name"
6
6
 
7
7
  # The email that will be used as sender in all emails from Decidim
8
- config.mailer_sender = "change-me@domain.org"
8
+ config.mailer_sender = "change-me@example.org"
9
9
 
10
10
  # Sets the list of available locales for the whole application.
11
11
  #
@@ -14,16 +14,16 @@ Decidim.configure do |config|
14
14
  # of languages will be equal or a subset of the list in this file.
15
15
  config.available_locales = [:en, :ca, :es]
16
16
 
17
- # Restrict access to the system part with an authorized ip list.
18
- # You can use a single ip like ("1.2.3.4"), or an ip subnet like ("1.2.3.4/24")
19
- # You may specify multiple ip in an array ["1.2.3.4", "1.2.3.4/24"]
20
- # config.system_accesslist_ips = ["127.0.0.1"]
21
-
22
17
  # Sets the default locale for new organizations. When creating a new
23
18
  # organization from the System area, system admins will be able to overwrite
24
19
  # this value for that specific organization.
25
20
  config.default_locale = :en
26
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
27
  # Defines a list of custom content processors. They are used to parse and
28
28
  # render specific tags inside some user-provided content. Check the docs for
29
29
  # more info.
@@ -32,10 +32,71 @@ Decidim.configure do |config|
32
32
  # Whether SSL should be enabled or not.
33
33
  # config.force_ssl = true
34
34
 
35
- # Geocoder configuration
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">&copy; 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.
36
92
  # config.geocoder = {
37
- # static_map_url: "https://image.maps.ls.hereapi.com/mia/1.6/mapview",
38
- # here_api_key: Rails.application.secrets.geocoder[:here_api_key]
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: "..."
39
100
  # }
40
101
 
41
102
  # Custom resource reference generator method. Check the docs for more info.
@@ -51,12 +112,6 @@ Decidim.configure do |config|
51
112
  # processed by Decidim, this value helps reduce the size of the files.
52
113
  # config.image_uploader_quality = 80
53
114
 
54
- # The maximum file size of an attachment
55
- # config.maximum_attachment_size = 10.megabytes
56
-
57
- # The maximum file size for a user avatar
58
- # config.maximum_avatar_size = 10.megabytes
59
-
60
115
  # The number of reports which a resource can receive before hiding it
61
116
  # config.max_reports_before_hiding = 3
62
117
 
@@ -90,13 +145,6 @@ Decidim.configure do |config|
90
145
  # Time window were users can access the website even if their email is not confirmed.
91
146
  # config.unconfirmed_access_for = 2.days
92
147
 
93
- # Etherpad configuration. Check the docs for more info.
94
- # config.etherpad = {
95
- # server: <your url>,
96
- # api_key: <your key>,
97
- # api_version: <your version>
98
- # }
99
-
100
148
  # A base path for the uploads. If set, make sure it ends in a slash.
101
149
  # Uploads will be set to `<base_path>/uploads/`. This can be useful if you
102
150
  # want to use the same uploads place for both staging and production
@@ -200,6 +248,36 @@ Decidim.configure do |config|
200
248
  # radio buttons collection input field form for a Decidim::Component
201
249
  # step setting :amendments_visibility.
202
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"
203
281
  end
204
282
 
205
283
  Rails.application.config.i18n.available_locales = Decidim.available_locales
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Rails.env.development?
4
+ require "rack-mini-profiler"
5
+
6
+ # initialization is skipped so trigger it
7
+ Rack::MiniProfilerRails.initialize!(Rails.application)
8
+ end
@@ -26,12 +26,17 @@ default: &default
26
26
  icon_path: decidim/brands/google.svg
27
27
  client_id: <%%= ENV["OMNIAUTH_GOOGLE_CLIENT_ID"] %>
28
28
  client_secret: <%%= ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"] %>
29
- geocoder:
30
- here_api_key: <%%= ENV["GEOCODER_API_KEY"] %>
29
+ maps:
30
+ api_key: <%%= ENV["MAPS_API_KEY"] %>
31
31
  etherpad:
32
32
  server: <%%= ENV["ETHERPAD_SERVER"] %>
33
33
  api_key: <%%= ENV["ETHERPAD_API_KEY"] %>
34
34
  api_version: "1.2.1"
35
+ bulletin_board:
36
+ identification_private_key: |
37
+ <%= ENV["BULLETIN_BOARD_IDENTIFICATION_PRIVATE_KEY"]&.indent(6) %>
38
+ server: <%= ENV["BULLETIN_BOARD_SERVER"] %>
39
+ api_key: <%= ENV["BULLETIN_BOARD_API_KEY"] %>
35
40
 
36
41
  development:
37
42
  <<: *default
@@ -3,18 +3,19 @@
3
3
  Decidim::Verifications.register_workflow(:dummy_authorization_handler) do |workflow|
4
4
  workflow.form = "DummyAuthorizationHandler"
5
5
  workflow.action_authorizer = "DummyAuthorizationHandler::DummyActionAuthorizer"
6
- workflow.expires_in = 1.hour
6
+ workflow.expires_in = 1.month
7
7
  workflow.renewable = true
8
8
  workflow.time_between_renewals = 5.minutes
9
9
 
10
10
  workflow.options do |options|
11
- options.attribute :postal_code, type: :string, default: "08001", required: false
11
+ options.attribute :allowed_postal_codes, type: :string, default: "08001", required: false
12
+ options.attribute :allowed_scope_id, type: :scope, required: false
12
13
  end
13
14
  end
14
15
 
15
16
  Decidim::Verifications.register_workflow(:another_dummy_authorization_handler) do |workflow|
16
17
  workflow.form = "AnotherDummyAuthorizationHandler"
17
- workflow.expires_in = 1.hour
18
+ workflow.expires_in = 1.month
18
19
 
19
20
  workflow.options do |options|
20
21
  options.attribute :passport_number, type: :string, required: false