decidim-decidim_awesome 0.11.2 → 0.11.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +54 -2
- data/app/cells/concerns/decidim/decidim_awesome/proposal_l_cell_override.rb +5 -3
- data/app/cells/decidim/decidim_awesome/content_blocks/map_cell.rb +0 -4
- data/app/cells/decidim/decidim_awesome/voting/proposal_metadata_cell.rb +18 -3
- data/app/commands/concerns/decidim/decidim_awesome/proposals/create_proposal_override.rb +2 -2
- data/app/commands/concerns/decidim/decidim_awesome/system/register_organization_override.rb +29 -0
- data/app/commands/concerns/decidim/decidim_awesome/system/update_organization_override.rb +35 -0
- data/app/commands/concerns/decidim/decidim_awesome/update_account_override.rb +30 -0
- data/app/commands/decidim/decidim_awesome/admin/create_scoped_style.rb +3 -2
- data/app/commands/decidim/decidim_awesome/admin/destroy_scoped_style.rb +6 -4
- data/app/controllers/concerns/decidim/decidim_awesome/check_login_authorizations.rb +60 -0
- data/app/controllers/concerns/decidim/decidim_awesome/needs_awesome_config.rb +0 -2
- data/app/controllers/concerns/decidim/decidim_awesome/proposals/memoize_extra_fields.rb +23 -0
- data/app/controllers/concerns/decidim/decidim_awesome/use_user_time_zone.rb +32 -0
- data/app/controllers/decidim/decidim_awesome/admin/admin_authorizations_controller.rb +122 -0
- data/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +1 -1
- data/app/controllers/decidim/decidim_awesome/admin/config_controller.rb +7 -1
- data/app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb +5 -1
- data/app/controllers/decidim/decidim_awesome/admin/scoped_styles_controller.rb +12 -4
- data/app/controllers/decidim/decidim_awesome/required_authorizations_controller.rb +58 -0
- data/app/forms/concerns/decidim/decidim_awesome/account_form_override.rb +25 -0
- data/app/forms/concerns/decidim/decidim_awesome/system/organization_form_override.rb +34 -0
- data/app/forms/decidim/decidim_awesome/admin/config_form.rb +41 -8
- data/app/helpers/decidim/decidim_awesome/map_helper.rb +28 -26
- data/app/overrides/decidim/account/show/add_timezone_select.html.erb.deface +3 -0
- data/app/overrides/decidim/admin/officializations/index/add_modal.html.erb.deface +3 -0
- data/app/overrides/decidim/admin/officializations/index/add_td.html.erb.deface +5 -0
- data/app/overrides/decidim/admin/officializations/index/add_th.html.erb.deface +5 -0
- data/app/overrides/decidim/system/organizations/_advanced_settings/add_awesome_config.html.erb.deface +9 -0
- data/app/overrides/layouts/decidim/_head/add_awesome_tags.html.erb.deface +1 -1
- data/app/overrides/layouts/decidim/admin/_header/add_awesome_custom_styles.html.erb.deface +3 -0
- data/app/overrides/layouts/decidim/admin/_header/add_awesome_tags.html.erb.deface +1 -0
- data/app/packs/src/decidim/decidim_awesome/admin/proposal_sortings.js +0 -5
- data/app/packs/src/decidim/decidim_awesome/admin/verification_selects.js +21 -0
- data/app/packs/src/decidim/decidim_awesome/admin/verifications.js +43 -0
- data/app/packs/src/decidim/decidim_awesome/awesome_admin.js +1 -0
- data/app/packs/src/decidim/decidim_awesome/awesome_admin_global.js +1 -0
- data/app/packs/stylesheets/decidim/decidim_awesome/admin/verifications.scss +99 -0
- data/app/packs/stylesheets/decidim/decidim_awesome/awesome_admin_global.scss +1 -0
- data/app/permissions/decidim/decidim_awesome/admin/permissions.rb +42 -11
- data/app/permissions/decidim/decidim_awesome/permissions.rb +7 -0
- data/app/presenters/decidim/decidim_awesome/admin_log/component_presenter_override.rb +3 -5
- data/app/presenters/decidim/decidim_awesome/admin_log/user_presenter_override.rb +46 -0
- data/app/views/decidim/decidim_awesome/account/_timezone_select.html.erb +3 -0
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/authorization.html.erb +20 -0
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/callout.html.erb +3 -0
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/conflict.html.erb +5 -0
- data/app/views/decidim/decidim_awesome/admin/admin_authorizations/edit.html.erb +41 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_scoped_admin_styles.html.erb +1 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_scoped_styles.html.erb +48 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_surveys.html.erb +8 -0
- data/app/views/decidim/decidim_awesome/admin/config/_form_verifications.html.erb +15 -0
- data/app/views/decidim/decidim_awesome/admin/constraints/no_permissions.html.erb +6 -0
- data/app/views/decidim/decidim_awesome/admin/officializations/_participants_td.html.erb +25 -0
- data/app/views/decidim/decidim_awesome/admin/officializations/_participants_th.html.erb +1 -0
- data/app/views/decidim/decidim_awesome/admin/officializations/_verification_modal.html.erb +9 -0
- data/app/views/decidim/decidim_awesome/required_authorizations/index.html.erb +66 -0
- data/app/views/decidim/decidim_awesome/system/organizations/_admin_allowed_authorizations.html.erb +5 -0
- data/app/views/layouts/decidim/decidim_awesome/_custom_styles.html.erb +1 -1
- data/app/views/layouts/decidim/decidim_awesome/admin/_custom_styles.html.erb +3 -0
- data/app/views/layouts/decidim/decidim_awesome/admin/admin_authorizations.html.erb +7 -0
- data/config/i18n-tasks.yml +6 -0
- data/config/locales/ca.yml +91 -5
- data/config/locales/cs.yml +86 -0
- data/config/locales/de.yml +52 -0
- data/config/locales/en.yml +115 -1
- data/config/locales/es.yml +89 -3
- data/config/locales/eu.yml +607 -26
- data/config/locales/fr.yml +37 -1
- data/config/locales/it.yml +0 -1
- data/config/locales/ja.yml +86 -0
- data/config/locales/nl.yml +0 -1
- data/config/locales/pt-BR.yml +0 -1
- data/lib/decidim/decidim_awesome/admin_engine.rb +2 -0
- data/lib/decidim/decidim_awesome/authorizator.rb +34 -0
- data/lib/decidim/decidim_awesome/awesome.rb +54 -1
- data/lib/decidim/decidim_awesome/awesome_helpers.rb +48 -19
- data/lib/decidim/decidim_awesome/checksums.yml +9 -0
- data/lib/decidim/decidim_awesome/engine.rb +20 -4
- data/lib/decidim/decidim_awesome/menu.rb +45 -9
- data/lib/decidim/decidim_awesome/request_memoizer.rb +16 -0
- data/lib/decidim/decidim_awesome/test/factories.rb +0 -4
- data/lib/decidim/decidim_awesome/test/initializer.rb +4 -0
- data/lib/decidim/decidim_awesome/test/shared_examples/config_examples.rb +1 -1
- data/lib/decidim/decidim_awesome/test/shared_examples/custom_styles_examples.rb +156 -0
- data/lib/decidim/decidim_awesome/test/shared_examples/summary_examples.rb +26 -10
- data/lib/decidim/decidim_awesome/version.rb +1 -1
- data/package.json +6 -5
- metadata +42 -7
- data/app/views/decidim/decidim_awesome/admin/config/_form_styles.html.erb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca78262a57db332a236230c15e2584c2dcbc1f5ee6055400b7fc187fbb24dfae
|
4
|
+
data.tar.gz: 48a4aa2ca9b10d8f9c6a8b4a6dc3e8084360e87398ad1c5160a87e9569e18060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e59ee2965fc55d0e8874a2745508ef10d15fe8d2582e5a1dad84f79810d0b39d4f58124f637c88a7100eaca171e9a59237f792f7acce7485ceae8de8b05f5ee5
|
7
|
+
data.tar.gz: e66c77623b540ed323d083d2d68967e033dc3bfed826ef82df9db5c40832fab46253ac5d3840a38226aa547cee7ca33ba5a6a4caf76b13e2612e983a6ddc5b1b
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
3
|
|
4
|
+
v0.11.3
|
5
|
+
-------
|
6
|
+
Compatibility:
|
7
|
+
- Decidim v0.28.x
|
8
|
+
|
9
|
+
Features:
|
10
|
+
- Added user time zones in account settings
|
11
|
+
- Added custom styles for the admin panel
|
12
|
+
- Added Verification tweaks
|
13
|
+
- Added Admin manual verifications
|
14
|
+
|
4
15
|
v0.11.2
|
5
16
|
-------
|
6
17
|
|
data/README.md
CHANGED
@@ -83,9 +83,15 @@ With this feature you can have a support chat in Decidim. It is linked to a [Tel
|
|
83
83
|
|
84
84
|
#### 8. Custom CSS applied only according scoped restrictions
|
85
85
|
|
86
|
-
|
86
|
+
##### 8.1 Public styles
|
87
|
+
With this feature you can create directly in the admin a CSS snipped that is only applied in the public frontend, in a particular assembly or even a single proposal!
|
87
88
|
|
88
|
-

|
90
|
+
|
91
|
+
##### 8.2 Admin styles
|
92
|
+
With this feature you can create directly in the admin a CSS snipped that is only applied in the admin panel, in a particular assembly or even a single proposal!
|
93
|
+
|
94
|
+

|
89
95
|
|
90
96
|
#### 9. Change the main menu of Decidim entirely!
|
91
97
|
|
@@ -379,6 +385,46 @@ This menu will show if there's any data older than 6 months (configurable) and w
|
|
379
385
|
|
380
386
|

|
381
387
|
|
388
|
+
#### 19. User custom timezone
|
389
|
+
|
390
|
+
If your organization spans across multiple timezones, you can enable this feature under the "Surveys & Forms" section in the Awesome admin panel. This allows users to set their own timezone, which will be used to display dates and times throughout the platform according to their preference.
|
391
|
+
|
392
|
+

|
393
|
+
|
394
|
+
#### 20. Mandatory verifications
|
395
|
+
|
396
|
+
This feature allows admins to enforce mandatory verifications for users before they can access the platform. Admins can configure which verifications are required.
|
397
|
+
|
398
|
+
Admins can manage these settings in the Awesome admin panel under the "Verifications" section.
|
399
|
+
|
400
|
+

|
401
|
+

|
402
|
+
|
403
|
+
Note that some pages are allowed, you can even configure which controller are allowed by creating an initializer ("required_authorizations" and "authorizations" are always allowed):
|
404
|
+
|
405
|
+
```ruby
|
406
|
+
# config/initializers/decidim_awesome.rb
|
407
|
+
|
408
|
+
Decidim::DecidimAwesome.configure do |config|
|
409
|
+
# default controllers are "account" and "pages"
|
410
|
+
config.force_authorization_allowed_controller_names = %w(account pages homepage)
|
411
|
+
```
|
412
|
+
|
413
|
+
#### 21. Manual verifications
|
414
|
+
|
415
|
+
The admin will be allowed to manually authorize users using the methods specified in the `/system` admin section.
|
416
|
+
Currently, only form based handlers are supported (Direct methods).
|
417
|
+
Admins can manually override or verify users in the participants list but they still have to fulfill the requirements of the verifier (although they will be allowed to force the authorization even if some of them fails).
|
418
|
+
|
419
|
+
Admin logs are also created in each action for accountability.
|
420
|
+
|
421
|
+
System configuration:
|
422
|
+
|
423
|
+

|
424
|
+

|
425
|
+

|
426
|
+

|
427
|
+
|
382
428
|
#### To be continued...
|
383
429
|
|
384
430
|
We're not done! Please check the [issues](/decidim-ice/decidim-module-decidim_awesome/issues) (and participate) to see what's on our mind
|
@@ -401,6 +447,12 @@ bin/rails decidim:upgrade
|
|
401
447
|
bin/rails db:migrate
|
402
448
|
```
|
403
449
|
|
450
|
+
> In production mode you must also precompile the assets:
|
451
|
+
>
|
452
|
+
> ```
|
453
|
+
> bin/rails assets:precompile
|
454
|
+
> ```
|
455
|
+
|
404
456
|
Go to `yourdomain/admin/decidim_awesome` and start tweaking things!
|
405
457
|
|
406
458
|
> **EXPERTS ONLY**
|
@@ -11,12 +11,14 @@ module Decidim
|
|
11
11
|
alias_method :decidim_original_cache_hash, :cache_hash
|
12
12
|
|
13
13
|
def metadata_cell
|
14
|
-
awesome_voting_manifest_for(resource&.component)&.proposal_metadata_cell.presence || "decidim/proposals/proposal_metadata"
|
14
|
+
@metadata_cell ||= awesome_voting_manifest_for(resource&.component)&.proposal_metadata_cell.presence || "decidim/proposals/proposal_metadata"
|
15
15
|
end
|
16
16
|
|
17
17
|
def cache_hash
|
18
|
-
|
19
|
-
|
18
|
+
all_extra_fields = memoize("extra_fields")
|
19
|
+
extra_fields = all_extra_fields ? all_extra_fields[resource.id] : resource.extra_fields
|
20
|
+
|
21
|
+
@cache_hash ||= "#{decidim_original_cache_hash}#{Decidim.cache_key_separator}#{extra_fields&.vote_weight_totals}"
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -12,7 +12,7 @@ module Decidim
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def current_vote
|
15
|
-
@current_vote ||=
|
15
|
+
@current_vote ||= vote_for(current_user) if current_user
|
16
16
|
end
|
17
17
|
|
18
18
|
def user_voted_weight
|
@@ -24,7 +24,7 @@ module Decidim
|
|
24
24
|
weights = [3, 2, 1]
|
25
25
|
weights << 0 if resource.component.settings.voting_cards_show_abstain
|
26
26
|
weights.index_with do |weight|
|
27
|
-
|
27
|
+
weight_count_for(weight)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -38,7 +38,7 @@ module Decidim
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def weight_count_item
|
41
|
-
return unless resource.respond_to?(:weight_count)
|
41
|
+
# return unless resource.respond_to?(:weight_count)
|
42
42
|
return if resource.component.current_settings.votes_hidden?
|
43
43
|
return if resource&.rejected? || resource&.withdrawn?
|
44
44
|
|
@@ -48,6 +48,21 @@ module Decidim
|
|
48
48
|
data_attributes: all_weights.transform_keys { |num| "weight-#{num}" }
|
49
49
|
}
|
50
50
|
end
|
51
|
+
|
52
|
+
def vote_for(user)
|
53
|
+
user_votes = memoize("user_votes")
|
54
|
+
return user_votes[resource.id] if user_votes
|
55
|
+
|
56
|
+
resource.votes.find_by(author: user)
|
57
|
+
end
|
58
|
+
|
59
|
+
def weight_count_for(weight)
|
60
|
+
all_extra_fields = memoize("extra_fields")
|
61
|
+
extra_fields = all_extra_fields ? all_extra_fields[resource.id] : resource.extra_fields
|
62
|
+
return 0 unless extra_fields
|
63
|
+
|
64
|
+
extra_fields.vote_weight_totals[weight.to_s] || 0
|
65
|
+
end
|
51
66
|
end
|
52
67
|
end
|
53
68
|
end
|
@@ -15,10 +15,10 @@ module Decidim
|
|
15
15
|
alias_method :decidim_original_create_proposal, :create_proposal
|
16
16
|
|
17
17
|
def create_proposal
|
18
|
-
|
18
|
+
decidim_original_create_proposal
|
19
19
|
# Update the proposal with the private body, to
|
20
20
|
# avoid tracebility on private fields.
|
21
|
-
|
21
|
+
@proposal.update_private_body!(form.private_body) if form.private_body.present?
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module System
|
6
|
+
module RegisterOrganizationOverride
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
private
|
11
|
+
|
12
|
+
alias_method :decidim_create_organization, :create_organization
|
13
|
+
|
14
|
+
def create_organization
|
15
|
+
@organization = decidim_create_organization
|
16
|
+
if form.clean_awesome_admins_available_authorizations.present?
|
17
|
+
AwesomeConfig.create!(
|
18
|
+
var: :admins_available_authorizations,
|
19
|
+
organization: @organization,
|
20
|
+
value: form.clean_awesome_admins_available_authorizations
|
21
|
+
)
|
22
|
+
end
|
23
|
+
@organization
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module System
|
6
|
+
module UpdateOrganizationOverride
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
private
|
11
|
+
|
12
|
+
alias_method :decidim_original_save_organization, :save_organization
|
13
|
+
|
14
|
+
def save_organization
|
15
|
+
decidim_original_save_organization
|
16
|
+
if form.clean_awesome_admins_available_authorizations.present?
|
17
|
+
add_awesome_configs!
|
18
|
+
elsif awesome_config&.persisted?
|
19
|
+
awesome_config.destroy!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_awesome_configs!
|
24
|
+
awesome_config.value = form.clean_awesome_admins_available_authorizations
|
25
|
+
awesome_config.save!
|
26
|
+
end
|
27
|
+
|
28
|
+
def awesome_config
|
29
|
+
@awesome_config ||= AwesomeConfig.find_or_initialize_by(var: :admins_available_authorizations, organization: @organization)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module UpdateAccountOverride
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
alias_method :decidim_update_personal_data, :update_personal_data
|
10
|
+
alias_method :decidim_send_update_summary!, :send_update_summary!
|
11
|
+
|
12
|
+
def update_personal_data
|
13
|
+
decidim_update_personal_data
|
14
|
+
return if @form.user_time_zone.blank?
|
15
|
+
|
16
|
+
@user.extended_data ||= {}
|
17
|
+
if @form.user_time_zone == @user.organization.time_zone
|
18
|
+
@user.extended_data.delete("time_zone")
|
19
|
+
else
|
20
|
+
@user.extended_data["time_zone"] = @form.user_time_zone
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def send_update_summary!(changes)
|
25
|
+
decidim_send_update_summary!(changes - ["extended_data"])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -6,9 +6,10 @@ module Decidim
|
|
6
6
|
class CreateScopedStyle < Command
|
7
7
|
# Public: Initializes the command.
|
8
8
|
#
|
9
|
-
def initialize(organization)
|
9
|
+
def initialize(organization, config_var = :scoped_styles)
|
10
10
|
@organization = organization
|
11
11
|
@ident = rand(36**8).to_s(36)
|
12
|
+
@config_var = config_var
|
12
13
|
end
|
13
14
|
|
14
15
|
# Executes the command. Broadcasts these events:
|
@@ -18,7 +19,7 @@ module Decidim
|
|
18
19
|
#
|
19
20
|
# Returns nothing.
|
20
21
|
def call
|
21
|
-
styles = AwesomeConfig.find_or_initialize_by(var:
|
22
|
+
styles = AwesomeConfig.find_or_initialize_by(var: @config_var, organization: @organization)
|
22
23
|
styles.value = {} unless styles.value.is_a? Hash
|
23
24
|
# TODO: prevent (unlikely) colisions with exisiting values
|
24
25
|
styles.value[@ident] = ""
|
@@ -6,11 +6,12 @@ module Decidim
|
|
6
6
|
class DestroyScopedStyle < Command
|
7
7
|
# Public: Initializes the command.
|
8
8
|
#
|
9
|
-
# key - the key to destroy inside scoped_styles
|
9
|
+
# key - the key to destroy inside scoped_styles/scoped_admin_styles
|
10
10
|
# organization
|
11
|
-
def initialize(key, organization)
|
11
|
+
def initialize(key, organization, config_var = :scoped_styles)
|
12
12
|
@key = key
|
13
13
|
@organization = organization
|
14
|
+
@config_var = config_var
|
14
15
|
end
|
15
16
|
|
16
17
|
# Executes the command. Broadcasts these events:
|
@@ -20,14 +21,15 @@ module Decidim
|
|
20
21
|
#
|
21
22
|
# Returns nothing.
|
22
23
|
def call
|
23
|
-
styles = AwesomeConfig.find_by(var:
|
24
|
+
styles = AwesomeConfig.find_by(var: @config_var, organization: @organization)
|
24
25
|
return broadcast(:invalid, "Not a hash") unless styles&.value.is_a? Hash
|
25
26
|
return broadcast(:invalid, "#{key} key invalid") unless styles.value.has_key?(@key)
|
26
27
|
|
27
28
|
styles.value.except!(@key)
|
28
29
|
styles.save!
|
29
30
|
# remove constrains associated (a new config var is generated automatically, by removing it, it will trigger destroy on dependents)
|
30
|
-
constraint =
|
31
|
+
constraint = @config_var == :scoped_styles ? :scoped_style : :scoped_admin_style
|
32
|
+
constraint = AwesomeConfig.find_by(var: "#{constraint}_#{@key}", organization: @organization)
|
31
33
|
constraint.destroy! if constraint.present?
|
32
34
|
|
33
35
|
broadcast(:ok, @key)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module CheckLoginAuthorizations
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ::Decidim::DecidimAwesome::NeedsAwesomeConfig
|
10
|
+
before_action :check_required_login_authorizations
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def check_required_login_authorizations
|
16
|
+
return unless user_signed_in?
|
17
|
+
return unless current_user.confirmed?
|
18
|
+
return if current_user.blocked?
|
19
|
+
return if allowed_controllers.include?(controller_name)
|
20
|
+
|
21
|
+
unless user_is_authorized?
|
22
|
+
flash[:alert] = I18n.t("decidim.decidim_awesome.session.authorization_is_required",
|
23
|
+
authorizations: required_authorizations.map(&:fullname).join(", "))
|
24
|
+
redirect_to decidim_decidim_awesome.required_authorizations_path(redirect_url: request.fullpath)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def user_is_authorized?
|
29
|
+
return true if required_authorizations.blank?
|
30
|
+
|
31
|
+
@user_is_authorized ||= if awesome_config[:force_authorization_with_any_method]
|
32
|
+
current_authorizations.any?
|
33
|
+
else
|
34
|
+
current_authorizations.count == required_authorizations.count
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def required_authorizations
|
39
|
+
return unless awesome_config[:force_authorization_after_login].is_a?(Array)
|
40
|
+
|
41
|
+
@required_authorizations ||= Decidim::Verifications::Adapter.from_collection(
|
42
|
+
awesome_config[:force_authorization_after_login] & current_organization.available_authorizations & Decidim.authorization_workflows.map(&:name)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_authorizations
|
47
|
+
@current_authorizations ||= Decidim::Verifications::Authorizations.new(
|
48
|
+
organization: current_organization,
|
49
|
+
user: current_user,
|
50
|
+
name: required_authorizations.map(&:name),
|
51
|
+
granted: true
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
def allowed_controllers
|
56
|
+
%w(required_authorizations authorizations upload_validations timeouts editor_images locales) + awesome_config[:force_authorization_allowed_controller_names].to_a
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module Proposals
|
6
|
+
module MemoizeExtraFields
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include Decidim::DecidimAwesome::RequestMemoizer
|
9
|
+
|
10
|
+
included do
|
11
|
+
alias_method :decidim_original_index, :index
|
12
|
+
|
13
|
+
def index
|
14
|
+
decidim_original_index
|
15
|
+
|
16
|
+
memoize("extra_fields") { Decidim::DecidimAwesome::ProposalExtraField.where(proposal: @proposals).index_by(&:decidim_proposal_id) }
|
17
|
+
memoize("user_votes") { Decidim::Proposals::ProposalVote.where(proposal: proposals, author: current_user).index_by(&:decidim_proposal_id) if current_user }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module UseUserTimeZone
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
around_action :use_user_time_zone, if: -> { user_time_zone.present? }
|
10
|
+
helper_method :user_time_zone
|
11
|
+
|
12
|
+
# Executes a block of code in the context of the user's time zone
|
13
|
+
#
|
14
|
+
# &action - a block of code to be wrapped around the time zone
|
15
|
+
#
|
16
|
+
# Returns nothing.
|
17
|
+
def use_user_time_zone(&)
|
18
|
+
Time.use_zone(user_time_zone, &)
|
19
|
+
end
|
20
|
+
|
21
|
+
# The current time zone from the user. Available as a helper for the views.
|
22
|
+
#
|
23
|
+
# Returns a String.
|
24
|
+
def user_time_zone
|
25
|
+
return if helpers&.awesome_config&.[](:user_timezone).blank?
|
26
|
+
|
27
|
+
@user_time_zone ||= current_user&.extended_data&.[]("time_zone")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module DecidimAwesome
|
5
|
+
module Admin
|
6
|
+
class AdminAuthorizationsController < DecidimAwesome::Admin::ApplicationController
|
7
|
+
include NeedsAwesomeConfig
|
8
|
+
|
9
|
+
layout "layouts/decidim/decidim_awesome/admin/admin_authorizations"
|
10
|
+
helper_method :user, :authorization, :workflow, :handler, :conflict
|
11
|
+
# overwrite original rescue_from to ensure we print messages from ajax methods
|
12
|
+
rescue_from Decidim::ActionForbidden, with: :json_error
|
13
|
+
|
14
|
+
before_action do
|
15
|
+
enforce_permission_to :edit_config, :admins_available_authorizations, handler: workflow.name
|
16
|
+
end
|
17
|
+
|
18
|
+
def edit
|
19
|
+
render "authorization" if authorization
|
20
|
+
end
|
21
|
+
|
22
|
+
def update
|
23
|
+
if conflict
|
24
|
+
message = render_to_string("conflict")
|
25
|
+
else
|
26
|
+
message = render_to_string("callout", locals: { i18n_key: "user_authorized", klass: "success" })
|
27
|
+
Decidim::Verifications::AuthorizeUser.call(handler, current_organization) do
|
28
|
+
on(:transferred) do |transfer|
|
29
|
+
message += render_to_string("callout", locals: { i18n_key: "authorization_transferred", klass: "success" }) if transfer.records.any?
|
30
|
+
end
|
31
|
+
on(:invalid) do
|
32
|
+
if force_verification.present?
|
33
|
+
create_forced_authorization
|
34
|
+
else
|
35
|
+
message = render_to_string("callout", locals: { i18n_key: "user_not_authorized", klass: "alert" })
|
36
|
+
message += render_to_string("edit", locals: { with_override: true })
|
37
|
+
end
|
38
|
+
end
|
39
|
+
on(:ok) do
|
40
|
+
Decidim::ActionLogger.log("admin_creates_authorization", current_user, user, nil, user_id: user.id, handler: workflow.name, handler_name: workflow.fullname)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
render json: {
|
46
|
+
message:,
|
47
|
+
granted: granted?,
|
48
|
+
userId: user.id,
|
49
|
+
handler: workflow.name
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
message = if destroy_authorization
|
55
|
+
render_to_string("callout", locals: { i18n_key: "authorization_destroyed", klass: "success" })
|
56
|
+
else
|
57
|
+
render_to_string("callout", locals: { i18n_key: "authorization_not_destroyed", klass: "alert" })
|
58
|
+
end
|
59
|
+
|
60
|
+
render json: {
|
61
|
+
message:,
|
62
|
+
granted: granted?,
|
63
|
+
userId: user.id,
|
64
|
+
handler: workflow.name
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def create_forced_authorization
|
71
|
+
Decidim::Authorization.create_or_update_from(handler)
|
72
|
+
Decidim::ActionLogger.log("admin_forces_authorization", current_user, user, nil, handler: workflow.name, user_id: user.id, handler_name: workflow.fullname,
|
73
|
+
reason: force_verification)
|
74
|
+
end
|
75
|
+
|
76
|
+
def destroy_authorization
|
77
|
+
if authorization&.destroy
|
78
|
+
Decidim::ActionLogger.log("admin_destroys_authorization", current_user, user, nil, user_id: user.id, handler: workflow.name, handler_name: workflow.fullname)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def json_error(exception)
|
83
|
+
render plain: render_to_string("callout", locals: { message: exception.message, klass: "alert" }), status: :unprocessable_entity
|
84
|
+
end
|
85
|
+
|
86
|
+
def user
|
87
|
+
@user ||= Decidim::User.find(params[:id])
|
88
|
+
end
|
89
|
+
|
90
|
+
def authorization
|
91
|
+
@authorization ||= Decidim::Authorization.where.not(granted_at: nil).find_by(user:, name: workflow.name)
|
92
|
+
end
|
93
|
+
|
94
|
+
def granted?
|
95
|
+
authorization&.reload.present?
|
96
|
+
rescue ActiveRecord::RecordNotFound
|
97
|
+
false
|
98
|
+
end
|
99
|
+
|
100
|
+
def workflow
|
101
|
+
@workflow ||= Decidim::Verifications.find_workflow_manifest(params[:handler])
|
102
|
+
end
|
103
|
+
|
104
|
+
def handler
|
105
|
+
@handler ||= Decidim::AuthorizationHandler.handler_for(params[:handler], handler_params)
|
106
|
+
end
|
107
|
+
|
108
|
+
def conflict
|
109
|
+
@conflict ||= Decidim::Authorization.find_by(unique_id: handler.unique_id)
|
110
|
+
end
|
111
|
+
|
112
|
+
def handler_params
|
113
|
+
(params[:authorization_handler] || {}).merge(user:)
|
114
|
+
end
|
115
|
+
|
116
|
+
def force_verification
|
117
|
+
@force_verification ||= params[:force_verification].to_s.strip.presence
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -35,7 +35,7 @@ module Decidim
|
|
35
35
|
case part
|
36
36
|
when :CSS
|
37
37
|
['<%= append_stylesheet_pack_tag "decidim_decidim_awesome", media: "all" %>',
|
38
|
-
'<%= render(partial: "layouts/decidim/decidim_awesome/custom_styles") if
|
38
|
+
'<%= render(partial: "layouts/decidim/decidim_awesome/custom_styles") if awesome_scoped_styles %>'].join("\n")
|
39
39
|
when :JavaScript
|
40
40
|
['<%= render partial: "layouts/decidim/decidim_awesome/awesome_config" %>',
|
41
41
|
'<%= append_javascript_pack_tag "decidim_decidim_awesome", defer: false %>',
|
@@ -9,7 +9,7 @@ module Decidim
|
|
9
9
|
include ConfigConstraintsHelpers
|
10
10
|
helper ConfigConstraintsHelpers
|
11
11
|
|
12
|
-
helper_method :constraints_for, :users_for, :config_var
|
12
|
+
helper_method :constraints_for, :users_for, :config_var, :available_authorizations
|
13
13
|
before_action do
|
14
14
|
enforce_permission_to :edit_config, configs
|
15
15
|
end
|
@@ -98,6 +98,12 @@ module Decidim
|
|
98
98
|
def format_user_name(user)
|
99
99
|
"#{user.name} (@#{user.nickname} - #{user.email})"
|
100
100
|
end
|
101
|
+
|
102
|
+
def available_authorizations
|
103
|
+
@available_authorizations ||= Decidim::Verifications::Adapter.from_collection(
|
104
|
+
current_organization.available_authorizations & Decidim.authorization_workflows.map(&:name)
|
105
|
+
)
|
106
|
+
end
|
101
107
|
end
|
102
108
|
end
|
103
109
|
end
|
@@ -10,8 +10,10 @@ module Decidim
|
|
10
10
|
helper ConfigConstraintsHelpers
|
11
11
|
|
12
12
|
layout false
|
13
|
+
helper_method :constraint_key
|
14
|
+
|
13
15
|
before_action do
|
14
|
-
render
|
16
|
+
render :no_permissions unless allowed_to? :edit_config, constraint_key
|
15
17
|
end
|
16
18
|
|
17
19
|
def show
|
@@ -128,6 +130,8 @@ module Decidim
|
|
128
130
|
case key
|
129
131
|
when /^scoped_style_/
|
130
132
|
:scoped_styles
|
133
|
+
when /^scoped_admin_style_/
|
134
|
+
:scoped_admin_styles
|
131
135
|
when /^scoped_admin_/
|
132
136
|
:scoped_admins
|
133
137
|
when /^proposal_custom_field_/
|