decidim-decidim_awesome 0.12.3 → 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 +13 -1
- data/README.md +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/enforce_access_authorizations.rb +49 -0
- data/app/controllers/concerns/decidim/decidim_awesome/needs_hashcash.rb +7 -5
- data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +2 -0
- data/app/controllers/decidim/decidim_awesome/admin/force_authorizations_controller.rb +44 -0
- data/app/controllers/decidim/decidim_awesome/required_authorizations_controller.rb +51 -13
- 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/decidim/decidim_awesome/admin/authorization_group_form.rb +66 -0
- data/app/forms/decidim/decidim_awesome/admin/config_form.rb +12 -26
- 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 +20 -17
- 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/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/packs/src/decidim/decidim_awesome/admin/auto_edit.js +15 -0
- data/app/packs/src/decidim/decidim_awesome/awesome_admin.js +0 -1
- 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/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/config/_authorization_options_form.html.erb +19 -0
- 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/shared/_visibility_notice.html.erb +8 -0
- data/app/views/decidim/decidim_awesome/hashcash/_hidden_field.html.erb +0 -1
- data/app/views/decidim/decidim_awesome/required_authorizations/index.html.erb +14 -4
- data/config/i18n-tasks.yml +1 -0
- data/config/locales/ca.yml +31 -7
- data/config/locales/cs.yml +32 -7
- data/config/locales/de.yml +31 -7
- data/config/locales/en.yml +36 -12
- data/config/locales/es.yml +32 -7
- data/config/locales/eu.yml +3 -8
- data/config/locales/fr.yml +3 -8
- data/config/locales/ja.yml +70 -7
- data/config/locales/sv.yml +49 -0
- data/lib/decidim/decidim_awesome/admin_engine.rb +1 -0
- data/lib/decidim/decidim_awesome/{authorizator.rb → authorizer.rb} +1 -1
- data/lib/decidim/decidim_awesome/awesome.rb +5 -17
- data/lib/decidim/decidim_awesome/awesome_helpers.rb +14 -5
- data/lib/decidim/decidim_awesome/checksums.yml +11 -0
- 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 +3 -1
- data/lib/decidim/decidim_awesome/menu.rb +1 -1
- data/lib/decidim/decidim_awesome/middleware/current_config.rb +5 -10
- data/lib/decidim/decidim_awesome/test/initializer.rb +1 -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 +7 -3
- data/lib/decidim/decidim_awesome/version.rb +1 -1
- data/package.json +4 -4
- metadata +20 -5
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85eb621adc0f8d42ade17d24162061418885a2d566fab94af0ede1a195c1cf06
|
4
|
+
data.tar.gz: ae6688521eb2a8f81d02f67790ea25e6ca1be0466e0874d6f624431b65a73c31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4b183a80725bc02a7c518f1de438eb182e2b1108c4d2ab935d47cd959abf8890da6d587990dc5de64194a69513bf7d758c9d763084c853ae83b62998c0d850c
|
7
|
+
data.tar.gz: 75aa3a809688d9d5f8a4cfa51a2cea964b1deeb214d9ad774a6869dadc6c81bcf640182ec9577a7b3dd840f5a74916a73c28e1c1913f03ed30ab8b5569605bab
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
-
v0.12.
|
4
|
+
v0.12.4
|
5
|
+
-------
|
6
|
+
Compatibility:
|
7
|
+
- Decidim 0.29.x
|
8
|
+
|
9
|
+
Features:
|
10
|
+
- Added application context for config constraints (whether the user is logged or not)
|
11
|
+
- Allow to granular permissions to forced verifications.
|
12
|
+
**NOTE** Config var `force_authorization_after_login` has changed to `force_authorizations`
|
13
|
+
- Fix use of Hashcash in loginModals
|
14
|
+
- Fix validation overrides in the admin for proposals
|
15
|
+
|
16
|
+
v0.12.3
|
5
17
|
-------
|
6
18
|
|
7
19
|
Compatibility:
|
data/README.md
CHANGED
@@ -387,7 +387,7 @@ Admins can manage these settings in the Awesome admin panel under the "Verificat
|
|
387
387
|

|
388
388
|

