decidim-action_delegator 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +97 -36
  3. data/app/commands/{decidim → concerns/decidim}/action_delegator/consultations/vote_question_override.rb +9 -1
  4. data/app/commands/decidim/action_delegator/admin/create_delegation.rb +5 -1
  5. data/app/commands/decidim/action_delegator/admin/create_participant.rb +41 -0
  6. data/app/commands/decidim/action_delegator/admin/create_ponderation.rb +38 -0
  7. data/app/commands/decidim/action_delegator/admin/create_setting.rb +49 -0
  8. data/app/commands/decidim/action_delegator/admin/fix_resource_permissions.rb +46 -0
  9. data/app/commands/decidim/action_delegator/admin/update_participant.rb +42 -0
  10. data/app/commands/decidim/action_delegator/admin/update_ponderation.rb +41 -0
  11. data/app/commands/decidim/action_delegator/admin/update_setting.rb +66 -0
  12. data/app/controllers/concerns/decidim/action_delegator/consultations/consultations_controller_override.rb +16 -0
  13. data/app/controllers/{decidim → concerns/decidim}/action_delegator/consultations/question_multiple_votes_controller_override.rb +2 -1
  14. data/app/controllers/{decidim → concerns/decidim}/action_delegator/consultations/question_votes_controller_override.rb +2 -0
  15. data/app/controllers/concerns/decidim/action_delegator/consultations/questions_controller_override.rb +16 -0
  16. data/app/controllers/concerns/decidim/action_delegator/needs_consultation_styles.rb +24 -0
  17. data/app/controllers/decidim/action_delegator/admin/consultations_controller.rb +22 -8
  18. data/app/controllers/decidim/action_delegator/admin/delegations_controller.rb +9 -9
  19. data/app/controllers/decidim/action_delegator/admin/invite_participants_controller.rb +84 -0
  20. data/app/controllers/decidim/action_delegator/admin/manage_delegations_controller.rb +48 -0
  21. data/app/controllers/decidim/action_delegator/admin/manage_participants_controller.rb +59 -0
  22. data/app/controllers/decidim/action_delegator/admin/participants_controller.rb +102 -0
  23. data/app/controllers/decidim/action_delegator/admin/permissions_controller.rb +40 -0
  24. data/app/controllers/decidim/action_delegator/admin/ponderations_controller.rb +101 -0
  25. data/app/controllers/decidim/action_delegator/admin/settings_controller.rb +51 -12
  26. data/app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb +108 -0
  27. data/app/forms/decidim/action_delegator/admin/delegation_form.rb +23 -4
  28. data/app/forms/decidim/action_delegator/admin/invitation_participant_form.rb +10 -0
  29. data/app/forms/decidim/action_delegator/admin/participant_form.rb +44 -0
  30. data/app/forms/decidim/action_delegator/admin/ponderation_form.rb +28 -0
  31. data/app/forms/decidim/action_delegator/admin/setting_form.rb +28 -0
  32. data/app/forms/decidim/action_delegator/verifications/delegations_verifier_form.rb +131 -0
  33. data/app/helpers/decidim/action_delegator/admin/delegation_helper.rb +40 -3
  34. data/app/helpers/decidim/action_delegator/delegation_helper.rb +13 -0
  35. data/app/jobs/decidim/action_delegator/admin/import_csv_job.rb +27 -0
  36. data/app/jobs/decidim/action_delegator/admin/invite_participants_job.rb +39 -0
  37. data/app/jobs/decidim/action_delegator/sync_participants_job.rb +27 -0
  38. data/app/mailers/decidim/action_delegator/import_mailer.rb +31 -0
  39. data/app/models/decidim/action_delegator/delegation.rb +11 -0
  40. data/app/models/decidim/action_delegator/participant.rb +106 -0
  41. data/app/models/decidim/action_delegator/ponderation.rb +28 -0
  42. data/app/models/decidim/action_delegator/setting.rb +50 -1
  43. data/app/overrides/decidim/consultations/consultations/_question/add_delegation_link.html.erb.deface +3 -0
  44. data/app/overrides/decidim/consultations/consultations/_regular_questions/remove_highlighted_scopes.html.erb.deface +4 -0
  45. data/app/overrides/decidim/consultations/question_multiple_votes/_form/add_delegation_notice.html.erb.deface +8 -0
  46. data/app/overrides/decidim/consultations/questions/_vote_button/add_delegations_link.html.erb.deface +3 -0
  47. data/app/overrides/decidim/consultations/questions/_vote_button/add_modal.html.erb.deface +3 -0
  48. data/app/overrides/decidim/consultations/questions/_vote_button/replace_delegation_to_multivote_link.html.erb.deface +8 -0
  49. data/app/overrides/decidim/consultations/questions/_vote_modal/add_delegation_callout.html.erb.deface +3 -0
  50. data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_delegation_callout.html.erb.deface +3 -0
  51. data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_hidden_field.html.erb.deface +3 -0
  52. data/app/overrides/layouts/decidim/admin/remove_deprecation.rb +10 -0
  53. data/app/packs/entrypoints/decidim_action_delegator_questions.js +2 -0
  54. data/app/packs/src/decidim/action_delegator/questions.js +27 -0
  55. data/app/packs/stylesheets/decidim/action_delegator/questions.scss +4 -3
  56. data/app/permissions/concerns/decidim/action_delegator/consultations/permissions_override.rb +35 -0
  57. data/app/permissions/decidim/action_delegator/permissions.rb +6 -2
  58. data/app/queries/decidim/action_delegator/delegated_votes_versions.rb +5 -11
  59. data/app/queries/decidim/action_delegator/organization_settings.rb +6 -0
  60. data/app/queries/decidim/action_delegator/responses_by_membership.rb +3 -20
  61. data/app/queries/decidim/action_delegator/sum_of_membership_weight.rb +1 -5
  62. data/app/queries/decidim/action_delegator/sum_of_weights.rb +1 -1
  63. data/app/queries/decidim/action_delegator/type_and_weight.rb +1 -1
  64. data/app/queries/decidim/action_delegator/voted_with_ponderations.rb +30 -0
  65. data/app/services/decidim/action_delegator/csv_importer.rb +86 -0
  66. data/app/services/decidim/action_delegator/delegations_csv_importer.rb +54 -0
  67. data/app/services/decidim/action_delegator/participants_csv_importer.rb +131 -0
  68. data/app/views/decidim/action_delegator/admin/consultations/results.html.erb +3 -3
  69. data/app/views/decidim/action_delegator/admin/{results/sum_of_weights/index.html.erb → consultations/weighted_results.html.erb} +3 -3
  70. data/app/views/decidim/action_delegator/admin/delegations/index.html.erb +8 -3
  71. data/app/views/decidim/action_delegator/admin/delegations/new.html.erb +15 -12
  72. data/app/views/decidim/action_delegator/admin/manage_delegations/new.html.erb +25 -0
  73. data/app/views/decidim/action_delegator/admin/manage_participants/new.html.erb +33 -0
  74. data/app/views/decidim/action_delegator/admin/participants/_form.html.erb +9 -0
  75. data/app/views/decidim/action_delegator/admin/participants/_missing_registered_check.html.erb +17 -0
  76. data/app/views/decidim/action_delegator/admin/participants/edit.html.erb +21 -0
  77. data/app/views/decidim/action_delegator/admin/participants/index.html.erb +72 -0
  78. data/app/views/decidim/action_delegator/admin/participants/new.html.erb +21 -0
  79. data/app/views/decidim/action_delegator/admin/ponderations/_form.html.erb +8 -0
  80. data/app/views/decidim/action_delegator/admin/ponderations/edit.html.erb +21 -0
  81. data/app/views/decidim/action_delegator/admin/ponderations/index.html.erb +40 -0
  82. data/app/views/decidim/action_delegator/admin/ponderations/new.html.erb +21 -0
  83. data/app/views/decidim/action_delegator/admin/settings/_check_verifier.html.erb +5 -0
  84. data/app/views/decidim/action_delegator/admin/settings/_form.html.erb +16 -0
  85. data/app/views/decidim/action_delegator/admin/settings/_participants_email_check.html.erb +7 -0
  86. data/app/views/decidim/action_delegator/admin/settings/_participants_sync_check.html.erb +11 -0
  87. data/app/views/decidim/action_delegator/admin/settings/_setting_checks.html.erb +81 -0
  88. data/app/views/decidim/action_delegator/admin/settings/edit.html.erb +18 -0
  89. data/app/views/decidim/action_delegator/admin/settings/index.html.erb +25 -5
  90. data/app/views/decidim/action_delegator/admin/settings/new.html.erb +14 -26
  91. data/app/views/decidim/action_delegator/consultations/_link_to_question.html.erb +11 -0
  92. data/app/views/decidim/action_delegator/consultations/questions/_delegations_modal.html.erb +36 -0
  93. data/app/views/decidim/action_delegator/consultations/questions/_link_to_delegations.html.erb +11 -0
  94. data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_active.html.erb +32 -0
  95. data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_finished.html.erb +9 -0
  96. data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_upcoming.html.erb +8 -0
  97. data/app/views/decidim/action_delegator/import_mailer/import.html.erb +11 -0
  98. data/app/views/decidim/{verifications/sms/authorizations/new.html.erb → action_delegator/verifications/delegations_verifier/authorizations/edit.html.erb} +12 -7
  99. data/app/views/decidim/action_delegator/verifications/delegations_verifier/authorizations/new.html.erb +49 -0
  100. data/config/assets.rb +1 -3
  101. data/config/i18n-tasks.yml +8 -0
  102. data/config/locales/ca.yml +287 -23
  103. data/config/locales/cs.yml +286 -18
  104. data/config/locales/en.yml +331 -24
  105. data/config/locales/es.yml +288 -24
  106. data/db/migrate/20230323101247_create_decidim_action_delegator_ponderations.rb +12 -0
  107. data/db/migrate/20230323210000_create_decidim_action_delegator_participants.rb +13 -0
  108. data/db/migrate/20230323223752_add_decidim_action_delegator_verification_method.rb +7 -0
  109. data/db/migrate/20230412105710_add_decidim_action_delegator_participants_user_id.rb +7 -0
  110. data/lib/decidim/action_delegator/admin_engine.rb +68 -6
  111. data/lib/decidim/action_delegator/engine.rb +25 -15
  112. data/lib/decidim/action_delegator/test/factories.rb +22 -7
  113. data/lib/decidim/action_delegator/verifications/delegations_authorizer.rb +85 -0
  114. data/lib/decidim/action_delegator/verifications/delegations_verifier/engine.rb +25 -0
  115. data/lib/decidim/action_delegator/verifications/delegations_verifier.rb +12 -0
  116. data/lib/decidim/action_delegator/version.rb +3 -3
  117. data/lib/decidim/action_delegator.rb +41 -0
  118. data/lib/tasks/import_direct_verification.rake +30 -0
  119. data/package.json +57 -0
  120. metadata +115 -50
  121. data/app/controllers/decidim/action_delegator/admin/results/sum_of_weights_controller.rb +0 -37
  122. data/app/controllers/decidim/action_delegator/verifications/sms/authorizations_controller_override.rb +0 -38
  123. data/app/packs/entrypoints/decidim_action_delegator_admin_action_delegator_js.js +0 -1
  124. data/app/packs/entrypoints/decidim_action_delegator_questions_js.js +0 -1
  125. data/app/packs/src/decidim/action_delegator/admin/action_delegator.js.es6 +0 -3
  126. data/app/packs/src/decidim/action_delegator/questions.js.es6 +0 -26
  127. data/app/permissions/decidim/action_delegator/consultations_permissions_extension.rb +0 -27
  128. data/app/presenters/decidim/action_delegator/admin/consultation_presenter.rb +0 -15
  129. data/app/presenters/decidim/action_delegator/admin/setting_presenter.rb +0 -13
  130. data/app/queries/decidim/action_delegator/decrypted_authorizations.rb +0 -112
  131. data/app/queries/decidim/action_delegator/json_build_object_query.rb +0 -45
  132. data/app/queries/decidim/action_delegator/voted_with_direct_verification.rb +0 -53
  133. data/app/views/decidim/action_delegator/_delegations_modal.html.erb +0 -93
  134. data/app/views/decidim/action_delegator/_link_to_delegations.html.erb +0 -5
  135. data/app/views/decidim/action_delegator/_link_to_question.html.erb +0 -5
  136. data/app/views/decidim/consultations/consultations/_question.html.erb +0 -41
  137. data/app/views/decidim/consultations/consultations/show.html.erb +0 -14
  138. data/app/views/decidim/consultations/question_multiple_votes/_form.html.erb +0 -25
  139. data/app/views/decidim/consultations/questions/_vote_button.html.erb +0 -106
  140. data/app/views/decidim/consultations/questions/_vote_modal.html.erb +0 -30
  141. data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +0 -38
  142. data/app/views/layouts/decidim/action_delegator/admin/_users_sidebar.html.erb +0 -56
  143. data/app/views/layouts/decidim/action_delegator/admin/delegations.html.erb +0 -13
  144. data/app/views/layouts/decidim/admin/consultation.html.erb +0 -56
  145. data/app/views/layouts/decidim/admin/question.html.erb +0 -98
  146. data/app/views/layouts/decidim/admin/users.html.erb +0 -7
  147. data/config/initializers/doorkeeper.rb +0 -492
  148. data/lib/json_key.rb +0 -10
  149. /data/app/commands/{decidim → concerns/decidim}/action_delegator/consultations/multiple_vote_question_override.rb +0 -0
  150. /data/app/controllers/decidim/action_delegator/admin/exports/{sum_of_weights_controller.rb → _sum_of_weights_controller.rb} +0 -0
  151. /data/app/forms/{decidim → concerns/decidim}/action_delegator/consultations/vote_form_override.rb +0 -0
  152. /data/app/models/{decidim → concerns/decidim}/action_delegator/consultations/vote_override.rb +0 -0
  153. /data/app/views/decidim/action_delegator/{_callout.html.erb → consultations/questions/_callout.html.erb} +0 -0
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Consultations
6
+ module QuestionsControllerOverride
7
+ extend ActiveSupport::Concern
8
+ include ::Decidim::ActionDelegator::NeedsConsultationStyles
9
+
10
+ included do
11
+ helper ::Decidim::ActionDelegator::DelegationHelper
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module NeedsConsultationStyles
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ helper_method :snippets
10
+ end
11
+
12
+ def snippets
13
+ @snippets ||= Decidim::Snippets.new
14
+
15
+ unless @snippets.any?(:action_delegator_consultation_questions)
16
+ @snippets.add(:action_delegator_consultation_questions, ActionController::Base.helpers.stylesheet_pack_tag("decidim_action_delegator_questions"))
17
+ @snippets.add(:head, @snippets.for(:action_delegator_consultation_questions))
18
+ end
19
+
20
+ @snippets
21
+ end
22
+ end
23
+ end
24
+ end
@@ -4,14 +4,16 @@ module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
6
  class ConsultationsController < Decidim::Consultations::Admin::ConsultationsController
