decidim-action_delegator 0.7.2 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -13
- data/app/commands/decidim/action_delegator/admin/create_delegation.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/create_participant.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/create_ponderation.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/create_setting.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/fix_resource_permissions.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/update_participant.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/update_ponderation.rb +1 -1
- data/app/commands/decidim/action_delegator/admin/update_setting.rb +1 -1
- data/app/controllers/concerns/decidim/action_delegator/devise/sessions_controller_override.rb +48 -0
- data/app/controllers/decidim/action_delegator/admin/consultations_controller.rb +1 -1
- data/app/controllers/decidim/action_delegator/admin/delegations_controller.rb +1 -1
- data/app/controllers/decidim/action_delegator/admin/manage_delegations_controller.rb +3 -4
- data/app/controllers/decidim/action_delegator/admin/manage_participants_controller.rb +2 -3
- data/app/controllers/decidim/action_delegator/admin/settings_controller.rb +1 -1
- data/app/controllers/decidim/action_delegator/questions_summary_controller.rb +14 -0
- data/app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb +38 -15
- data/app/forms/decidim/action_delegator/admin/delegation_form.rb +6 -2
- data/app/forms/decidim/action_delegator/verifications/delegations_verifier_form.rb +7 -5
- data/app/helpers/decidim/action_delegator/admin/delegation_helper.rb +1 -1
- data/app/jobs/decidim/action_delegator/send_sms_job.rb +1 -0
- data/app/models/concerns/decidim/action_delegator/consultations/question_override.rb +36 -0
- data/app/models/decidim/action_delegator/delegation.rb +25 -0
- data/app/models/decidim/action_delegator/participant.rb +15 -11
- data/app/overrides/decidim/consultations/admin/consultations/results/add_ongoing_warning.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/consultations/_question/replace_vote_info.html.erb.deface +4 -0
- data/app/overrides/decidim/consultations/questions/_results/replace_results.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/questions/_vote_button/add_modal.html.erb.deface +1 -1
- data/app/overrides/decidim/consultations/questions/_vote_button/add_modal_javascript.html.erb.deface +3 -0
- data/app/overrides/layouts/decidim/_consultation_header/add_consultation_callout.html.erb.deface +9 -0
- data/app/overrides/layouts/decidim/_question_header/add_consultation_callout.html.erb.deface +9 -0
- data/app/packs/entrypoints/decidim_action_delegator_questions_summary.js +1 -0
- data/app/packs/src/decidim/action_delegator/questions.js +6 -0
- data/app/packs/src/decidim/action_delegator/summary.js +24 -0
- data/app/packs/stylesheets/decidim/action_delegator/questions.scss +1 -1
- data/app/queries/decidim/action_delegator/consultation_delegations.rb +1 -1
- data/app/queries/decidim/action_delegator/delegates_votes_by_consultation.rb +1 -1
- data/app/queries/decidim/action_delegator/delegates_votes_by_question.rb +1 -1
- data/app/queries/decidim/action_delegator/delegation_votes.rb +1 -1
- data/app/queries/decidim/action_delegator/organization_delegations.rb +1 -1
- data/app/queries/decidim/action_delegator/organization_settings.rb +1 -1
- data/app/queries/decidim/action_delegator/{published_responses.rb → responses.rb} +1 -2
- data/app/queries/decidim/action_delegator/responses_by_membership.rb +1 -1
- data/app/queries/decidim/action_delegator/setting_delegations.rb +1 -1
- data/app/queries/decidim/action_delegator/sum_of_membership_weight.rb +1 -1
- data/app/queries/decidim/action_delegator/sum_of_weights.rb +2 -2
- data/app/queries/decidim/action_delegator/type_and_weight.rb +2 -2
- data/app/queries/decidim/action_delegator/voted_with_ponderations.rb +1 -1
- data/app/services/decidim/action_delegator/delegations_csv_importer.rb +3 -3
- data/app/views/decidim/action_delegator/admin/consultations/_ongoing_consultation_warning.html.erb +3 -0
- data/app/views/decidim/action_delegator/admin/consultations/results.html.erb +3 -0
- data/app/views/decidim/action_delegator/admin/consultations/weighted_results.html.erb +3 -0
- data/app/views/decidim/action_delegator/admin/delegations/new.html.erb +24 -26
- data/app/views/decidim/action_delegator/admin/manage_delegations/new.html.erb +27 -22
- data/app/views/decidim/action_delegator/admin/manage_participants/new.html.erb +3 -1
- data/app/views/decidim/action_delegator/admin/participants/edit.html.erb +14 -16
- data/app/views/decidim/action_delegator/admin/participants/new.html.erb +14 -16
- data/app/views/decidim/action_delegator/admin/ponderations/edit.html.erb +14 -16
- data/app/views/decidim/action_delegator/admin/ponderations/new.html.erb +14 -16
- data/app/views/decidim/action_delegator/consultations/_link_with_results.html.erb +11 -0
- data/app/views/decidim/action_delegator/consultations/questions/_delegations_modal.html.erb +0 -2
- data/app/views/decidim/action_delegator/consultations/questions/_link_to_delegations.html.erb +9 -5
- data/app/views/decidim/action_delegator/consultations/questions/_weight_results.html.erb +8 -0
- data/app/views/decidim/consultations/question_votes/_callout.html.erb +47 -0
- data/app/views/decidim/consultations/question_votes/update_vote_button.js.erb +55 -5
- data/config/assets.rb +2 -1
- data/config/locales/ca.yml +97 -40
- data/config/locales/en.yml +13 -1
- data/config/locales/es.yml +106 -46
- data/lib/decidim/action_delegator/admin_engine.rb +15 -1
- data/lib/decidim/action_delegator/engine.rb +4 -1
- data/lib/decidim/action_delegator/verifications/delegations_authorizer.rb +1 -3
- data/lib/decidim/action_delegator/version.rb +3 -3
- data/lib/decidim/action_delegator.rb +12 -1
- metadata +38 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86b19e1b854993702dadf3708f277d118c966380818bc6833f217aba2a6a6ef1
|
4
|
+
data.tar.gz: cc1855838e4640a8836aabb25bc0adb5cc38967ae44d6eca3b2dce29454f3ac0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dede3edfb646c09476cada959f9c613b851bdf6bb7b95f3d4aaf9db90e3c2f7756c4b6ae7dc9f11c5be2b017860fe02b339ada863bfd29333367e7bcf1147f3f
|
7
|
+
data.tar.gz: 1b91d0c5bbba56a7f3a4c2ae030bf9904cad6aac865637a1701d0cf25edd8e634cc26062576a65df9e310b61bd6f13f3bfaa8d6ae85c1586b16b166e16a3dcd1
|
data/README.md
CHANGED
@@ -16,9 +16,9 @@ Initially, only votes on consultations can be delegated.
|
|
16
16
|
|
17
17
|
## Dependencies
|
18
18
|
|
19
|
-
* [decidim-consultations](https://github.com/decidim/decidim/tree/master/decidim-consultations) >= v0.
|
20
|
-
* [decidim-admin](https://github.com/decidim/decidim/tree/master/decidim-admin) >= v0.
|
21
|
-
* [decidim-core](https://github.com/decidim/decidim/tree/master/decidim-core) >= v0.
|
19
|
+
* [decidim-consultations](https://github.com/decidim/decidim/tree/master/decidim-consultations) >= v0.27.0
|
20
|
+
* [decidim-admin](https://github.com/decidim/decidim/tree/master/decidim-admin) >= v0.27.0
|
21
|
+
* [decidim-core](https://github.com/decidim/decidim/tree/master/decidim-core) >= v0.27.0
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -42,7 +42,37 @@ bundle exec rails decidim_action_delegator:install:migrations
|
|
42
42
|
bundle exec rails db:migrate
|
43
43
|
```
|
44
44
|
|
45
|
-
|
45
|
+
**ActiveJob Configuration**
|
46
|
+
|
47
|
+
This module can send invitations to users in order to register into the platform.
|
48
|
+
If you are using Sidekiq (or another queue processor), you need to make sure that the `invite_participants` queue is processed by Sidekiq.
|
49
|
+
|
50
|
+
For instance, this file should work for Sidekiq:
|
51
|
+
|
52
|
+
`config/sidekiq.yml`
|
53
|
+
|
54
|
+
```yaml
|
55
|
+
:concurrency: <%= ENV.fetch("SIDEKIQ_CONCURRENCY", "5").to_i %>
|
56
|
+
:queues:
|
57
|
+
- [mailers, 4]
|
58
|
+
- [invite_participants, 4]
|
59
|
+
- [vote_reminder, 2]
|
60
|
+
- [reminders, 2]
|
61
|
+
- [default, 2]
|
62
|
+
- [newsletter, 2]
|
63
|
+
- [newsletters_opt_in, 2]
|
64
|
+
- [conference_diplomas, 2]
|
65
|
+
- [events, 2]
|
66
|
+
- [translations, 2]
|
67
|
+
- [user_report, 2]
|
68
|
+
- [block_user, 2]
|
69
|
+
- [metrics, 1]
|
70
|
+
- [exports, 1]
|
71
|
+
- [close_meeting_reminder, 1]
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
> **UPGRADE NOTES:**
|
46
76
|
>
|
47
77
|
> If you are upgrading from a previous version, you need to run the migrations again and import all membership types/weights into the built-in census by executing in your production server:
|
48
78
|
>
|
@@ -56,14 +86,15 @@ bundle exec rails db:migrate
|
|
56
86
|
Depending on your Decidim version, you can choose the corresponding version to ensure compatibility:
|
57
87
|
|
58
88
|
| Version | Compatible Decidim versions |
|
59
|
-
|
60
|
-
| 0.
|
61
|
-
| 0.
|
62
|
-
| 0.
|
63
|
-
| 0.
|
64
|
-
| 0.
|
65
|
-
| 0.
|
66
|
-
| 0.
|
89
|
+
|---------|-----------------------------|
|
90
|
+
| 0.8.x | 0.27.x |
|
91
|
+
| 0.7.x | 0.26.x |
|
92
|
+
| 0.6.x | 0.26.x |
|
93
|
+
| 0.5 | 0.25.x |
|
94
|
+
| 0.4 | 0.24.x |
|
95
|
+
| 0.3 | 0.24.x |
|
96
|
+
| 0.2 | 0.23.x |
|
97
|
+
| 0.1 | 0.22.0 |
|
67
98
|
|
68
99
|
*Heads up!* [Consultations module will be deprecated in the near future.](https://github.com/decidim/decidim/issues/7097)
|
69
100
|
|
@@ -328,4 +359,3 @@ This engine is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
|
|
328
359
|
## About
|
329
360
|
|
330
361
|
This plugin is currently maintained by [![Pokecode](app/packs/images/logo-pokecode.png)](https://pokecode.net)with much appreciated contributions from other companies.
|
331
|
-
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
module Devise
|
6
|
+
module SessionsControllerOverride
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
alias_method :after_sign_in_path_for_original, :after_sign_in_path_for
|
11
|
+
|
12
|
+
# automatically authorize the user if theres a setting for it
|
13
|
+
def after_sign_in_path_for(user)
|
14
|
+
after_sign_in_path_for_original(user) unless authorize_user_with_delegations_verifier(user)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def authorize_user_with_delegations_verifier(user)
|
21
|
+
setting = Decidim::ActionDelegator::OrganizationSettings.new(current_user.organization).active.first
|
22
|
+
delegations_verifier_authorization = Decidim::Authorization.find_or_initialize_by(
|
23
|
+
user: user,
|
24
|
+
name: "delegations_verifier"
|
25
|
+
)
|
26
|
+
|
27
|
+
return unless ActionDelegator.authorize_on_login
|
28
|
+
return unless user.present? && !user.blocked?
|
29
|
+
return unless setting&.verify_with_email? && !delegations_verifier_authorization.granted?
|
30
|
+
|
31
|
+
form = Decidim::ActionDelegator::Verifications::DelegationsVerifierForm.new.with_context(
|
32
|
+
current_user: user,
|
33
|
+
setting: setting
|
34
|
+
)
|
35
|
+
Decidim::Verifications::PerformAuthorizationStep.call(delegations_verifier_authorization, form) do
|
36
|
+
on(:ok) do
|
37
|
+
delegations_verifier_authorization.grant!
|
38
|
+
form.participant.update!(decidim_user: user)
|
39
|
+
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
|
40
|
+
return true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -22,15 +22,14 @@ module Decidim
|
|
22
22
|
enforce_permission_to :create, :delegation
|
23
23
|
|
24
24
|
@csv_file = params[:csv_file]
|
25
|
-
redirect_to
|
25
|
+
redirect_to(new_setting_manage_delegation_path) && return if @csv_file.blank?
|
26
26
|
|
27
|
-
importer_type = "DelegationsCsvImporter"
|
28
27
|
csv_file = @csv_file.read.force_encoding("utf-8").encode("utf-8")
|
29
|
-
@import_summary = Decidim::ActionDelegator::Admin::ImportCsvJob.perform_now(
|
28
|
+
@import_summary = Decidim::ActionDelegator::Admin::ImportCsvJob.perform_now("DelegationsCsvImporter", csv_file, current_user, current_setting)
|
30
29
|
|
31
30
|
flash[:notice] = t(".success")
|
32
31
|
|
33
|
-
redirect_to
|
32
|
+
redirect_to setting_delegations_path(current_setting)
|
34
33
|
end
|
35
34
|
|
36
35
|
private
|
@@ -24,9 +24,8 @@ module Decidim
|
|
24
24
|
@csv_file = params[:csv_file]
|
25
25
|
redirect_to seting_manage_participants_path && return if @csv_file.blank?
|
26
26
|
|
27
|
-
importer_type = "ParticipantsCsvImporter"
|
28
27
|
csv_file = @csv_file.read.force_encoding("utf-8").encode("utf-8")
|
29
|
-
@import_summary = Decidim::ActionDelegator::Admin::ImportCsvJob.perform_later(
|
28
|
+
@import_summary = Decidim::ActionDelegator::Admin::ImportCsvJob.perform_later("ParticipantsCsvImporter", csv_file, current_user, current_setting)
|
30
29
|
|
31
30
|
flash[:notice] = t(".success")
|
32
31
|
|
@@ -34,7 +33,7 @@ module Decidim
|
|
34
33
|
end
|
35
34
|
|
36
35
|
def destroy_all
|
37
|
-
enforce_permission_to :destroy, :participant, resource: current_setting
|
36
|
+
enforce_permission_to :destroy, :participant, { resource: current_setting }
|
38
37
|
|
39
38
|
participants_to_remove = current_setting.participants.reject(&:voted?)
|
40
39
|
|
@@ -98,7 +98,7 @@ module Decidim
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def settings_select_options
|
101
|
-
collection.
|
101
|
+
collection.to_h { |setting| [setting.consultation.id, translated_attribute(setting.title)] }
|
102
102
|
end
|
103
103
|
|
104
104
|
def copy_from_setting
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
# This controller handles user profile actions for this module
|
6
|
+
class QuestionsSummaryController < ActionDelegator::ApplicationController
|
7
|
+
include Decidim::Consultations::NeedsConsultation
|
8
|
+
|
9
|
+
def show
|
10
|
+
render partial: "decidim/consultations/question_votes/callout", locals: { consultation: current_consultation }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -10,10 +10,30 @@ module Decidim
|
|
10
10
|
|
11
11
|
helper_method :authorization, :setting
|
12
12
|
|
13
|
+
before_action do
|
14
|
+
unless setting
|
15
|
+
flash[:alert] = t("verifications.delegations_verifier.not_active", scope: "decidim.action_delegator")
|
16
|
+
redirect
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
13
20
|
def new
|
14
|
-
|
21
|
+
@authorization.destroy! if authorization&.persisted? && !authorization&.granted?
|
15
22
|
|
23
|
+
enforce_permission_to :create, :authorization, authorization: authorization
|
16
24
|
@form = form(DelegationsVerifierForm).instance(setting: setting)
|
25
|
+
participant = @form&.participant
|
26
|
+
|
27
|
+
return unless ActionDelegator.authorize_on_login && setting&.verify_with_email?
|
28
|
+
|
29
|
+
Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do
|
30
|
+
on(:ok) do
|
31
|
+
grant_and_redirect(participant)
|
32
|
+
end
|
33
|
+
on(:invalid) do
|
34
|
+
render :new
|
35
|
+
end
|
36
|
+
end
|
17
37
|
end
|
18
38
|
|
19
39
|
def create
|
@@ -29,15 +49,7 @@ module Decidim
|
|
29
49
|
authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name)
|
30
50
|
redirect_to authorization_method.resume_authorization_path(redirect_url: redirect_url)
|
31
51
|
else
|
32
|
-
|
33
|
-
participant.update!(decidim_user: authorization.user)
|
34
|
-
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
|
35
|
-
|
36
|
-
if redirect_url
|
37
|
-
redirect_to redirect_url
|
38
|
-
else
|
39
|
-
redirect_to decidim_verifications.authorizations_path
|
40
|
-
end
|
52
|
+
grant_and_redirect(participant)
|
41
53
|
end
|
42
54
|
end
|
43
55
|
on(:invalid) do
|
@@ -62,11 +74,7 @@ module Decidim
|
|
62
74
|
on(:ok) do
|
63
75
|
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
|
64
76
|
|
65
|
-
|
66
|
-
redirect_to redirect_url
|
67
|
-
else
|
68
|
-
redirect_to decidim_verifications.authorizations_path
|
69
|
-
end
|
77
|
+
redirect
|
70
78
|
end
|
71
79
|
|
72
80
|
on(:invalid) do
|
@@ -87,6 +95,21 @@ module Decidim
|
|
87
95
|
|
88
96
|
private
|
89
97
|
|
98
|
+
def grant_and_redirect(participant)
|
99
|
+
authorization.grant!
|
100
|
+
participant.update!(decidim_user: authorization.user)
|
101
|
+
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
|
102
|
+
redirect
|
103
|
+
end
|
104
|
+
|
105
|
+
def redirect
|
106
|
+
if redirect_url
|
107
|
+
redirect_to redirect_url
|
108
|
+
else
|
109
|
+
redirect_to decidim_verifications.authorizations_path
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
90
113
|
def authorization
|
91
114
|
@authorization ||= Decidim::Authorization.find_or_initialize_by(
|
92
115
|
user: current_user,
|
@@ -18,15 +18,19 @@ module Decidim
|
|
18
18
|
validate :grantee_exists
|
19
19
|
|
20
20
|
def granter
|
21
|
-
User.find_by(id: granter_id) || User.find_by(email: granter_email)
|
21
|
+
User.find_by(id: granter_id, organization: current_organization) || User.find_by(email: granter_email, organization: current_organization)
|
22
22
|
end
|
23
23
|
|
24
24
|
def grantee
|
25
|
-
User.find_by(id: grantee_id) || User.find_by(email: grantee_email)
|
25
|
+
User.find_by(id: grantee_id, organization: current_organization) || User.find_by(email: grantee_email, organization: current_organization)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
+
def current_organization
|
31
|
+
context&.current_organization
|
32
|
+
end
|
33
|
+
|
30
34
|
def granter_exists
|
31
35
|
return if granter.present?
|
32
36
|
|
@@ -70,11 +70,13 @@ module Decidim
|
|
70
70
|
params = {}
|
71
71
|
params[:email] = email if setting.email_required?
|
72
72
|
if setting.phone_required?
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
if phone.blank?
|
74
|
+
@participant = setting.participants.none
|
75
|
+
else
|
76
|
+
params[:phone] = phone
|
77
|
+
params[:phone] = phone_prefixes.map { |prefix| "#{prefix}#{phone}" }
|
78
|
+
params[:phone] += phone_prefixes.map { |prefix| phone.delete_prefix(prefix).to_s }
|
79
|
+
end
|
78
80
|
end
|
79
81
|
|
80
82
|
setting.participants.find_by(params)
|
@@ -31,7 +31,7 @@ module Decidim
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def missing_decidim_users(participants)
|
34
|
-
participants.where(decidim_user: nil).or(
|
34
|
+
participants.where(decidim_user: nil).or(participants.where.not(decidim_user: current_organization.users)).where.not(id: missing_registered_users(participants))
|
35
35
|
end
|
36
36
|
|
37
37
|
def missing_registered_users(participants)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
module Consultations
|
6
|
+
module QuestionOverride
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
# if results can be shown to admins
|
11
|
+
def publishable_results?
|
12
|
+
(ActionDelegator.admin_preview_results || consultation.finished?) && sorted_results.any?
|
13
|
+
end
|
14
|
+
|
15
|
+
def weighted_responses
|
16
|
+
@weighted_responses ||= Decidim::ActionDelegator::SumOfWeights.new(consultation).query.group_by(&:question_id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def total_weighted_votes
|
20
|
+
@total_weighted_votes ||= weighted_responses[id].sum(&:votes_count)
|
21
|
+
end
|
22
|
+
|
23
|
+
def most_weighted_voted_response
|
24
|
+
weighted_responses[id].max_by(&:votes_count)
|
25
|
+
end
|
26
|
+
|
27
|
+
def responses_sorted_by_weighted_votes
|
28
|
+
@responses_sorted_by_weighted_votes ||= weighted_responses.transform_values do |responses|
|
29
|
+
responses.sort_by { |response| -response.votes_count }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -16,6 +16,10 @@ module Decidim
|
|
16
16
|
message: I18n.t("delegations.create.error_granter_unique", scope: "decidim.action_delegator.admin")
|
17
17
|
}
|
18
18
|
|
19
|
+
validate :grantee_is_not_granter
|
20
|
+
validate :granter_and_grantee_belongs_to_same_organization
|
21
|
+
validate :granter_is_same_organization_as_consultation
|
22
|
+
|
19
23
|
delegate :consultation, to: :setting
|
20
24
|
|
21
25
|
before_destroy { |record| throw(:abort) if record.grantee_voted? }
|
@@ -32,6 +36,27 @@ module Decidim
|
|
32
36
|
granter_votes&.detect { |vote| vote.versions.exists?(whodunnit: grantee&.id) } ? true : false
|
33
37
|
end
|
34
38
|
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def grantee_is_not_granter
|
43
|
+
return unless granter == grantee
|
44
|
+
|
45
|
+
errors.add(:grantee, :invalid)
|
46
|
+
end
|
47
|
+
|
48
|
+
def granter_and_grantee_belongs_to_same_organization
|
49
|
+
return unless granter.organization != grantee.organization
|
50
|
+
|
51
|
+
errors.add(:grantee, :invalid)
|
52
|
+
end
|
53
|
+
|
54
|
+
def granter_is_same_organization_as_consultation
|
55
|
+
return unless setting && setting.consultation
|
56
|
+
return unless consultation.organization != granter.organization
|
57
|
+
|
58
|
+
errors.add(:granter, :invalid)
|
59
|
+
end
|
35
60
|
end
|
36
61
|
end
|
37
62
|
end
|
@@ -21,11 +21,12 @@ module Decidim
|
|
21
21
|
delegate :consultation, to: :setting
|
22
22
|
delegate :organization, to: :setting
|
23
23
|
|
24
|
-
validates :setting, presence: true
|
25
24
|
validates :decidim_user, uniqueness: { scope: :setting }, if: -> { decidim_user.present? }
|
26
25
|
validates :email, uniqueness: { scope: :setting }, if: -> { email.present? }
|
27
26
|
validates :phone, uniqueness: { scope: :setting }, if: -> { phone.present? }
|
28
27
|
|
28
|
+
validate :user_belongs_to_organization
|
29
|
+
|
29
30
|
# sets the decidim user if found
|
30
31
|
before_save :set_decidim_user
|
31
32
|
|
@@ -37,7 +38,7 @@ module Decidim
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def user_from_metadata
|
40
|
-
@user_from_metadata ||= if setting
|
41
|
+
@user_from_metadata ||= if setting&.email_required?
|
41
42
|
Decidim::User.find_by(email: email, organization: setting.organization)
|
42
43
|
else
|
43
44
|
Decidim::Authorization.find_by(unique_id: uniq_ids)&.user
|
@@ -85,15 +86,11 @@ module Decidim
|
|
85
86
|
def voted?
|
86
87
|
return false if user.blank?
|
87
88
|
|
88
|
-
@voted ||=
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
true
|
94
|
-
else
|
95
|
-
false
|
96
|
-
end
|
89
|
+
@voted ||= Decidim::Consultations::Vote
|
90
|
+
.joins(question: :consultation)
|
91
|
+
.where(decidim_consultations_questions: {
|
92
|
+
decidim_consultation_id: setting.consultation.id
|
93
|
+
}, author: user).any?
|
97
94
|
end
|
98
95
|
|
99
96
|
private
|
@@ -101,6 +98,13 @@ module Decidim
|
|
101
98
|
def set_decidim_user
|
102
99
|
self.decidim_user = user_from_metadata if decidim_user.blank?
|
103
100
|
end
|
101
|
+
|
102
|
+
def user_belongs_to_organization
|
103
|
+
return unless decidim_user && setting && setting.consultation
|
104
|
+
return if decidim_user.organization == organization
|
105
|
+
|
106
|
+
errors.add(:decidim_user, :invalid)
|
107
|
+
end
|
104
108
|
end
|
105
109
|
end
|
106
110
|
end
|
data/app/overrides/layouts/decidim/_consultation_header/add_consultation_callout.html.erb.deface
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<!-- insert_after '.consultations-home-banner' -->
|
2
|
+
|
3
|
+
<% if user_signed_in? %>
|
4
|
+
<div id="user-answers-summary" class="row" style="padding:0 1rem;margint-top:-1rem" data-summary-path="<%= decidim_action_delegator.questions_summary_path(current_consultation) %>">
|
5
|
+
<%= render "decidim/consultations/question_votes/callout", consultation: current_consultation %>
|
6
|
+
|
7
|
+
<%= javascript_pack_tag "decidim_action_delegator_questions_summary" %>
|
8
|
+
</div>
|
9
|
+
<% end %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<!-- insert_before 'h2' -->
|
2
|
+
|
3
|
+
<% if user_signed_in? %>
|
4
|
+
<div id="user-answers-summary" data-summary-path="<%= decidim_action_delegator.questions_summary_path(current_question.consultation) %>">
|
5
|
+
<%= render "decidim/consultations/question_votes/callout", consultation: current_question.consultation %>
|
6
|
+
|
7
|
+
<%= javascript_pack_tag "decidim_action_delegator_questions_summary" %>
|
8
|
+
</div>
|
9
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
import "src/decidim/action_delegator/summary.js";
|