|
389
389
|
|
390
|
-
|
390
|
+
You can configure which controller are allowed by creating an initializer (some controllers like the login, terms and conditions, etc. are always allowed):
|
391
391
|
|
392
392
|
```ruby
|
393
393
|
# config/initializers/decidim_awesome.rb
|
@@ -6,12 +6,46 @@ module Decidim
|
|
6
6
|
module NeedsConstraintHelpers
|
7
7
|
private
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
attr_reader :organization, :config_var
|
10
|
+
|
11
|
+
def ident
|
12
|
+
@ident ||= rand(36**8).to_s(36)
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_var
|
16
|
+
@find_var ||= AwesomeConfig.find_or_initialize_by(var: config_var, organization:)
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_sub_var
|
20
|
+
@find_sub_var ||= AwesomeConfig.find_or_initialize_by(var: "#{config_var.to_s.singularize}_#{ident}", organization:)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_array_config!(default_attributes = nil)
|
24
|
+
find_var.value = [] unless find_var.value.is_a?(Array)
|
25
|
+
find_var.value << default_attributes if default_attributes
|
26
|
+
find_var.save!
|
27
|
+
find_var
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_hash_config!(default_attributes = nil)
|
31
|
+
find_var.value = {} unless find_var.value.is_a?(Hash)
|
32
|
+
find_var.value[ident] = default_attributes if default_attributes
|
33
|
+
find_var.save!
|
34
|
+
find_var
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy_hash_ident!
|
38
|
+
find_var.value.except!(ident)
|
39
|
+
find_var.save!
|
40
|
+
|
41
|
+
# remove associated sub var (dependents will be destroyed automatically via ActiveRecord triggers)
|
42
|
+
find_sub_var.destroy! if find_sub_var.present?
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_constraint_never!
|
12
46
|
@constraint = ConfigConstraint.create!(
|
13
|
-
awesome_config:
|
14
|
-
settings:
|
47
|
+
awesome_config: find_sub_var,
|
48
|
+
settings: { "participatory_space_manifest" => "none" }
|
15
49
|
)
|
16
50
|
end
|
17
51
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module Admin
|
6
|
+
class CreateAuthorizationGroup < Command
|
7
|
+
include NeedsConstraintHelpers
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
def initialize(organization, config_var = :force_authorizations)
|
11
|
+
@organization = organization
|
12
|
+
@config_var = config_var
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid.
|
18
|
+
# - :invalid if we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
create_hash_config!(attributes)
|
23
|
+
|
24
|
+
create_constraint_never!
|
25
|
+
|
26
|
+
broadcast(:ok, ident)
|
27
|
+
rescue StandardError => e
|
28
|
+
broadcast(:invalid, e.message)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def attributes
|
34
|
+
{
|
35
|
+
"authorization_handlers" => {},
|
36
|
+
"force_authorization_help_text" => {}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -4,11 +4,14 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class CreateCustomRedirect < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
def initialize(form)
|
10
11
|
@form = form
|
11
|
-
@
|
12
|
+
@ident = form.to_params[0]
|
13
|
+
@organization = form.current_organization
|
14
|
+
@config_var = :custom_redirects
|
12
15
|
end
|
13
16
|
|
14
17
|
# Executes the command. Broadcasts these events:
|
@@ -21,7 +24,8 @@ module Decidim
|
|
21
24
|
return broadcast(:invalid) if form.invalid?
|
22
25
|
return broadcast(:invalid, I18n.t("custom_redirects.origin_exists", scope: "decidim.decidim_awesome.admin")) if url_exists?
|
23
26
|
|
24
|
-
|
27
|
+
create_hash_config!(form.to_params[1])
|
28
|
+
|
25
29
|
broadcast(:ok)
|
26
30
|
rescue StandardError => e
|
27
31
|
broadcast(:invalid, e.message)
|
@@ -29,21 +33,13 @@ module Decidim
|
|
29
33
|
|
30
34
|
private
|
31
35
|
|
32
|
-
attr_reader :form
|
33
|
-
|
34
|
-
delegate :to_params, to: :form
|
35
|
-
|
36
|
-
def create_redirection!
|
37
|
-
redirections.value = {} unless redirections.value.is_a? Hash
|
38
|
-
redirections.value[to_params[0]] = to_params[1]
|
39
|
-
redirections.save!
|
40
|
-
end
|
36
|
+
attr_reader :form
|
41
37
|
|
42
38
|
def url_exists?
|
43
|
-
return false unless
|
44
|
-
return false unless
|
39
|
+
return false unless find_var
|
40
|
+
return false unless find_var.value.is_a? Hash
|
45
41
|
|
46
|
-
|
42
|
+
find_var.value[form.origin].present?
|
47
43
|
end
|
48
44
|
end
|
49
45
|
end
|
@@ -4,11 +4,13 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class CreateMenuHack < 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:
|
@@ -21,22 +23,21 @@ module Decidim
|
|
21
23
|
return broadcast(:invalid) if form.invalid?
|
22
24
|
return broadcast(:invalid, I18n.t("menu_hacks.url_exists", scope: "decidim.decidim_awesome.admin")) if url_exists?
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
broadcast(:ok, menu)
|
26
|
+
create_array_config!(to_params)
|
27
|
+
|
28
|
+
broadcast(:ok, find_var)
|
28
29
|
rescue StandardError => e
|
29
30
|
broadcast(:invalid, e.message)
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
33
34
|
|
34
|
-
attr_reader :form
|
35
|
+
attr_reader :form
|
35
36
|
|
36
37
|
def url_exists?
|
37
|
-
return false unless
|
38
|
+
return false unless find_var
|
38
39
|
|
39
|
-
|
40
|
+
find_var.value&.detect { |i| i["url"] == form.url.gsub(/\?.*/, "") }
|
40
41
|
end
|
41
42
|
|
42
43
|
def to_params
|
@@ -10,7 +10,6 @@ module Decidim
|
|
10
10
|
#
|
11
11
|
def initialize(organization, config_var = :proposal_custom_fields)
|
12
12
|
@organization = organization
|
13
|
-
@ident = rand(36**8).to_s(36)
|
14
13
|
@config_var = config_var
|
15
14
|
end
|
16
15
|
|
@@ -21,15 +20,11 @@ module Decidim
|
|
21
20
|
#
|
22
21
|
# Returns nothing.
|
23
22
|
def call
|
24
|
-
|
25
|
-
fields.value = {} unless fields.value.is_a? Hash
|
26
|
-
# TODO: prevent (unlikely) colisions with exisiting values
|
27
|
-
fields.value[@ident] = default_definition
|
28
|
-
fields.save!
|
23
|
+
create_hash_config!(default_definition)
|
29
24
|
|
30
|
-
create_constraint_never
|
25
|
+
create_constraint_never!
|
31
26
|
|
32
|
-
broadcast(:ok,
|
27
|
+
broadcast(:ok, ident)
|
33
28
|
rescue StandardError => e
|
34
29
|
broadcast(:invalid, e.message)
|
35
30
|
end
|
@@ -10,7 +10,7 @@ module Decidim
|
|
10
10
|
#
|
11
11
|
def initialize(organization)
|
12
12
|
@organization = organization
|
13
|
-
@
|
13
|
+
@config_var = :scoped_admins
|
14
14
|
end
|
15
15
|
|
16
16
|
# Executes the command. Broadcasts these events:
|
@@ -20,15 +20,11 @@ module Decidim
|
|
20
20
|
#
|
21
21
|
# Returns nothing.
|
22
22
|
def call
|
23
|
-
|
24
|
-
admins.value = {} unless admins.value.is_a? Hash
|
25
|
-
# TODO: prevent (unlikely) colisions with exisiting values
|
26
|
-
admins.value[@ident] = []
|
27
|
-
admins.save!
|
23
|
+
create_hash_config!([])
|
28
24
|
|
29
|
-
create_constraint_never
|
25
|
+
create_constraint_never!
|
30
26
|
|
31
|
-
broadcast(:ok,
|
27
|
+
broadcast(:ok, ident)
|
32
28
|
rescue StandardError => e
|
33
29
|
broadcast(:invalid, e.message)
|
34
30
|
end
|
@@ -4,11 +4,11 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class CreateScopedStyle < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
def initialize(organization, config_var = :scoped_styles)
|
10
11
|
@organization = organization
|
11
|
-
@ident = rand(36**8).to_s(36)
|
12
12
|
@config_var = config_var
|
13
13
|
end
|
14
14
|
|
@@ -19,13 +19,9 @@ module Decidim
|
|
19
19
|
#
|
20
20
|
# Returns nothing.
|
21
21
|
def call
|
22
|
-
|
23
|
-
styles.value = {} unless styles.value.is_a? Hash
|
24
|
-
# TODO: prevent (unlikely) colisions with exisiting values
|
25
|
-
styles.value[@ident] = ""
|
26
|
-
styles.save!
|
22
|
+
create_hash_config!("")
|
27
23
|
|
28
|
-
broadcast(:ok,
|
24
|
+
broadcast(:ok, ident)
|
29
25
|
rescue StandardError => e
|
30
26
|
broadcast(:invalid, e.message)
|
31
27
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module Admin
|
6
|
+
class DestroyAuthorizationGroup < Command
|
7
|
+
include NeedsConstraintHelpers
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# key - the key to destroy inside force_authorizations
|
11
|
+
# organization - the organization to which the config belongs
|
12
|
+
def initialize(key, organization, config_var = :force_authorizations)
|
13
|
+
@ident = key
|
14
|
+
@organization = organization
|
15
|
+
@config_var = config_var
|
16
|
+
end
|
17
|
+
|
18
|
+
# Executes the command. Broadcasts these events:
|
19
|
+
#
|
20
|
+
# - :ok when everything is valid.
|
21
|
+
# - :invalid if we couldn't proceed.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def call
|
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
|
+
|
28
|
+
destroy_hash_ident!
|
29
|
+
|
30
|
+
broadcast(:ok, ident)
|
31
|
+
rescue StandardError => e
|
32
|
+
broadcast(:invalid, e.message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -4,14 +4,15 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class DestroyCustomRedirect < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
|
-
# item - the
|
10
|
+
# item - the redirects item to destroy
|
10
11
|
# organization
|
11
12
|
def initialize(item, organization)
|
12
13
|
@item = item
|
13
14
|
@organization = organization
|
14
|
-
@
|
15
|
+
@config_var = :custom_redirects
|
15
16
|
end
|
16
17
|
|
17
18
|
# Executes the command. Broadcasts these events:
|
@@ -23,23 +24,23 @@ module Decidim
|
|
23
24
|
def call
|
24
25
|
return broadcast(:invalid) unless url_exists?
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
find_var.value&.except!(item.origin)
|
28
|
+
find_var.save!
|
28
29
|
|
29
|
-
broadcast(:ok,
|
30
|
+
broadcast(:ok, item)
|
30
31
|
rescue StandardError => e
|
31
32
|
broadcast(:invalid, e.message)
|
32
33
|
end
|
33
34
|
|
34
35
|
private
|
35
36
|
|
36
|
-
attr_reader :
|
37
|
+
attr_reader :item
|
37
38
|
|
38
39
|
def url_exists?
|
39
|
-
return false unless
|
40
|
-
return false unless
|
40
|
+
return false unless find_var
|
41
|
+
return false unless find_var.value.is_a? Hash
|
41
42
|
|
42
|
-
|
43
|
+
find_var.value[item.origin].present?
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -4,6 +4,7 @@ module Decidim
|
|
4
4
|
module DecidimAwesome
|
5
5
|
module Admin
|
6
6
|
class DestroyMenuHack < Command
|
7
|
+
include NeedsConstraintHelpers
|
7
8
|
# Public: Initializes the command.
|
8
9
|
#
|
9
10
|
# item - the menu item to destroy
|
@@ -11,7 +12,7 @@ module Decidim
|
|
11
12
|
def initialize(item, menu_name, organization)
|
12
13
|
@item = item
|
13
14
|
@organization = organization
|
14
|
-
@
|
15
|
+
@config_var = menu_name
|
15
16
|
end
|
16
17
|
|
17
18
|
# Executes the command. Broadcasts these events:
|
@@ -23,8 +24,8 @@ module Decidim
|
|
23
24
|
def call
|
24
25
|
return broadcast(:invalid) unless url_exists?
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
find_var.value&.reject! { |i| i["url"] == item.url }
|
28
|
+
find_var.save!
|
28
29
|
|
29
30
|
broadcast(:ok, @item)
|
30
31
|
rescue StandardError => e
|
@@ -33,13 +34,13 @@ module Decidim
|
|
33
34
|
|
34
35
|
private
|
35
36
|
|
36
|
-
attr_reader :organization, :item
|
37
|
+
attr_reader :organization, :item
|
37
38
|
|
38
39
|
def url_exists?
|
39
|
-
return false unless
|
40
|
-
return false unless
|
40
|
+
return false unless find_var
|
41
|
+
return false unless find_var.value.is_a? Array
|
41
42
|
|
42
|
-
|
43
|
+
find_var.value&.detect { |i| i["url"] == item.url }
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -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
|