decidim-decidim_awesome 0.12.0 → 0.12.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/CHANGELOG.md +45 -0
- data/README.md +25 -15
- data/Rakefile +12 -0
- data/app/cells/concerns/decidim/decidim_awesome/global_menu_cell_override.rb +14 -2
- data/app/cells/concerns/decidim/decidim_awesome/proposal_l_cell_override.rb +5 -4
- data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal/show.erb +3 -3
- data/app/cells/decidim/decidim_awesome/voting/voting_cards_proposal/vote_block_for.erb +1 -1
- data/app/commands/concerns/decidim/decidim_awesome/admin/needs_constraint_helpers.rb +39 -5
- data/app/commands/decidim/decidim_awesome/admin/create_authorization_group.rb +42 -0
- data/app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb +10 -14
- data/app/commands/decidim/decidim_awesome/admin/create_menu_hack.rb +9 -8
- data/app/commands/decidim/decidim_awesome/admin/create_proposal_custom_field.rb +3 -8
- data/app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb +4 -8
- data/app/commands/decidim/decidim_awesome/admin/create_scoped_style.rb +3 -7
- data/app/commands/decidim/decidim_awesome/admin/destroy_authorization_group.rb +37 -0
- data/app/commands/decidim/decidim_awesome/admin/destroy_custom_redirect.rb +10 -9
- data/app/commands/decidim/decidim_awesome/admin/destroy_menu_hack.rb +8 -7
- data/app/commands/decidim/decidim_awesome/admin/destroy_proposal_custom_field.rb +7 -13
- data/app/commands/decidim/decidim_awesome/admin/destroy_scoped_admin.rb +7 -10
- data/app/commands/decidim/decidim_awesome/admin/destroy_scoped_style.rb +6 -11
- data/app/commands/decidim/decidim_awesome/admin/update_config.rb +12 -1
- data/app/commands/decidim/decidim_awesome/admin/update_custom_redirect.rb +11 -11
- data/app/commands/decidim/decidim_awesome/admin/update_menu_hack.rb +10 -8
- data/app/controllers/concerns/decidim/decidim_awesome/admin/maintenance_context.rb +0 -28
- data/app/controllers/concerns/decidim/decidim_awesome/enforce_access_authorizations.rb +49 -0
- data/app/controllers/concerns/decidim/decidim_awesome/needs_hashcash.rb +43 -0
- data/app/controllers/concerns/decidim/decidim_awesome/not_found_redirect.rb +2 -2
- data/app/controllers/decidim/decidim_awesome/admin/admin_authorizations_controller.rb +2 -2
- data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +0 -4
- data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +2 -1
- data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +2 -0
- data/app/controllers/decidim/decidim_awesome/admin/custom_redirects_controller.rb +1 -2
- data/app/controllers/decidim/decidim_awesome/admin/force_authorizations_controller.rb +44 -0
- data/app/controllers/decidim/decidim_awesome/admin/hashcash_controller.rb +39 -0
- data/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb +1 -1
- data/app/controllers/decidim/decidim_awesome/admin/{maintenance_controller.rb → private_data_controller.rb} +9 -9
- data/app/controllers/decidim/decidim_awesome/required_authorizations_controller.rb +51 -13
- data/app/controllers/decidim/decidim_awesome/utils_controller.rb +17 -0
- data/app/forms/concerns/decidim/decidim_awesome/proposals/admin/proposal_form_customizations.rb +59 -0
- data/app/forms/concerns/decidim/decidim_awesome/proposals/proposal_form_customizations.rb +28 -28
- data/app/forms/concerns/decidim/decidim_awesome/proposals/proposal_form_customizations_base.rb +36 -0
- data/app/forms/concerns/decidim/decidim_awesome/proposals/proposal_form_override.rb +7 -1
- data/app/forms/decidim/decidim_awesome/admin/authorization_group_form.rb +66 -0
- data/app/forms/decidim/decidim_awesome/admin/config_form.rb +23 -24
- data/app/forms/decidim/decidim_awesome/admin/constraint_form.rb +2 -0
- data/app/helpers/concerns/decidim/decidim_awesome/amendments_helper_override.rb +2 -1
- data/app/helpers/decidim/decidim_awesome/admin/config_constraints_helpers.rb +21 -18
- data/app/helpers/decidim/decidim_awesome/map_helper.rb +4 -2
- data/app/models/decidim/decidim_awesome/paper_trail_version.rb +1 -1
- data/app/overrides/decidim/assemblies/admin/assemblies/_form/add_visibility_callout.html.erb.deface +3 -0
- data/app/overrides/decidim/conferences/admin/conferences/_form/add_visibility_callout.html.erb.deface +3 -0
- data/app/overrides/decidim/devise/registrations/new/add_hashcash.html.erb.deface +3 -0
- data/app/overrides/decidim/devise/sessions/new/add_hashcash.html.erb.deface +3 -0
- data/app/overrides/decidim/participatory_processes/admin/participatory_process_groups/_form/add_visibility_callout.html.erb.deface +3 -0
- data/app/overrides/decidim/participatory_processes/admin/participatory_processes/_form/add_visibility_callout.html.erb.deface +3 -0
- data/app/overrides/decidim/shared/_login_modal/add_hashcash.html.erb.deface +3 -0
- data/app/overrides/layouts/decidim/_head/add_awesome_custom_styles.html.erb.deface +3 -0
- data/app/overrides/layouts/decidim/_head/add_awesome_tags.html.erb.deface +0 -2
- data/app/packs/entrypoints/decidim_decidim_awesome_hashcash.js +4 -0
- data/app/packs/src/decidim/decidim_awesome/admin/auto_edit.js +25 -6
- data/app/packs/src/decidim/decidim_awesome/admin/custom_fields_builder.js +4 -2
- data/app/packs/src/decidim/decidim_awesome/admin/verifications.js +6 -3
- data/app/packs/src/decidim/decidim_awesome/awesome_admin.js +0 -1
- data/app/packs/src/decidim/decidim_awesome/awesome_map/api/proposals_fetcher.js +1 -1
- data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/controller.js +1 -1
- data/app/packs/src/decidim/decidim_awesome/awesome_map/controllers/proposals_controller.js +1 -1
- data/app/packs/src/decidim/decidim_awesome/awesome_map/controls_ui.js +6 -6
- data/app/packs/src/decidim/decidim_awesome/awesome_map/load_map.js +1 -1
- data/app/packs/src/decidim/decidim_awesome/forms/autosave.js +3 -3
- data/app/packs/src/decidim/decidim_awesome/forms/custom_fields_renderer.js +1 -113
- data/app/packs/src/decidim/decidim_awesome/proposals/images.js +1 -1
- data/app/packs/src/vendor/form_builder_langs/ar-SA.lang +111 -0
- data/app/packs/src/vendor/form_builder_langs/ar-TN.lang +94 -0
- data/app/packs/src/vendor/form_builder_langs/ca-ES.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/cs-CZ.lang +105 -0
- data/app/packs/src/vendor/form_builder_langs/da-DK.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/de-DE.lang +109 -0
- data/app/packs/src/vendor/form_builder_langs/el-GR.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/en-US.lang +117 -0
- data/app/packs/src/vendor/form_builder_langs/es-ES.lang +103 -0
- data/app/packs/src/vendor/form_builder_langs/fa-IR.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/fi-FI.lang +107 -0
- data/app/packs/src/vendor/form_builder_langs/fr-FR.lang +117 -0
- data/app/packs/src/vendor/form_builder_langs/he-IL.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/hi-IN.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/hu-HU.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/id-ID.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/it-IT.lang +107 -0
- data/app/packs/src/vendor/form_builder_langs/ja-JP.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/my-MM.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/nb-NO.lang +94 -0
- data/app/packs/src/vendor/form_builder_langs/nl-NL.lang +94 -0
- data/app/packs/src/vendor/form_builder_langs/pl-PL.lang +122 -0
- data/app/packs/src/vendor/form_builder_langs/pt-BR.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/pu-IN.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/qz-MM.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/ro-RO.lang +94 -0
- data/app/packs/src/vendor/form_builder_langs/ru-RU.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/sl-SI.lang +110 -0
- data/app/packs/src/vendor/form_builder_langs/th-TH.lang +111 -0
- data/app/packs/src/vendor/form_builder_langs/tr-TR.lang +115 -0
- data/app/packs/src/vendor/form_builder_langs/uk-UA.lang +108 -0
- data/app/packs/src/vendor/form_builder_langs/vi-VN.lang +94 -0
- data/app/packs/src/vendor/form_builder_langs/zh-CN.lang +100 -0
- data/app/packs/src/vendor/form_builder_langs/zh-TW.lang +94 -0
- data/app/packs/src/vendor/hashcash.js +83 -0
- data/app/packs/src/vendor/sha1.js +143 -0
- data/app/packs/src/vendor/stamp.js +50 -0
- data/app/packs/stylesheets/decidim/decidim_awesome/admin/codemirror.scss +6 -1
- data/app/packs/stylesheets/decidim/decidim_awesome/admin/constraints.scss +5 -0
- data/app/packs/stylesheets/decidim/decidim_awesome/admin/custom_fields.scss +1 -2
- data/app/packs/stylesheets/decidim/decidim_awesome/forms/autosave.scss +2 -12
- data/app/presenters/decidim/decidim_awesome/private_data_presenter.rb +2 -2
- data/app/queries/decidim/decidim_awesome/space_constraint_finder.rb +43 -0
- data/app/serializers/concerns/decidim/decidim_awesome/proposals/proposal_serializer_methods.rb +3 -2
- data/app/services/decidim/decidim_awesome/access_authorization_service.rb +79 -0
- data/app/types/concerns/decidim/decidim_awesome/add_proposal_type_custom_fields.rb +2 -1
- data/app/views/decidim/decidim_awesome/admin/admin_accountability/index.html.erb +4 -4
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/callout.html.erb +2 -2
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/conflict.html.erb +4 -4
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/edit.html.erb +6 -5
- data/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +6 -6
- data/app/views/decidim/decidim_awesome/admin/config/_authorization_options_form.html.erb +19 -0
- data/app/views/decidim/decidim_awesome/admin/config/_autoedit_box_label.html.erb +2 -2
- data/app/views/decidim/decidim_awesome/admin/config/_constraints.html.erb +3 -3
- data/app/views/decidim/decidim_awesome/admin/config/_form_admins.html.erb +4 -3
- data/app/views/decidim/decidim_awesome/admin/config/_form_editors.html.erb +1 -1
- data/app/views/decidim/decidim_awesome/admin/config/_form_proposal_custom_fields.html.erb +4 -4
- data/app/views/decidim/decidim_awesome/admin/config/_form_scoped_styles.html.erb +3 -3
- data/app/views/decidim/decidim_awesome/admin/config/_form_surveys.html.erb +40 -2
- data/app/views/decidim/decidim_awesome/admin/config/_form_verifications.html.erb +71 -9
- data/app/views/decidim/decidim_awesome/admin/constraints/_form.html.erb +5 -4
- data/app/views/decidim/decidim_awesome/admin/hashcash/_filters.html.erb +55 -0
- data/app/views/decidim/decidim_awesome/admin/hashcash/index.html.erb +33 -0
- data/app/views/decidim/decidim_awesome/admin/hashcash/ip_addresses.html.erb +29 -0
- data/app/views/decidim/decidim_awesome/admin/hashcash/show.html.erb +42 -0
- data/app/views/decidim/decidim_awesome/admin/menu_hacks/index.html.erb +2 -2
- data/app/views/decidim/decidim_awesome/admin/{maintenance → private_data}/_private_data.html.erb +2 -2
- data/app/views/decidim/decidim_awesome/admin/{maintenance/show.html.erb → private_data/index.html.erb} +2 -3
- data/app/views/decidim/decidim_awesome/admin/proposals/_private_body.html.erb +1 -1
- data/app/views/decidim/decidim_awesome/admin/shared/_visibility_notice.html.erb +8 -0
- data/app/views/decidim/decidim_awesome/amendments/_modal.html.erb +2 -2
- data/app/views/decidim/decidim_awesome/hashcash/_hidden_field.html.erb +4 -0
- data/app/views/decidim/decidim_awesome/required_authorizations/index.html.erb +14 -4
- data/app/views/layouts/decidim/decidim_awesome/_awesome_config.html.erb +2 -2
- data/app/views/layouts/decidim/decidim_awesome/admin/maintenance.html.erb +2 -11
- data/config/assets.rb +1 -0
- data/config/i18n-tasks.yml +2 -0
- data/config/locales/ca.yml +100 -37
- data/config/locales/cs.yml +100 -36
- data/config/locales/de.yml +98 -35
- data/config/locales/en.yml +117 -44
- data/config/locales/es.yml +100 -36
- data/config/locales/eu.yml +34 -39
- data/config/locales/fr.yml +77 -31
- data/config/locales/ja.yml +99 -36
- data/config/locales/sv.yml +49 -0
- data/lib/decidim/decidim_awesome/admin_engine.rb +9 -5
- data/lib/decidim/decidim_awesome/{authorizator.rb → authorizer.rb} +1 -1
- data/lib/decidim/decidim_awesome/awesome.rb +34 -24
- data/lib/decidim/decidim_awesome/awesome_helpers.rb +14 -5
- data/lib/decidim/decidim_awesome/checksums.yml +26 -40
- data/lib/decidim/decidim_awesome/config.rb +18 -7
- data/lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb +1 -1
- data/lib/decidim/decidim_awesome/engine.rb +14 -3
- data/lib/decidim/decidim_awesome/menu.rb +151 -138
- data/lib/decidim/decidim_awesome/middleware/current_config.rb +5 -10
- data/lib/decidim/decidim_awesome/test/initializer.rb +5 -2
- data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +1 -3
- data/lib/decidim/decidim_awesome/test/shared_examples/editor_examples.rb +2 -1
- data/lib/decidim/decidim_awesome/test/shared_examples/proposal_form_examples.rb +191 -0
- data/lib/decidim/decidim_awesome/test/shared_examples/summary_examples.rb +15 -4
- data/lib/decidim/decidim_awesome/version.rb +1 -1
- data/lib/tasks/decidim_awesome_upgrade_tasks.rake +4 -1
- data/package.json +7 -8
- metadata +86 -13
- data/app/controllers/concerns/decidim/decidim_awesome/check_login_authorizations.rb +0 -60
- data/app/packs/src/decidim/decidim_awesome/admin/verification_selects.js +0 -21
- data/config/rubocop/disabled.yml +0 -11
- data/config/rubocop/faker.yml +0 -480
- data/config/rubocop/rails.yml +0 -88
- data/config/rubocop/rspec.yml +0 -65
- data/config/rubocop/ruby.yml +0 -1210
@@ -4,12 +4,13 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class DestroyProposalCustomField < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
|
-
# key - the key to destroy
|
10
|
+
# key - the key to destroy init proposal_custom_fields
|
10
11
|
# organization
|
11
12
|
def initialize(key, organization, config_var = :proposal_custom_fields)
|
12
|
-
@
|
13
|
+
@ident = key
|
13
14
|
@organization = organization
|
14
15
|
@config_var = config_var
|
15
16
|
end
|
@@ -21,19 +22,12 @@ module Decidim
|
|
21
22
|
#
|
22
23
|
# Returns nothing.
|
23
24
|
def call
|
24
|
-
|
25
|
-
return broadcast(:invalid, "
|
26
|
-
return broadcast(:invalid, "#{key} key invalid") unless fields.value.has_key?(@key)
|
25
|
+
return broadcast(:invalid, "Not a hash") unless find_var&.value.is_a? Hash
|
26
|
+
return broadcast(:invalid, "#{ident} key invalid") unless find_var.value.has_key?(ident)
|
27
27
|
|
28
|
-
|
29
|
-
fields.save!
|
28
|
+
destroy_hash_ident!
|
30
29
|
|
31
|
-
|
32
|
-
constraint = @config_var == :proposal_custom_fields ? :proposal_custom_field : :proposal_private_custom_field
|
33
|
-
constraint = AwesomeConfig.find_by(var: "#{constraint}_#{@key}", organization: @organization)
|
34
|
-
constraint.destroy! if constraint.present?
|
35
|
-
|
36
|
-
broadcast(:ok, @key)
|
30
|
+
broadcast(:ok, ident)
|
37
31
|
rescue StandardError => e
|
38
32
|
broadcast(:invalid, e.message)
|
39
33
|
end
|
@@ -4,13 +4,15 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class DestroyScopedAdmin < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
# key - the key to destroy inside scoped_admins
|
10
11
|
# organization
|
11
12
|
def initialize(key, organization)
|
12
|
-
@
|
13
|
+
@ident = key
|
13
14
|
@organization = organization
|
15
|
+
@config_var = :scoped_admins
|
14
16
|
end
|
15
17
|
|
16
18
|
# Executes the command. Broadcasts these events:
|
@@ -20,17 +22,12 @@ module Decidim
|
|
20
22
|
#
|
21
23
|
# Returns nothing.
|
22
24
|
def call
|
23
|
-
|
24
|
-
return broadcast(:invalid, "
|
25
|
-
return broadcast(:invalid, "#{key} key invalid") unless admins.value.has_key?(@key)
|
25
|
+
return broadcast(:invalid, "Not a hash") unless find_var&.value.is_a? Hash
|
26
|
+
return broadcast(:invalid, "#{ident} key invalid") unless find_var.value.has_key?(ident)
|
26
27
|
|
27
|
-
|
28
|
-
admins.save!
|
29
|
-
# remove constrains associated (a new config var is generated automatically, by removing it, it will trigger destroy on dependents)
|
30
|
-
constraint = AwesomeConfig.find_by(var: "scoped_admin_#{@key}", organization: @organization)
|
31
|
-
constraint.destroy! if constraint.present?
|
28
|
+
destroy_hash_ident!
|
32
29
|
|
33
|
-
broadcast(:ok,
|
30
|
+
broadcast(:ok, ident)
|
34
31
|
rescue StandardError => e
|
35
32
|
broadcast(:invalid, e.message)
|
36
33
|
end
|
@@ -4,12 +4,13 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class DestroyScopedStyle < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
# key - the key to destroy inside scoped_styles/scoped_admin_styles
|
10
11
|
# organization
|
11
12
|
def initialize(key, organization, config_var = :scoped_styles)
|
12
|
-
@
|
13
|
+
@ident = key
|
13
14
|
@organization = organization
|
14
15
|
@config_var = config_var
|
15
16
|
end
|
@@ -21,18 +22,12 @@ module Decidim
|
|
21
22
|
#
|
22
23
|
# Returns nothing.
|
23
24
|
def call
|
24
|
-
|
25
|
-
return broadcast(:invalid, "
|
26
|
-
return broadcast(:invalid, "#{key} key invalid") unless styles.value.has_key?(@key)
|
25
|
+
return broadcast(:invalid, "Not a hash") unless find_var&.value.is_a? Hash
|
26
|
+
return broadcast(:invalid, "#{ident} key invalid") unless find_var.value.has_key?(ident)
|
27
27
|
|
28
|
-
|
29
|
-
styles.save!
|
30
|
-
# remove constrains associated (a new config var is generated automatically, by removing it, it will trigger destroy on dependents)
|
31
|
-
constraint = @config_var == :scoped_styles ? :scoped_style : :scoped_admin_style
|
32
|
-
constraint = AwesomeConfig.find_by(var: "#{constraint}_#{@key}", organization: @organization)
|
33
|
-
constraint.destroy! if constraint.present?
|
28
|
+
destroy_hash_ident!
|
34
29
|
|
35
|
-
broadcast(:ok,
|
30
|
+
broadcast(:ok, ident)
|
36
31
|
rescue StandardError => e
|
37
32
|
broadcast(:invalid, e.message)
|
38
33
|
end
|
@@ -30,7 +30,18 @@ module Decidim
|
|
30
30
|
next unless form.valid_keys.include?(key.to_sym)
|
31
31
|
|
32
32
|
setting = AwesomeConfig.find_or_initialize_by(var: key, organization: form.current_organization)
|
33
|
-
|
33
|
+
|
34
|
+
value = if form.respond_to?("#{key}_attributes")
|
35
|
+
# for complex cases
|
36
|
+
form.public_send("#{key}_attributes")
|
37
|
+
elsif val.respond_to?(:attributes)
|
38
|
+
# when the value is another form
|
39
|
+
val.attributes
|
40
|
+
else
|
41
|
+
val
|
42
|
+
end
|
43
|
+
|
44
|
+
setting.value = value
|
34
45
|
setting.save!
|
35
46
|
end
|
36
47
|
|
@@ -4,12 +4,14 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class UpdateCustomRedirect < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
def initialize(form, item)
|
10
11
|
@form = form
|
11
12
|
@item = item
|
12
|
-
@
|
13
|
+
@config_var = :custom_redirects
|
14
|
+
@organization = form.current_organization
|
13
15
|
end
|
14
16
|
|
15
17
|
# Executes the command. Broadcasts these events:
|
@@ -22,26 +24,24 @@ module Decidim
|
|
22
24
|
return broadcast(:invalid) if form.invalid?
|
23
25
|
return broadcast(:invalid, I18n.t("custom_redirects.origin_missing", scope: "decidim.decidim_awesome.admin")) unless url_exists?
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
find_var.value&.except!(item.origin)
|
28
|
+
find_var.value[form.to_params[0]] = form.to_params[1]
|
29
|
+
find_var.save!
|
28
30
|
|
29
|
-
broadcast(:ok,
|
31
|
+
broadcast(:ok, find_var)
|
30
32
|
rescue StandardError => e
|
31
33
|
broadcast(:invalid, e.message)
|
32
34
|
end
|
33
35
|
|
34
36
|
private
|
35
37
|
|
36
|
-
attr_reader :form, :
|
37
|
-
|
38
|
-
delegate :to_params, to: :form
|
38
|
+
attr_reader :form, :item
|
39
39
|
|
40
40
|
def url_exists?
|
41
|
-
return false unless
|
42
|
-
return false unless
|
41
|
+
return false unless find_var
|
42
|
+
return false unless find_var.value.is_a? Hash
|
43
43
|
|
44
|
-
|
44
|
+
find_var.value[item.origin].present?
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -4,11 +4,13 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class UpdateMenuHack < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
def initialize(form, menu_name)
|
10
11
|
@form = form
|
11
|
-
@
|
12
|
+
@config_var = menu_name
|
13
|
+
@organization = form.current_organization
|
12
14
|
end
|
13
15
|
|
14
16
|
# Executes the command. Broadcasts these events:
|
@@ -20,10 +22,10 @@ module Decidim
|
|
20
22
|
def call
|
21
23
|
return broadcast(:invalid) if form.invalid?
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
find_var.value = [] unless find_var.value.is_a? Array
|
26
|
+
find_var.value = find_var.value.filter { |i| i.is_a? Hash }
|
25
27
|
found = false
|
26
|
-
|
28
|
+
find_var.value.map! do |item|
|
27
29
|
if item["url"] == form.url
|
28
30
|
found = true
|
29
31
|
form.to_params
|
@@ -31,16 +33,16 @@ module Decidim
|
|
31
33
|
item
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
|
-
|
36
|
-
broadcast(:ok,
|
36
|
+
find_var.value << form.to_params unless found
|
37
|
+
find_var.save!
|
38
|
+
broadcast(:ok, find_var)
|
37
39
|
rescue StandardError => e
|
38
40
|
broadcast(:invalid, e.message)
|
39
41
|
end
|
40
42
|
|
41
43
|
private
|
42
44
|
|
43
|
-
attr_reader :form
|
45
|
+
attr_reader :form
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
@@ -8,34 +8,6 @@ module Decidim
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
layout "decidim/decidim_awesome/admin/maintenance"
|
11
|
-
helper_method :current_view, :available_views, :present_private_data
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def present_private_data(model)
|
16
|
-
PrivateDataPresenter.new(model)
|
17
|
-
end
|
18
|
-
|
19
|
-
def current_view
|
20
|
-
return params[:id] if available_views.include?(params[:id])
|
21
|
-
|
22
|
-
available_views.keys.first
|
23
|
-
end
|
24
|
-
|
25
|
-
def available_views
|
26
|
-
{
|
27
|
-
"private_data" => {
|
28
|
-
title: I18n.t("private_data", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
|
29
|
-
icon: "spy-line",
|
30
|
-
path: decidim_admin_decidim_awesome.maintenance_path("private_data")
|
31
|
-
},
|
32
|
-
"checks" => {
|
33
|
-
title: I18n.t("checks", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
|
34
|
-
icon: "pulse",
|
35
|
-
path: decidim_admin_decidim_awesome.checks_maintenance_index_path
|
36
|
-
}
|
37
|
-
}
|
38
|
-
end
|
39
11
|
end
|
40
12
|
end
|
41
13
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module EnforceAccessAuthorizations
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ::Decidim::DecidimAwesome::NeedsAwesomeConfig
|
10
|
+
before_action :enforce_authorizations
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def enforce_authorizations
|
16
|
+
return if skip_enforcement_for_current_request?
|
17
|
+
|
18
|
+
unless service.granted?
|
19
|
+
flash[:alert] = I18n.t("decidim.decidim_awesome.session.authorization_is_required",
|
20
|
+
authorizations: service.adapters.map(&:fullname).join(", "))
|
21
|
+
redirect_to decidim_decidim_awesome.required_authorizations_path(redirect_url: request.fullpath)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def service
|
26
|
+
@service ||= Decidim::DecidimAwesome::AccessAuthorizationService.new(current_user, current_organization, required_authorization_groups)
|
27
|
+
end
|
28
|
+
|
29
|
+
def required_authorization_groups
|
30
|
+
return unless awesome_force_authorizations.is_a?(Array)
|
31
|
+
|
32
|
+
@required_authorization_groups ||= awesome_force_authorizations.pluck("authorization_handlers").compact_blank
|
33
|
+
end
|
34
|
+
|
35
|
+
def skip_enforcement_for_current_request?
|
36
|
+
# skip unconfirmed and blocked as other decidim mechanisms kick in
|
37
|
+
return true if user_signed_in? && (!current_user.confirmed? || current_user.blocked?)
|
38
|
+
return true if allowed_controllers.include?(controller_name.to_s)
|
39
|
+
|
40
|
+
# Only apply it if the context requires it
|
41
|
+
awesome_force_authorizations.blank?
|
42
|
+
end
|
43
|
+
|
44
|
+
def allowed_controllers
|
45
|
+
%w(required_authorizations authorizations upload_validations timeouts editor_images locales pages tos) + awesome_config[:force_authorization_allowed_controller_names].to_a
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module NeedsHashcash
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include AwesomeHelpers
|
10
|
+
include ActiveHashcash
|
11
|
+
|
12
|
+
helper_method :awesome_hashcash_bits
|
13
|
+
before_action :set_hashcash_bits
|
14
|
+
before_action :awesome_check_hashcash, only: :create # rubocop:disable Rails/LexicallyScopedActionFilter
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def awesome_hashcash_bits(zone)
|
20
|
+
return false unless awesome_config["hashcash_#{zone}".to_sym]
|
21
|
+
|
22
|
+
awesome_config["hashcash_#{zone}_bits".to_sym]
|
23
|
+
end
|
24
|
+
|
25
|
+
def awesome_check_hashcash
|
26
|
+
return unless set_hashcash_bits
|
27
|
+
|
28
|
+
check_hashcash
|
29
|
+
end
|
30
|
+
|
31
|
+
# Dynamically configures the gem https://github.com/BaseSecrete/active_hashcash
|
32
|
+
def set_hashcash_bits
|
33
|
+
return if user_signed_in?
|
34
|
+
|
35
|
+
ActiveHashcash.bits = if controller_name == "registrations"
|
36
|
+
awesome_hashcash_bits(:signup)
|
37
|
+
else
|
38
|
+
awesome_hashcash_bits(:login)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -14,9 +14,9 @@ module Decidim
|
|
14
14
|
return unless Decidim::User.respond_to? :awesome_admins_for_current_scope
|
15
15
|
return unless Decidim::User.respond_to? :awesome_potential_admins
|
16
16
|
return unless defined? current_user
|
17
|
-
return unless Decidim::User.awesome_potential_admins.include? current_user
|
17
|
+
return unless Decidim::User.awesome_potential_admins.include? current_user&.id
|
18
18
|
|
19
|
-
#
|
19
|
+
# assigning a flash message here does not work after redirection due the order of middleware in Rails
|
20
20
|
# as a workaround, send a message through a get parameter
|
21
21
|
path = "/admin/?unauthorized"
|
22
22
|
referer = request.headers["Referer"]
|
@@ -32,8 +32,8 @@ module Decidim
|
|
32
32
|
if force_verification.present?
|
33
33
|
create_forced_authorization
|
34
34
|
else
|
35
|
-
|
36
|
-
message
|
35
|
+
callout = render_to_string("callout", locals: { i18n_key: "user_not_authorized", klass: "alert" }, layout: false)
|
36
|
+
message = render_to_string("edit", locals: { with_override: true, callout: })
|
37
37
|
end
|
38
38
|
end
|
39
39
|
on(:ok) do
|
@@ -16,8 +16,9 @@ module Decidim
|
|
16
16
|
|
17
17
|
def show
|
18
18
|
@form = form(ConfigForm).from_params(organization_awesome_config)
|
19
|
+
path = main_path_for(config_var)
|
19
20
|
|
20
|
-
redirect_to decidim_admin_decidim_awesome.
|
21
|
+
redirect_to decidim_admin_decidim_awesome.send(path[0], *path[1]) unless path[0] == :config_path
|
21
22
|
end
|
22
23
|
|
23
24
|
def update
|
@@ -3,13 +3,12 @@
|
|
3
3
|
module Decidim
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
|
-
# Editing menu items
|
7
6
|
class CustomRedirectsController < DecidimAwesome::Admin::ApplicationController
|
8
7
|
include NeedsAwesomeConfig
|
9
8
|
include ConfigConstraintsHelpers
|
10
9
|
|
11
10
|
before_action do
|
12
|
-
enforce_permission_to :edit_config, :
|
11
|
+
enforce_permission_to :edit_config, :custom_redirects
|
13
12
|
end
|
14
13
|
|
15
14
|
helper ConfigConstraintsHelpers
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module Admin
|
6
|
+
class ForceAuthorizationsController < DecidimAwesome::Admin::ConfigController
|
7
|
+
def create
|
8
|
+
CreateAuthorizationGroup.call(current_organization, config_var) do
|
9
|
+
on(:ok) do |key|
|
10
|
+
flash[:notice] = I18n.t("config.create_force_authorization.success", key:, scope: "decidim.decidim_awesome.admin")
|
11
|
+
end
|
12
|
+
|
13
|
+
on(:invalid) do |message|
|
14
|
+
flash[:alert] = I18n.t("config.create_force_authorization.error", error: message, scope: "decidim.decidim_awesome.admin")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
redirect_to decidim_admin_decidim_awesome.config_path(:verifications)
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy
|
22
|
+
DestroyAuthorizationGroup.call(params[:key], current_organization, config_var) do
|
23
|
+
on(:ok) do |key|
|
24
|
+
flash[:notice] = I18n.t("config.destroy_force_authorization.success", key:, scope: "decidim.decidim_awesome.admin")
|
25
|
+
end
|
26
|
+
|
27
|
+
on(:invalid) do |message|
|
28
|
+
flash[:alert] = I18n.t("config.destroy_force_authorization.error", error: message, scope: "decidim.decidim_awesome.admin")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
redirect_to decidim_admin_decidim_awesome.config_path(:verifications)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# maybe in the future we want to restrict the admin as well
|
38
|
+
def config_var
|
39
|
+
:force_authorizations
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/decidim_awesome/version"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module DecidimAwesome
|
7
|
+
module Admin
|
8
|
+
# System compatibility analyzer
|
9
|
+
class HashcashController < DecidimAwesome::Admin::ApplicationController
|
10
|
+
include NeedsAwesomeConfig
|
11
|
+
include MaintenanceContext
|
12
|
+
helper ConfigConstraintsHelpers
|
13
|
+
|
14
|
+
helper_method :stamps, :stamp, :addresses
|
15
|
+
before_action do
|
16
|
+
enforce_permission_to :edit_config, [:hashcash_login, :hashcash_signup]
|
17
|
+
end
|
18
|
+
|
19
|
+
def ip_addresses
|
20
|
+
render "ip_addresses"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def stamps
|
26
|
+
@stamps ||= ActiveHashcash::Stamp.filter_by(params).order(created_at: :desc).limit(1000)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stamp
|
30
|
+
@stamp ||= ActiveHashcash::Stamp.find_by(id: params[:id])
|
31
|
+
end
|
32
|
+
|
33
|
+
def addresses
|
34
|
+
@addresses ||= ActiveHashcash::Stamp.filter_by(params).group(:ip_address).order(count_all: :desc).limit(1000).count
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -6,7 +6,7 @@ module Decidim
|
|
6
6
|
module DecidimAwesome
|
7
7
|
module Admin
|
8
8
|
# System compatibility analyzer
|
9
|
-
class
|
9
|
+
class PrivateDataController < DecidimAwesome::Admin::ApplicationController
|
10
10
|
include NeedsAwesomeConfig
|
11
11
|
include MaintenanceContext
|
12
12
|
include Decidim::Admin::Filterable
|
@@ -19,36 +19,36 @@ module Decidim
|
|
19
19
|
enforce_permission_to :edit_config, :private_data, private_data:
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def index
|
23
23
|
respond_to do |format|
|
24
24
|
format.json do
|
25
25
|
render json: private_data_finder.for(params[:resources].to_s.split(",")).map { |resource| present(resource) }
|
26
26
|
end
|
27
27
|
format.all do
|
28
|
-
render :
|
28
|
+
render :index
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def destroy
|
34
34
|
if private_data && private_data.total.to_i.positive?
|
35
35
|
Decidim::ActionLogger.log("destroy_private_data", current_user, resource, nil, count: private_data.total)
|
36
36
|
|
37
37
|
Lock.new(current_organization).get!(resource)
|
38
38
|
DestroyPrivateDataJob.set(wait: 1.second).perform_later(resource)
|
39
39
|
end
|
40
|
-
redirect_to decidim_admin_decidim_awesome.
|
41
|
-
notice: I18n.t("
|
40
|
+
redirect_to decidim_admin_decidim_awesome.private_data_path,
|
41
|
+
notice: I18n.t("destroying", scope: "decidim.decidim_awesome.admin.private_data.private_data", title: present(resource).name)
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def resource
|
47
|
-
@resource ||= Component.find_by(id: params[:
|
47
|
+
@resource ||= Component.find_by(id: params[:id])
|
48
48
|
end
|
49
49
|
|
50
50
|
def private_data
|
51
|
-
@private_data ||=
|
51
|
+
@private_data ||= present(resource) if resource
|
52
52
|
end
|
53
53
|
|
54
54
|
def collection
|
@@ -60,7 +60,7 @@ module Decidim
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def present(resource)
|
63
|
-
|
63
|
+
PrivateDataPresenter.new(resource)
|
64
64
|
end
|
65
65
|
|
66
66
|
def private_data_finder
|