7
+ layout "decidim/admin/consultation"
8
+
9
+ helper_method :questions, :total_delegates, :responses_by_membership, :responses_by_weight
10
+
7
11
  def results
8
12
  enforce_permission_to :read, :consultation, consultation: current_consultation
13
+ end
9
14
 
10
- @questions = Scrutiny.new(current_consultation).questions
11
- @responses = responses.group_by(&:decidim_consultations_questions_id)
12
- @total_delegates = DelegatesVotesByConsultation.new(current_consultation).query
13
-
14
- render layout: "decidim/admin/consultation"
15
+ def weighted_results
16
+ enforce_permission_to :read, :consultation, consultation: current_consultation
15
17
  end
16
18
 
17
19
  private
@@ -20,12 +22,24 @@ module Decidim
20
22
  Decidim.permissions_registry.chain_for(ActionDelegator::Admin::ApplicationController)
21
23
  end
22
24
 
23
- def responses
24
- ResponsesByMembership.new(published_questions_responses).query
25
+ def questions
26
+ @questions ||= Scrutiny.new(current_consultation).questions
27
+ end
28
+
29
+ def total_delegates
30
+ @total_delegates ||= DelegatesVotesByConsultation.new(current_consultation).query
31
+ end
32
+
33
+ def responses_by_membership
34
+ ResponsesByMembership.new(published_questions_responses).query.group_by(&:decidim_consultations_questions_id)
35
+ end
36
+
37
+ def responses_by_weight
38
+ SumOfWeights.new(current_consultation).query.group_by(&:question_id)
25
39
  end
