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.
- checksums.yaml +4 -4
- data/README.md +97 -36
- data/app/commands/{decidim → concerns/decidim}/action_delegator/consultations/vote_question_override.rb +9 -1
- data/app/commands/decidim/action_delegator/admin/create_delegation.rb +5 -1
- data/app/commands/decidim/action_delegator/admin/create_participant.rb +41 -0
- data/app/commands/decidim/action_delegator/admin/create_ponderation.rb +38 -0
- data/app/commands/decidim/action_delegator/admin/create_setting.rb +49 -0
- data/app/commands/decidim/action_delegator/admin/fix_resource_permissions.rb +46 -0
- data/app/commands/decidim/action_delegator/admin/update_participant.rb +42 -0
- data/app/commands/decidim/action_delegator/admin/update_ponderation.rb +41 -0
- data/app/commands/decidim/action_delegator/admin/update_setting.rb +66 -0
- data/app/controllers/concerns/decidim/action_delegator/consultations/consultations_controller_override.rb +16 -0
- data/app/controllers/{decidim → concerns/decidim}/action_delegator/consultations/question_multiple_votes_controller_override.rb +2 -1
- data/app/controllers/{decidim → concerns/decidim}/action_delegator/consultations/question_votes_controller_override.rb +2 -0
- data/app/controllers/concerns/decidim/action_delegator/consultations/questions_controller_override.rb +16 -0
- data/app/controllers/concerns/decidim/action_delegator/needs_consultation_styles.rb +24 -0
- data/app/controllers/decidim/action_delegator/admin/consultations_controller.rb +22 -8
- data/app/controllers/decidim/action_delegator/admin/delegations_controller.rb +9 -9
- data/app/controllers/decidim/action_delegator/admin/invite_participants_controller.rb +84 -0
- data/app/controllers/decidim/action_delegator/admin/manage_delegations_controller.rb +48 -0
- data/app/controllers/decidim/action_delegator/admin/manage_participants_controller.rb +59 -0
- data/app/controllers/decidim/action_delegator/admin/participants_controller.rb +102 -0
- data/app/controllers/decidim/action_delegator/admin/permissions_controller.rb +40 -0
- data/app/controllers/decidim/action_delegator/admin/ponderations_controller.rb +101 -0
- data/app/controllers/decidim/action_delegator/admin/settings_controller.rb +51 -12
- data/app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb +108 -0
- data/app/forms/decidim/action_delegator/admin/delegation_form.rb +23 -4
- data/app/forms/decidim/action_delegator/admin/invitation_participant_form.rb +10 -0
- data/app/forms/decidim/action_delegator/admin/participant_form.rb +44 -0
- data/app/forms/decidim/action_delegator/admin/ponderation_form.rb +28 -0
- data/app/forms/decidim/action_delegator/admin/setting_form.rb +28 -0
- data/app/forms/decidim/action_delegator/verifications/delegations_verifier_form.rb +131 -0
- data/app/helpers/decidim/action_delegator/admin/delegation_helper.rb +40 -3
- data/app/helpers/decidim/action_delegator/delegation_helper.rb +13 -0
- data/app/jobs/decidim/action_delegator/admin/import_csv_job.rb +27 -0
- data/app/jobs/decidim/action_delegator/admin/invite_participants_job.rb +39 -0
- data/app/jobs/decidim/action_delegator/sync_participants_job.rb +27 -0
- data/app/mailers/decidim/action_delegator/import_mailer.rb +31 -0
- data/app/models/decidim/action_delegator/delegation.rb +11 -0
- data/app/models/decidim/action_delegator/participant.rb +106 -0
- data/app/models/decidim/action_delegator/ponderation.rb +28 -0
- data/app/models/decidim/action_delegator/setting.rb +50 -1
- data/app/overrides/decidim/consultations/consultations/_question/add_delegation_link.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/consultations/_regular_questions/remove_highlighted_scopes.html.erb.deface +4 -0
- data/app/overrides/decidim/consultations/question_multiple_votes/_form/add_delegation_notice.html.erb.deface +8 -0
- data/app/overrides/decidim/consultations/questions/_vote_button/add_delegations_link.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/questions/_vote_button/add_modal.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/questions/_vote_button/replace_delegation_to_multivote_link.html.erb.deface +8 -0
- data/app/overrides/decidim/consultations/questions/_vote_modal/add_delegation_callout.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_delegation_callout.html.erb.deface +3 -0
- data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_hidden_field.html.erb.deface +3 -0
- data/app/overrides/layouts/decidim/admin/remove_deprecation.rb +10 -0
- data/app/packs/entrypoints/decidim_action_delegator_questions.js +2 -0
- data/app/packs/src/decidim/action_delegator/questions.js +27 -0
- data/app/packs/stylesheets/decidim/action_delegator/questions.scss +4 -3
- data/app/permissions/concerns/decidim/action_delegator/consultations/permissions_override.rb +35 -0
- data/app/permissions/decidim/action_delegator/permissions.rb +6 -2
- data/app/queries/decidim/action_delegator/delegated_votes_versions.rb +5 -11
- data/app/queries/decidim/action_delegator/organization_settings.rb +6 -0
- data/app/queries/decidim/action_delegator/responses_by_membership.rb +3 -20
- data/app/queries/decidim/action_delegator/sum_of_membership_weight.rb +1 -5
- data/app/queries/decidim/action_delegator/sum_of_weights.rb +1 -1
- data/app/queries/decidim/action_delegator/type_and_weight.rb +1 -1
- data/app/queries/decidim/action_delegator/voted_with_ponderations.rb +30 -0
- data/app/services/decidim/action_delegator/csv_importer.rb +86 -0
- data/app/services/decidim/action_delegator/delegations_csv_importer.rb +54 -0
- data/app/services/decidim/action_delegator/participants_csv_importer.rb +131 -0
- data/app/views/decidim/action_delegator/admin/consultations/results.html.erb +3 -3
- data/app/views/decidim/action_delegator/admin/{results/sum_of_weights/index.html.erb → consultations/weighted_results.html.erb} +3 -3
- data/app/views/decidim/action_delegator/admin/delegations/index.html.erb +8 -3
- data/app/views/decidim/action_delegator/admin/delegations/new.html.erb +15 -12
- data/app/views/decidim/action_delegator/admin/manage_delegations/new.html.erb +25 -0
- data/app/views/decidim/action_delegator/admin/manage_participants/new.html.erb +33 -0
- data/app/views/decidim/action_delegator/admin/participants/_form.html.erb +9 -0
- data/app/views/decidim/action_delegator/admin/participants/_missing_registered_check.html.erb +17 -0
- data/app/views/decidim/action_delegator/admin/participants/edit.html.erb +21 -0
- data/app/views/decidim/action_delegator/admin/participants/index.html.erb +72 -0
- data/app/views/decidim/action_delegator/admin/participants/new.html.erb +21 -0
- data/app/views/decidim/action_delegator/admin/ponderations/_form.html.erb +8 -0
- data/app/views/decidim/action_delegator/admin/ponderations/edit.html.erb +21 -0
- data/app/views/decidim/action_delegator/admin/ponderations/index.html.erb +40 -0
- data/app/views/decidim/action_delegator/admin/ponderations/new.html.erb +21 -0
- data/app/views/decidim/action_delegator/admin/settings/_check_verifier.html.erb +5 -0
- data/app/views/decidim/action_delegator/admin/settings/_form.html.erb +16 -0
- data/app/views/decidim/action_delegator/admin/settings/_participants_email_check.html.erb +7 -0
- data/app/views/decidim/action_delegator/admin/settings/_participants_sync_check.html.erb +11 -0
- data/app/views/decidim/action_delegator/admin/settings/_setting_checks.html.erb +81 -0
- data/app/views/decidim/action_delegator/admin/settings/edit.html.erb +18 -0
- data/app/views/decidim/action_delegator/admin/settings/index.html.erb +25 -5
- data/app/views/decidim/action_delegator/admin/settings/new.html.erb +14 -26
- data/app/views/decidim/action_delegator/consultations/_link_to_question.html.erb +11 -0
- data/app/views/decidim/action_delegator/consultations/questions/_delegations_modal.html.erb +36 -0
- data/app/views/decidim/action_delegator/consultations/questions/_link_to_delegations.html.erb +11 -0
- data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_active.html.erb +32 -0
- data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_finished.html.erb +9 -0
- data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_upcoming.html.erb +8 -0
- data/app/views/decidim/action_delegator/import_mailer/import.html.erb +11 -0
- data/app/views/decidim/{verifications/sms/authorizations/new.html.erb → action_delegator/verifications/delegations_verifier/authorizations/edit.html.erb} +12 -7
- data/app/views/decidim/action_delegator/verifications/delegations_verifier/authorizations/new.html.erb +49 -0
- data/config/assets.rb +1 -3
- data/config/i18n-tasks.yml +8 -0
- data/config/locales/ca.yml +287 -23
- data/config/locales/cs.yml +286 -18
- data/config/locales/en.yml +331 -24
- data/config/locales/es.yml +288 -24
- data/db/migrate/20230323101247_create_decidim_action_delegator_ponderations.rb +12 -0
- data/db/migrate/20230323210000_create_decidim_action_delegator_participants.rb +13 -0
- data/db/migrate/20230323223752_add_decidim_action_delegator_verification_method.rb +7 -0
- data/db/migrate/20230412105710_add_decidim_action_delegator_participants_user_id.rb +7 -0
- data/lib/decidim/action_delegator/admin_engine.rb +68 -6
- data/lib/decidim/action_delegator/engine.rb +25 -15
- data/lib/decidim/action_delegator/test/factories.rb +22 -7
- data/lib/decidim/action_delegator/verifications/delegations_authorizer.rb +85 -0
- data/lib/decidim/action_delegator/verifications/delegations_verifier/engine.rb +25 -0
- data/lib/decidim/action_delegator/verifications/delegations_verifier.rb +12 -0
- data/lib/decidim/action_delegator/version.rb +3 -3
- data/lib/decidim/action_delegator.rb +41 -0
- data/lib/tasks/import_direct_verification.rake +30 -0
- data/package.json +57 -0
- metadata +115 -50
- data/app/controllers/decidim/action_delegator/admin/results/sum_of_weights_controller.rb +0 -37
- data/app/controllers/decidim/action_delegator/verifications/sms/authorizations_controller_override.rb +0 -38
- data/app/packs/entrypoints/decidim_action_delegator_admin_action_delegator_js.js +0 -1
- data/app/packs/entrypoints/decidim_action_delegator_questions_js.js +0 -1
- data/app/packs/src/decidim/action_delegator/admin/action_delegator.js.es6 +0 -3
- data/app/packs/src/decidim/action_delegator/questions.js.es6 +0 -26
- data/app/permissions/decidim/action_delegator/consultations_permissions_extension.rb +0 -27
- data/app/presenters/decidim/action_delegator/admin/consultation_presenter.rb +0 -15
- data/app/presenters/decidim/action_delegator/admin/setting_presenter.rb +0 -13
- data/app/queries/decidim/action_delegator/decrypted_authorizations.rb +0 -112
- data/app/queries/decidim/action_delegator/json_build_object_query.rb +0 -45
- data/app/queries/decidim/action_delegator/voted_with_direct_verification.rb +0 -53
- data/app/views/decidim/action_delegator/_delegations_modal.html.erb +0 -93
- data/app/views/decidim/action_delegator/_link_to_delegations.html.erb +0 -5
- data/app/views/decidim/action_delegator/_link_to_question.html.erb +0 -5
- data/app/views/decidim/consultations/consultations/_question.html.erb +0 -41
- data/app/views/decidim/consultations/consultations/show.html.erb +0 -14
- data/app/views/decidim/consultations/question_multiple_votes/_form.html.erb +0 -25
- data/app/views/decidim/consultations/questions/_vote_button.html.erb +0 -106
- data/app/views/decidim/consultations/questions/_vote_modal.html.erb +0 -30
- data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +0 -38
- data/app/views/layouts/decidim/action_delegator/admin/_users_sidebar.html.erb +0 -56
- data/app/views/layouts/decidim/action_delegator/admin/delegations.html.erb +0 -13
- data/app/views/layouts/decidim/admin/consultation.html.erb +0 -56
- data/app/views/layouts/decidim/admin/question.html.erb +0 -98
- data/app/views/layouts/decidim/admin/users.html.erb +0 -7
- data/config/initializers/doorkeeper.rb +0 -492
- data/lib/json_key.rb +0 -10
- /data/app/commands/{decidim → concerns/decidim}/action_delegator/consultations/multiple_vote_question_override.rb +0 -0
- /data/app/controllers/decidim/action_delegator/admin/exports/{sum_of_weights_controller.rb → _sum_of_weights_controller.rb} +0 -0
- /data/app/forms/{decidim → concerns/decidim}/action_delegator/consultations/vote_form_override.rb +0 -0
- /data/app/models/{decidim → concerns/decidim}/action_delegator/consultations/vote_override.rb +0 -0
- /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
|
-
|
11
|
-
|
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
|
24
|
-
|
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
|
-
|
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/
|
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(
|
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(
|
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
|
-
@
|
21
|
+
@form = form(SettingForm).instance
|
24
22
|
end
|
25
23
|
|
26
24
|
def create
|
27
25
|
enforce_permission_to :create, :setting
|
28
26
|
|
29
|
-
@
|
27
|
+
@form = form(SettingForm).from_params(params)
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|