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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +43 -13
  3. data/app/commands/decidim/action_delegator/admin/create_delegation.rb +1 -1
  4. data/app/commands/decidim/action_delegator/admin/create_participant.rb +1 -1
  5. data/app/commands/decidim/action_delegator/admin/create_ponderation.rb +1 -1
  6. data/app/commands/decidim/action_delegator/admin/create_setting.rb +1 -1
  7. data/app/commands/decidim/action_delegator/admin/fix_resource_permissions.rb +1 -1
  8. data/app/commands/decidim/action_delegator/admin/update_participant.rb +1 -1
  9. data/app/commands/decidim/action_delegator/admin/update_ponderation.rb +1 -1
  10. data/app/commands/decidim/action_delegator/admin/update_setting.rb +1 -1
  11. data/app/controllers/concerns/decidim/action_delegator/devise/sessions_controller_override.rb +48 -0
  12. data/app/controllers/decidim/action_delegator/admin/consultations_controller.rb +1 -1
  13. data/app/controllers/decidim/action_delegator/admin/delegations_controller.rb +1 -1
  14. data/app/controllers/decidim/action_delegator/admin/manage_delegations_controller.rb +3 -4
  15. data/app/controllers/decidim/action_delegator/admin/manage_participants_controller.rb +2 -3
  16. data/app/controllers/decidim/action_delegator/admin/settings_controller.rb +1 -1
  17. data/app/controllers/decidim/action_delegator/questions_summary_controller.rb +14 -0
  18. data/app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb +38 -15
  19. data/app/forms/decidim/action_delegator/admin/delegation_form.rb +6 -2
  20. data/app/forms/decidim/action_delegator/verifications/delegations_verifier_form.rb +7 -5
  21. data/app/helpers/decidim/action_delegator/admin/delegation_helper.rb +1 -1
  22. data/app/jobs/decidim/action_delegator/send_sms_job.rb +1 -0
  23. data/app/models/concerns/decidim/action_delegator/consultations/question_override.rb +36 -0
  24. data/app/models/decidim/action_delegator/delegation.rb +25 -0
  25. data/app/models/decidim/action_delegator/participant.rb +15 -11
  26. data/app/overrides/decidim/consultations/admin/consultations/results/add_ongoing_warning.html.erb.deface +3 -0
  27. data/app/overrides/decidim/consultations/consultations/_question/replace_vote_info.html.erb.deface +4 -0
  28. data/app/overrides/decidim/consultations/questions/_results/replace_results.html.erb.deface +3 -0
  29. data/app/overrides/decidim/consultations/questions/_vote_button/add_modal.html.erb.deface +1 -1
  30. data/app/overrides/decidim/consultations/questions/_vote_button/add_modal_javascript.html.erb.deface +3 -0
  31. data/app/overrides/layouts/decidim/_consultation_header/add_consultation_callout.html.erb.deface +9 -0
  32. data/app/overrides/layouts/decidim/_question_header/add_consultation_callout.html.erb.deface +9 -0
  33. data/app/packs/entrypoints/decidim_action_delegator_questions_summary.js +1 -0
  34. data/app/packs/src/decidim/action_delegator/questions.js +6 -0
  35. data/app/packs/src/decidim/action_delegator/summary.js +24 -0
  36. data/app/packs/stylesheets/decidim/action_delegator/questions.scss +1 -1
  37. data/app/queries/decidim/action_delegator/consultation_delegations.rb +1 -1
  38. data/app/queries/decidim/action_delegator/delegates_votes_by_consultation.rb +1 -1
  39. data/app/queries/decidim/action_delegator/delegates_votes_by_question.rb +1 -1
  40. data/app/queries/decidim/action_delegator/delegation_votes.rb +1 -1
  41. data/app/queries/decidim/action_delegator/organization_delegations.rb +1 -1
  42. data/app/queries/decidim/action_delegator/organization_settings.rb +1 -1
  43. data/app/queries/decidim/action_delegator/{published_responses.rb → responses.rb} +1 -2
  44. data/app/queries/decidim/action_delegator/responses_by_membership.rb +1 -1
  45. data/app/queries/decidim/action_delegator/setting_delegations.rb +1 -1
  46. data/app/queries/decidim/action_delegator/sum_of_membership_weight.rb +1 -1
  47. data/app/queries/decidim/action_delegator/sum_of_weights.rb +2 -2
  48. data/app/queries/decidim/action_delegator/type_and_weight.rb +2 -2
  49. data/app/queries/decidim/action_delegator/voted_with_ponderations.rb +1 -1
  50. data/app/services/decidim/action_delegator/delegations_csv_importer.rb +3 -3
  51. data/app/views/decidim/action_delegator/admin/consultations/_ongoing_consultation_warning.html.erb +3 -0
  52. data/app/views/decidim/action_delegator/admin/consultations/results.html.erb +3 -0
  53. data/app/views/decidim/action_delegator/admin/consultations/weighted_results.html.erb +3 -0
  54. data/app/views/decidim/action_delegator/admin/delegations/new.html.erb +24 -26
  55. data/app/views/decidim/action_delegator/admin/manage_delegations/new.html.erb +27 -22
  56. data/app/views/decidim/action_delegator/admin/manage_participants/new.html.erb +3 -1
  57. data/app/views/decidim/action_delegator/admin/participants/edit.html.erb +14 -16
  58. data/app/views/decidim/action_delegator/admin/participants/new.html.erb +14 -16
  59. data/app/views/decidim/action_delegator/admin/ponderations/edit.html.erb +14 -16
  60. data/app/views/decidim/action_delegator/admin/ponderations/new.html.erb +14 -16
  61. data/app/views/decidim/action_delegator/consultations/_link_with_results.html.erb +11 -0
  62. data/app/views/decidim/action_delegator/consultations/questions/_delegations_modal.html.erb +0 -2
  63. data/app/views/decidim/action_delegator/consultations/questions/_link_to_delegations.html.erb +9 -5
  64. data/app/views/decidim/action_delegator/consultations/questions/_weight_results.html.erb +8 -0
  65. data/app/views/decidim/consultations/question_votes/_callout.html.erb +47 -0
  66. data/app/views/decidim/consultations/question_votes/update_vote_button.js.erb +55 -5
  67. data/config/assets.rb +2 -1
  68. data/config/locales/ca.yml +97 -40
  69. data/config/locales/en.yml +13 -1
  70. data/config/locales/es.yml +106 -46
  71. data/lib/decidim/action_delegator/admin_engine.rb +15 -1
  72. data/lib/decidim/action_delegator/engine.rb +4 -1
  73. data/lib/decidim/action_delegator/verifications/delegations_authorizer.rb +1 -3
  74. data/lib/decidim/action_delegator/version.rb +3 -3
  75. data/lib/decidim/action_delegator.rb +12 -1
  76. metadata +38 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca4612ec0f7ff48ca4db9c6ce96adf9563afd16c898b45333fc3e63177c70454