26
40
 
27
41
  def published_questions_responses
28
- VotedWithDirectVerification.new(PublishedResponses.new(current_consultation).query).query
42
+ VotedWithPonderations.new(PublishedResponses.new(current_consultation).query).query
29
43
  end
30
44
  end
31
45
  end
@@ -7,15 +7,13 @@ module Decidim
7
7
  include NeedsPermission
8
8
  include Paginable
9
9
 
10
- helper DelegationHelper
11
- helper_method :current_setting
10
+ helper ::Decidim::ActionDelegator::Admin::DelegationHelper
11
+ helper_method :current_setting, :delegations
12
12
 
13
- layout "decidim/action_delegator/admin/delegations"
13
+ layout "decidim/admin/users"
14
14
 
15
15
  def index
16
16
  enforce_permission_to :index, :delegation
17
-
18
- @delegations = paginate(collection)
19
17
  end
20
18
 
21
19
  def new
@@ -45,14 +43,12 @@ module Decidim
45
43
  def destroy
46
44
  enforce_permission_to :destroy, :delegation, resource: delegation
47
45
 
48
- setting_id = delegation.setting.id
49
-
50
46
  if delegation.destroy
51
47
  notice = I18n.t("delegations.destroy.success", scope: "decidim.action_delegator.admin")
52
- redirect_to setting_delegations_path(setting_id), notice: notice
48
+ redirect_to setting_delegations_path(current_setting), notice: notice
53
49
  else
54
50
  error = I18n.t("delegations.destroy.error", scope: "decidim.action_delegator.admin")
55
- redirect_to setting_delegations_path(setting_id), flash: { error: error }
51
+ redirect_to setting_delegations_path(current_setting), flash: { error: error }
56
52
  end
57
53
  end
58
54
 
@@ -62,6 +58,10 @@ module Decidim
62
58
  @delegation ||= collection.find_by(id: params[:id])
63
59
  end
64
60
 
61
+ def delegations
62
+ @delegations ||= paginate(collection)
63
+ end
64
+
65
65
  def collection
66
66
  @collection ||= SettingDelegations.new(current_setting).query
67
67
  end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class InviteParticipantsController < ActionDelegator::Admin::ApplicationController
7
+ include NeedsPermission
8
+
9
+ before_action :enforce_permission_to_invite
10
+
11
+ helper_method :current_setting, :participant, :form
12
+
13
+ def invite_user
14
+ enforce_permission_to :invite, :participant, resource: current_setting
15
+
16
+ Decidim::InviteUser.call(form) do
17
+ on(:ok) do
18
+ notice = t("invite_user.success", scope: "decidim.action_delegator.admin.invite_participants")
19
+ redirect_to decidim_admin_action_delegator.setting_participants_path(current_setting), notice: notice
20
+ end
21
+ end
22
+ end
23
+
24
+ def invite_all_users
25
+ enforce_permission_to :invite, :participant, resource: current_setting
26
+
27
+ InviteParticipantsJob.perform_later(current_setting, current_organization)
28
+
29
+ notice = t("invite_all_users.success", scope: "decidim.action_delegator.admin.invite_participants")
30
+ redirect_to decidim_admin_action_delegator.setting_participants_path(current_setting), notice: notice
31
+ end
32
+
33
+ def resend_invitation
34
+ enforce_permission_to :invite, :participant, resource: current_setting
35
+
36
+ Decidim::InviteUserAgain.call(participant.user, "invitation_instructions") do
37
+ on(:ok) do
38
+ flash[:notice] = I18n.t("users.resend_invitation.success", scope: "decidim.admin")
39
+ end
40
+
41
+ redirect_to setting_participants_path(current_setting)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def current_setting
48
+ @current_setting ||= organization_settings.find_by(id: params[:setting_id])
49
+ end
50
+
51
+ def participants
52
+ @participants ||= current_setting.participants
53
+ end
54
+
55
+ def participant
56
+ @participant ||= participants.find_by(id: params[:id])
57
+ end
58
+
59
+ def organization_settings
60
+ ActionDelegator::OrganizationSettings.new(current_organization).query
61
+ end
62
+
63
+ def build_form(participant)
64
+ Decidim::ActionDelegator::Admin::InvitationParticipantForm.new(
65
+ name: participant.email.split("@").first&.gsub(/\W/, ""),
66
+ email: participant.email.downcase,
67
+ organization: current_organization,
68
+ admin: false,
69
+ invited_by: current_user
70
+ )
71
+ end
72
+
73
+ def form
74
+ @form ||= build_form(participant)
75
+ end
76
+
77
+ def enforce_permission_to_invite
78
+ alert = t("permissions.not_allowed", scope: "decidim.action_delegator.admin.invite_participants")
79
+ redirect_to setting_participants_path(current_setting), alert: alert unless Decidim::ActionDelegator.allow_to_invite_users
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class ManageDelegationsController < ActionDelegator::Admin::ApplicationController
7
+ include NeedsPermission
8
+ include Decidim::Paginable
9
+
10
+ helper ::Decidim::ActionDelegator::Admin::DelegationHelper
11
+ helper_method :organization_settings, :current_setting
12
+
13
+ layout "decidim/admin/users"
14
+
15
+ def new
16
+ enforce_permission_to :create, :delegation
17
+
18
+ @errors = []
19
+ end
20
+
21
+ def create
22
+ enforce_permission_to :create, :delegation
23
+
24
+ @csv_file = params[:csv_file]
25
+ redirect_to seting_manage_delegations_path && return if @csv_file.blank?
26
+
27
+ importer_type = "DelegationsCsvImporter"
28
+ 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)
30
+
31
+ flash[:notice] = t(".success")
32
+
33
+ redirect_to decidim_admin_action_delegator.setting_delegations_path(current_setting)
34
+ end
35
+
36
+ private
37
+
38
+ def current_setting
39
+ @current_setting ||= organization_settings.find_by(id: params[:setting_id])
40
+ end
41
+
42
+ def organization_settings
43
+ Decidim::ActionDelegator::OrganizationSettings.new(current_organization).query
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class ManageParticipantsController < ActionDelegator::Admin::ApplicationController
7
+ include NeedsPermission
8
+ include Decidim::Paginable
9
+
10
+ helper ::Decidim::ActionDelegator::Admin::DelegationHelper
11
+ helper_method :organization_settings, :current_setting
12
+
13
+ layout "decidim/admin/users"
14
+
15
+ def new
16
+ enforce_permission_to :create, :participant
17
+
18
+ @errors = []
19
+ end
20
+
21
+ def create
22
+ enforce_permission_to :create, :participant
23
+
24
+ @csv_file = params[:csv_file]
25
+ redirect_to seting_manage_participants_path && return if @csv_file.blank?
26
+
27
+ importer_type = "ParticipantsCsvImporter"
28
+ 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)
30
+
31
+ flash[:notice] = t(".success")
32
+
33
+ redirect_to decidim_admin_action_delegator.setting_participants_path(current_setting)
34
+ end
35
+
36
+ def destroy_all
37
+ enforce_permission_to :destroy, :participant, resource: current_setting
38
+
39
+ participants_to_remove = current_setting.participants.reject(&:voted?)
40
+
41
+ participants_to_remove.each(&:destroy)
42
+
43
+ flash[:notice] = I18n.t("participants.remove_census.success", scope: "decidim.action_delegator.admin", participants_count: participants_to_remove.count)
44
+ redirect_to setting_participants_path(current_setting)
45
+ end
46
+
47
+ private
48
+
49
+ def current_setting
50
+ @current_setting ||= organization_settings.find_by(id: params[:setting_id])
51
+ end
52
+
53
+ def organization_settings
54
+ Decidim::ActionDelegator::OrganizationSettings.new(current_organization).query
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class ParticipantsController < ActionDelegator::Admin::ApplicationController
7
+ include NeedsPermission
8
+ include Decidim::Paginable
9
+
10
+ helper ::Decidim::ActionDelegator::Admin::DelegationHelper
11
+ helper_method :current_setting, :participants
12
+
13
+ layout "decidim/admin/users"
14
+
15
+ def index
16
+ enforce_permission_to :index, :participant
17
+ end
18
+
19
+ def new
20
+ enforce_permission_to :create, :participant
21
+
22
+ @form = form(ParticipantForm).instance(setting: current_setting)
23
+ end
24
+
25
+ def create
26
+ enforce_permission_to :create, :participant
27
+
28
+ @form = form(ParticipantForm).from_params(params, setting: current_setting)
29
+
30
+ CreateParticipant.call(@form) do
31
+ on(:ok) do
32
+ notice = I18n.t("participants.create.success", scope: "decidim.action_delegator.admin")
33
+ redirect_to setting_participants_path(current_setting), notice: notice
34
+ end
35
+
36
+ on(:invalid) do |_error|
37
+ flash.now[:error] = I18n.t("participants.create.error", scope: "decidim.action_delegator.admin")
38
+ render :new
39
+ end
40
+ end
41
+ end
42
+
43
+ def edit
44
+ enforce_permission_to :update, :participant
45
+
46
+ @form = form(ParticipantForm).from_model(participant, setting: current_setting)
47
+ end
48
+
49
+ def update
50
+ enforce_permission_to :update, :participant
51
+
52
+ @form = form(ParticipantForm).from_params(params, setting: current_setting)
53
+ UpdateParticipant.call(@form, participant) do
54
+ on(:ok) do
55
+ notice = I18n.t("participants.update.success", scope: "decidim.action_delegator.admin")
56
+ redirect_to setting_participants_path(current_setting), notice: notice
57
+ end
58
+
59
+ on(:invalid) do |_error|
60
+ flash.now[:error] = I18n.t("participants.update.error", scope: "decidim.action_delegator.admin")
61
+ render :edit
62
+ end
63
+ end
64
+ end
65
+
66
+ def destroy
67
+ enforce_permission_to :destroy, :participant, resource: participant
68
+
69
+ if participant.destroy
70
+ notice = I18n.t("participants.destroy.success", scope: "decidim.action_delegator.admin")
71
+ redirect_to setting_participants_path(current_setting), notice: notice
72
+ else
73
+ error = I18n.t("participants.destroy.error", scope: "decidim.action_delegator.admin")
74
+ redirect_to setting_participants_path(current_setting), flash: { error: error }
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def participant
81
+ @participant ||= collection.find_by(id: params[:id])
82
+ end
83
+
84
+ def participants
85
+ @participants ||= paginate(collection)
86
+ end
87
+
88
+ def collection
89
+ @collection ||= current_setting.participants
90
+ end
91
+
92
+ def current_setting
93
+ @current_setting ||= organization_settings.find_by(id: params[:setting_id])
94
+ end
95
+
96
+ def organization_settings
97
+ ActionDelegator::OrganizationSettings.new(current_organization).query
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class PermissionsController < ActionDelegator::Admin::ApplicationController
7
+ def create
8
+ enforce_permission_to :update, :setting
9
+ return redirect_to decidim_admin_action_delegator.settings_path unless setting&.consultation
10
+
11
+ FixResourcePermissions.call(setting.consultation.questions) do
12
+ on(:ok) do
13
+ notice = I18n.t("permissions.update.success", scope: "decidim.action_delegator.admin")
14
+ redirect_to decidim_admin_action_delegator.settings_path, notice: notice
15
+ end
16
+
17
+ on(:invalid) do |_error|
18
+ flash.now[:error] = I18n.t("permissions.update.error", scope: "decidim.action_delegator.admin")
19
+ render :new
20
+ end
21
+ end
22
+ end
23
+
24
+ def sync
25
+ enforce_permission_to :update, :setting
26
+
27
+ SyncParticipantsJob.perform_later(setting)
28
+ notice = I18n.t("permissions.sync.started", scope: "decidim.action_delegator.admin")
29
+ redirect_to decidim_admin_action_delegator.settings_path, notice: notice
30
+ end
31
+
32
+ private
33
+
34
+ def setting
35
+ @setting ||= Decidim::ActionDelegator::Setting.find(params[:setting_id])
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ActionDelegator
5
+ module Admin
6
+ class PonderationsController < ActionDelegator::Admin::ApplicationController
7
+ include NeedsPermission
8
+ include Decidim::Paginable
9
+
10
+ helper_method :current_setting, :ponderations
11
+
12
+ layout "decidim/admin/users"
13
+
14
+ def index
15
+ enforce_permission_to :index, :ponderation
16
+ end
17
+
18
+ def new
19
+ enforce_permission_to :create, :ponderation
20
+
21
+ @form = form(PonderationForm).instance
22
+ end
23
+
24
+ def create
25
+ enforce_permission_to :create, :ponderation
26
+
27
+ @form = PonderationForm.from_params(params).with_context(setting: current_setting)
28
+
29
+ CreatePonderation.call(@form) do
30
+ on(:ok) do
31
+ notice = I18n.t("ponderations.create.success", scope: "decidim.action_delegator.admin")
32
+ redirect_to setting_ponderations_path(current_setting), notice: notice
33
+ end
34
+
35
+ on(:invalid) do |_error|
36
+ flash.now[:error] = I18n.t("ponderations.create.error", scope: "decidim.action_delegator.admin")
37
+ render :new
38
+ end
39
+ end
40
+ end
41
+
42
+ def edit
43
+ enforce_permission_to :update, :ponderation
44
+
45
+ @form = form(PonderationForm).from_model(ponderation)
46
+ end
47
+
48
+ def update
49
+ enforce_permission_to :update, :ponderation
50
+
51
+ @form = PonderationForm.from_params(params).with_context(setting: current_setting)
52
+ UpdatePonderation.call(@form, ponderation) do
53
+ on(:ok) do
54
+ notice = I18n.t("ponderations.update.success", scope: "decidim.action_delegator.admin")
55
+ redirect_to setting_ponderations_path(current_setting), notice: notice
56
+ end
57
+
58
+ on(:invalid) do |_error|
59
+ flash.now[:error] = I18n.t("ponderations.update.error", scope: "decidim.action_delegator.admin")
60
+ render :edit
61
+ end
62
+ end
63
+ end
64
+
65
+ def destroy
66
+ enforce_permission_to :destroy, :ponderation, resource: ponderation
67
+
68
+ if ponderation.destroy
69
+ notice = I18n.t("ponderations.destroy.success", scope: "decidim.action_delegator.admin")
70
+ redirect_to setting_ponderations_path(current_setting), notice: notice
71
+ else
72
+ error = I18n.t("ponderations.destroy.error", scope: "decidim.action_delegator.admin")
73
+ redirect_to setting_ponderations_path(current_setting), flash: { error: error }
74
+ end
75
+ end
76
+
77
+ private
78
+
79
+ def ponderation
80
+ @ponderation ||= collection.find_by(id: params[:id])
81
+ end
82
+
83
+ def ponderations
84
+ @ponderations ||= paginate(collection)
85
+ end
86
+
87
+ def collection
88
+ @collection ||= current_setting.ponderations
89
+ end
90
+
91
+ def current_setting
92
+ @current_setting ||= organization_settings.find_by(id: params[:setting_id])
93
+ end
94
+
95
+ def organization_settings
96
+ ActionDelegator::OrganizationSettings.new(current_organization).query
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -4,35 +4,62 @@ module Decidim
4
4
  module ActionDelegator