4
- data.tar.gz: f503d3d4b9d4ab544e60909c1907aff6b405cbe54dce8eab3330c7e718ea6b50
3
+ metadata.gz: 86b19e1b854993702dadf3708f277d118c966380818bc6833f217aba2a6a6ef1
4
+ data.tar.gz: cc1855838e4640a8836aabb25bc0adb5cc38967ae44d6eca3b2dce29454f3ac0
5
5
  SHA512:
6
- metadata.gz: 8a32dd04273f2f27ee30969e638ec3341365214fdaa22ec37cdbe0a6d2a2cb4c98c1bd78b680eb2cc162a48fd2b7277993f6b85180ab1e51357bdf53d6c791aa
7
- data.tar.gz: e4629f6b1eb8d5debdb3bafabce31563f5d63ffbf498909068e317dfb2a13311f1753035d7def22c3c4dc16b0760a626627079a08942372d1671592d3964ac19
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.26.0
20
- * [decidim-admin](https://github.com/decidim/decidim/tree/master/decidim-admin) >= v0.26.0
21
- * [decidim-core](https://github.com/decidim/decidim/tree/master/decidim-core) >= v0.26.0
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
- > **IMPORTANT:**
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.7.x | 0.26.x |
61
- | 0.6.x | 0.26.x |
62
- | 0.5 | 0.25.x |
63
- | 0.4 | 0.24.x |
64
- | 0.3 | 0.24.x |
65
- | 0.2 | 0.23.x |
66
- | 0.1 | 0.22.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
-
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class CreateDelegation < Rectify::Command
6
+ class CreateDelegation < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class CreateParticipant < Rectify::Command
6
+ class CreateParticipant < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class CreatePonderation < Rectify::Command
6
+ class CreatePonderation < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class CreateSetting < Rectify::Command
6
+ class CreateSetting < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class FixResourcePermissions < Rectify::Command
6
+ class FixResourcePermissions < Decidim::Command
7
7
  def initialize(resources)
8
8
  @resources = resources
9
9
  @errors = []
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class UpdateParticipant < Rectify::Command
6
+ class UpdateParticipant < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class UpdatePonderation < Rectify::Command
6
+ class UpdatePonderation < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -3,7 +3,7 @@
3
3
  module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
- class UpdateSetting < Rectify::Command
6
+ class UpdateSetting < Decidim::Command
7
7
  # Public: Initializes the command.
8
8
  #
9
9
  # form - A form object with the params.
@@ -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
@@ -39,7 +39,7 @@ module Decidim
39
39
  end
40
40
 
41
41
  def published_questions_responses
42
- VotedWithPonderations.new(PublishedResponses.new(current_consultation).query).query
42
+ VotedWithPonderations.new(Responses.new(current_consultation).query).query
43
43
  end
44
44
  end
45
45
  end
@@ -25,7 +25,7 @@ module Decidim
25
25
  def create
26
26
  enforce_permission_to :create, :delegation
27
27
 
28
- @form = DelegationForm.from_params(params)
28
+ @form = form(DelegationForm).from_params(params)
29
29
 
30
30
  CreateDelegation.call(@form, current_user, current_setting) do
31
31
  on(:ok) do
@@ -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 seting_manage_delegations_path && return if @csv_file.blank?
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(importer_type, csv_file, current_user, current_setting)
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 decidim_admin_action_delegator.setting_delegations_path(current_setting)
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(importer_type, csv_file, current_user, current_setting)
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.map { |setting| [setting.consultation.id, translated_attribute(setting.title)] }.to_h
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
- enforce_permission_to :create, :authorization, authorization: authorization
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
- authorization.grant!
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
- if redirect_url
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
- return setting.participants.none if phone.blank?
74
-
75
- params[:phone] = phone
76
- params[:phone] = phone_prefixes.map { |prefix| "#{prefix}#{phone}" }
77
- params[:phone] += phone_prefixes.map { |prefix| phone.delete_prefix(prefix).to_s }
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(Participant.where.not(decidim_user: current_organization.users)).where.not(id: missing_registered_users(participants))
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)
@@ -5,6 +5,7 @@ require "savon"
5
5
  module Decidim
6
6
  module ActionDelegator
7
7
  class SendSmsJobException < StandardError; end
8
+
8
9
  class SendSmsJob < ApplicationJob
9
10
  queue_as :default
10
11
 
@@ -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.email_required?
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 ||= if Decidim::Consultations::Vote
89
- .joins(question: :consultation)
90
- .where(decidim_consultations_questions: {
91
- decidim_consultation_id: setting.consultation.id
92
- }, author: user).any?
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
@@ -0,0 +1,3 @@
1
+ <!-- insert_before '.table-list' -->
2
+
3
+ <%= render "decidim/action_delegator/admin/consultations/ongoing_consultation_warning", consultation: current_consultation %>
@@ -0,0 +1,4 @@
1
+ <!-- replace_contents "erb[silent]:contains('if question.results_published?')"
2
+ closing_selector "erb[silent]:contains('else')" -->
3
+
4
+ <%= render partial: "decidim/action_delegator/consultations/link_with_results", locals: { question: question } %>
@@ -0,0 +1,3 @@
1
+ <!-- replace_contents ".card--list" -->
2
+
3
+ <%= render partial: "decidim/action_delegator/consultations/questions/weight_results", locals: { response: response, question: question } %>
@@ -1,3 +1,3 @@
1
- <!-- insert_before "erb[loud]:contains('javascript_pack_tag')" -->
1
+ <!-- insert_before "erb[silent]:contains('content_for :js_content')" -->
2
2
 
3
3
  <%= render partial: "decidim/action_delegator/consultations/questions/delegations_modal", locals: { question: question } %>
@@ -0,0 +1,3 @@
1
+ <!-- insert_before "erb[loud]:contains('javascript_pack_tag')" -->
2
+
3
+ <%= javascript_pack_tag "decidim_action_delegator_questions" %>
@@ -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";