5
5
  module Admin
6
6
  class SettingsController < ActionDelegator::Admin::ApplicationController
7
- helper DelegationHelper
7
+ helper ::Decidim::ActionDelegator::Admin::DelegationHelper
8
8
  include Filterable
9
+ include Paginable
9
10
 
10
11
  layout "decidim/admin/users"
12
+ helper_method :settings, :settings_select_options, :copy_from_setting
11
13
 
12
14
  def index
13
15
  enforce_permission_to :index, :setting
14
-
15
- @settings = filtered_collection.map do |setting|
16
- SettingPresenter.new(setting)
17
- end
18
16
  end
19
17
 
20
18
  def new
21
19
  enforce_permission_to :create, :setting
22
20
 
23
- @setting = Setting.new(max_grants: 1)
21
+ @form = form(SettingForm).instance
24
22
  end
25
23
 
26
24
  def create
27
25
  enforce_permission_to :create, :setting
28
26
 
29
- @setting = build_setting
27
+ @form = form(SettingForm).from_params(params)
30
28
 
31
- if @setting.save
32
- flash[:notice] = I18n.t("settings.create.success", scope: "decidim.action_delegator.admin")
33
- redirect_to decidim_admin_action_delegator.settings_path
34
- else
35
- flash.now[:error] = I18n.t("settings.create.error", scope: "decidim.action_delegator.admin")
29
+ CreateSetting.call(@form, copy_from_setting) do
30
+ on(:ok) do
31
+ notice = I18n.t("settings.create.success", scope: "decidim.action_delegator.admin")
32
+ redirect_to decidim_admin_action_delegator.settings_path, notice: notice
33
+ end
34
+
35
+ on(:invalid) do |_error|
36
+ flash.now[:error] = I18n.t("settings.create.error", scope: "decidim.action_delegator.admin")
37
+ render :new
38
+ end
39
+ end
40
+ end
41
+
42
+ def edit
43
+ enforce_permission_to :update, :setting
44
+
45
+ @form = form(SettingForm).from_model(setting)
46
+ end
47
+
48
+ def update
49
+ enforce_permission_to :update, :setting
50
+
51
+ @form = form(SettingForm).from_params(params)
52
+
53
+ UpdateSetting.call(@form, setting, copy_from_setting) do
54
+ on(:ok) do
55
+ notice = I18n.t("settings.update.success", scope: "decidim.action_delegator.admin")
56
+ redirect_to decidim_admin_action_delegator.settings_path, notice: notice
57
+ end
58
+
59
+ on(:invalid) do |_error|
60
+ flash.now[:error] = I18n.t("settings.update.error", scope: "decidim.action_delegator.admin")
61
+ render :edit
62
+ end
36
63
  end
37
64
  end
38
65
 
@@ -62,9 +89,21 @@ module Decidim
62
89
  @setting ||= collection.find_by(id: params[:id])
63
90
  end
64
91
 
92
+ def settings
93
+ @settings ||= paginate(collection)
94
+ end
95
+
65
96
  def collection
66
97
  @collection ||= ActionDelegator::OrganizationSettings.new(current_organization).query
67
98
  end
99
+
100
+ def settings_select_options
101
+ collection.map { |setting| [setting.consultation.id, translated_attribute(setting.title)] }.to_h
102
+ end
103
+
104
+ def copy_from_setting
105
+ @copy_from_setting ||= Setting.find_by(decidim_consultation_id: params[:setting][:copy_from_setting_id])
106
+ end
68
107
  end
69
108
  end
70
109
  end