decidim-action_delegator 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +104 -58
- data/Rakefile +2 -2
- data/app/commands/decidim/action_delegator/admin/create_delegation.rb +1 -3
- data/app/commands/decidim/action_delegator/admin/create_setting.rb +5 -2
- data/app/commands/decidim/action_delegator/admin/update_setting.rb +4 -2
- data/app/controllers/concerns/decidim/action_delegator/devise/sessions_controller_override.rb +1 -1
- data/app/controllers/concerns/decidim/action_delegator/election_per_question_votes_controller_override.rb +65 -0
- data/app/controllers/concerns/decidim/action_delegator/election_votes_controller_override.rb +38 -0
- data/app/controllers/concerns/decidim/action_delegator/votes_controller_methods.rb +46 -0
- data/app/controllers/decidim/action_delegator/admin/application_controller.rb +11 -5
- data/app/controllers/decidim/action_delegator/admin/delegations_controller.rb +3 -11
- data/app/controllers/decidim/action_delegator/admin/invite_participants_controller.rb +0 -8
- data/app/controllers/decidim/action_delegator/admin/manage_delegations_controller.rb +13 -21
- data/app/controllers/decidim/action_delegator/admin/manage_participants_controller.rb +11 -20
- data/app/controllers/decidim/action_delegator/admin/participants_controller.rb +1 -9
- data/app/controllers/decidim/action_delegator/admin/permissions_controller.rb +1 -24
- data/app/controllers/decidim/action_delegator/admin/ponderations_controller.rb +0 -8
- data/app/controllers/decidim/action_delegator/admin/settings_controller.rb +12 -12
- data/app/controllers/decidim/action_delegator/application_controller.rb +3 -3
- data/app/controllers/decidim/action_delegator/elections/admin/results_controller.rb +58 -0
- data/app/controllers/decidim/action_delegator/elections/results_controller.rb +36 -0
- data/app/controllers/decidim/action_delegator/user_delegations_controller.rb +1 -1
- data/app/controllers/decidim/action_delegator/verifications/delegations_verifier/authorizations_controller.rb +14 -18
- data/app/forms/decidim/action_delegator/admin/action_delegator_census_form.rb +44 -0
- data/app/forms/decidim/action_delegator/admin/csv_import_form.rb +17 -0
- data/app/forms/decidim/action_delegator/admin/delegation_form.rb +6 -2
- data/app/forms/decidim/action_delegator/admin/ponderation_form.rb +2 -1
- data/app/forms/decidim/action_delegator/admin/setting_form.rb +16 -10
- data/app/forms/decidim/action_delegator/censuses/internal_users_form.rb +32 -0
- data/app/forms/decidim/action_delegator/verifications/delegations_verifier_form.rb +41 -25
- data/app/helpers/decidim/action_delegator/admin/{delegation_helper.rb → settings_helper.rb} +3 -16
- data/app/helpers/decidim/action_delegator/settings_helper.rb +124 -0
- data/app/jobs/decidim/action_delegator/admin/invite_participants_job.rb +1 -1
- data/app/jobs/decidim/action_delegator/send_sms_job.rb +2 -2
- data/app/jobs/decidim/action_delegator/twilio_send_sms_job.rb +2 -2
- data/app/models/decidim/action_delegator/delegation.rb +35 -9
- data/app/models/decidim/action_delegator/participant.rb +15 -9
- data/app/models/decidim/action_delegator/ponderation.rb +0 -2
- data/app/models/decidim/action_delegator/setting.rb +14 -32
- data/app/overrides/decidim/elections/admin/dashboard/_results/_add_results_contents.html.erb.deface +10 -0
- data/app/overrides/decidim/elections/admin/dashboard/_results/_add_results_tabs.html.erb.deface +3 -0
- data/app/overrides/decidim/elections/elections/_election_aside/add_delegation_buttons.html.erb.deface +3 -0
- data/app/overrides/decidim/elections/elections/_vote_results/replace_results_div.html.erb.deface +8 -0
- data/app/overrides/decidim/elections/per_question_votes/show/add_delegation_hidden_input.html.erb.deface +3 -0
- data/app/overrides/decidim/elections/per_question_votes/show/add_delegation_id_to_links.html.erb.deface +3 -0
- data/app/overrides/decidim/elections/per_question_votes/waiting/add_delegation_buttons.html.erb.deface +3 -0
- data/app/overrides/decidim/elections/votes/receipt/add_delegation_buttons.html.erb.deface +3 -0
- data/app/packs/entrypoints/decidim_action_delegator_elections.js +1 -0
- data/app/packs/src/decidim/action_delegator/elections_live_results.js +160 -0
- data/app/permissions/decidim/action_delegator/admin/permissions.rb +29 -0
- data/app/permissions/decidim/action_delegator/permissions.rb +6 -30
- data/app/presenters/decidim/action_delegator/setting_presenter.rb +33 -0
- data/app/queries/decidim/action_delegator/action_delegator_census_users.rb +51 -0
- data/app/queries/decidim/action_delegator/authorized_resources.rb +28 -0
- data/app/queries/decidim/action_delegator/election_settings.rb +23 -0
- data/app/queries/decidim/action_delegator/{delegated_votes_versions.rb → elections_delegated_votes_versions.rb} +8 -8
- data/app/queries/decidim/action_delegator/elections_question_responses_by_type.rb +33 -0
- data/app/queries/decidim/action_delegator/elections_question_weighted_responses.rb +28 -0
- data/app/queries/decidim/action_delegator/elections_votes_with_ponderations.rb +62 -0
- data/app/services/decidim/action_delegator/delegations_csv_importer.rb +3 -3
- data/app/services/decidim/action_delegator/participants_csv_importer.rb +1 -1
- data/app/services/decidim/action_delegator/sms_gateway.rb +2 -2
- data/app/views/decidim/action_delegator/admin/censuses/_action_delegator_census_form.html.erb +44 -0
- data/app/views/decidim/action_delegator/admin/censuses/_action_delegator_census_options_form.html.erb +25 -0
- data/app/views/decidim/action_delegator/admin/delegations/index.html.erb +12 -13
- data/app/views/decidim/action_delegator/admin/delegations/new.html.erb +29 -27
- data/app/views/decidim/action_delegator/admin/manage_delegations/new.html.erb +36 -24
- data/app/views/decidim/action_delegator/admin/manage_participants/new.html.erb +47 -33
- data/app/views/decidim/action_delegator/admin/participants/_form.html.erb +14 -8
- data/app/views/decidim/action_delegator/admin/participants/edit.html.erb +11 -13
- data/app/views/decidim/action_delegator/admin/participants/index.html.erb +20 -25
- data/app/views/decidim/action_delegator/admin/participants/new.html.erb +11 -13
- data/app/views/decidim/action_delegator/admin/ponderations/_form.html.erb +13 -7
- data/app/views/decidim/action_delegator/admin/ponderations/edit.html.erb +11 -13
- data/app/views/decidim/action_delegator/admin/ponderations/index.html.erb +8 -11
- data/app/views/decidim/action_delegator/admin/ponderations/new.html.erb +11 -13
- data/app/views/decidim/action_delegator/admin/settings/_form.html.erb +26 -12
- data/app/views/decidim/action_delegator/admin/settings/_participants_sync_check.html.erb +1 -1
- data/app/views/decidim/action_delegator/admin/settings/_setting_checks.html.erb +11 -16
- data/app/views/decidim/action_delegator/admin/settings/edit.html.erb +11 -12
- data/app/views/decidim/action_delegator/admin/settings/index.html.erb +22 -19
- data/app/views/decidim/action_delegator/admin/settings/new.html.erb +11 -12
- data/app/views/decidim/action_delegator/admin/shared/_tabs_menu.html.erb +15 -0
- data/app/views/decidim/action_delegator/censuses/_internal_users_form.html.erb +61 -0
- data/app/views/decidim/action_delegator/elections/_delegation_buttons.html.erb +10 -0
- data/app/views/decidim/action_delegator/elections/_normal_election_buttons.html.erb +13 -0
- data/app/views/decidim/action_delegator/elections/_per_question_buttons.html.erb +9 -0
- data/app/views/decidim/action_delegator/elections/_per_question_waiting_buttons.html.erb +19 -0
- data/app/views/decidim/action_delegator/elections/_vote_results.html.erb +10 -0
- data/app/views/decidim/action_delegator/elections/_vote_results_question.html.erb +13 -0
- data/app/views/decidim/action_delegator/elections/admin/dashboard/_by_type_and_weight.html.erb +45 -0
- data/app/views/decidim/action_delegator/elections/admin/dashboard/_results_tabs.html.erb +5 -0
- data/app/views/decidim/action_delegator/elections/admin/dashboard/_results_type_info.html.erb +4 -0
- data/app/views/decidim/action_delegator/elections/admin/dashboard/_sum_of_weights.html.erb +43 -0
- data/app/views/decidim/action_delegator/elections/admin/dashboard/_totals.html.erb +27 -0
- data/app/views/decidim/action_delegator/user_delegations/index.html.erb +13 -14
- data/app/views/decidim/action_delegator/verifications/delegations_verifier/authorizations/edit.html.erb +19 -29
- data/app/views/decidim/action_delegator/verifications/delegations_verifier/authorizations/new.html.erb +42 -40
- data/config/assets.rb +3 -35
- data/config/i18n-tasks.yml +27 -5
- data/config/locales/ca.yml +70 -56
- data/config/locales/cs.yml +161 -145
- data/config/locales/en.yml +110 -67
- data/config/locales/es.yml +70 -56
- data/db/migrate/20200824113801_create_settings.rb +1 -1
- data/db/migrate/20250729104037_add_title_to_action_delegator_settings.rb +31 -0
- data/lib/decidim/action_delegator/admin_engine.rb +72 -45
- data/lib/decidim/action_delegator/common_rake.rb +13 -0
- data/lib/decidim/action_delegator/engine.rb +49 -19
- data/lib/decidim/action_delegator/test/delegation_examples.rb +144 -0
- data/lib/decidim/action_delegator/test/factories.rb +11 -6
- data/lib/decidim/action_delegator/verifications/delegations_authorizer.rb +80 -47
- data/lib/decidim/action_delegator/version.rb +3 -3
- data/lib/decidim/action_delegator.rb +8 -26
- data/lib/tasks/migrate_consultations.rake +382 -0
- data/lib/tasks/upgrade_tasks.rake +5 -0
- data/package.json +10 -27
- metadata +72 -112
- data/app/commands/concerns/decidim/action_delegator/consultations/multiple_vote_question_override.rb +0 -31
- data/app/commands/concerns/decidim/action_delegator/consultations/vote_question_override.rb +0 -44
- data/app/commands/decidim/action_delegator/admin/fix_resource_permissions.rb +0 -46
- data/app/commands/decidim/action_delegator/vote_delegation.rb +0 -28
- data/app/controllers/concerns/decidim/action_delegator/consultations/consultations_controller_override.rb +0 -16
- data/app/controllers/concerns/decidim/action_delegator/consultations/question_multiple_votes_controller_override.rb +0 -29
- data/app/controllers/concerns/decidim/action_delegator/consultations/question_votes_controller_override.rb +0 -57
- data/app/controllers/concerns/decidim/action_delegator/consultations/questions_controller_override.rb +0 -16
- data/app/controllers/concerns/decidim/action_delegator/needs_consultation_styles.rb +0 -24
- data/app/controllers/decidim/action_delegator/admin/consultations/exports_controller.rb +0 -27
- data/app/controllers/decidim/action_delegator/admin/consultations_controller.rb +0 -47
- data/app/controllers/decidim/action_delegator/admin/exports/_sum_of_weights_controller.rb +0 -15
- data/app/forms/concerns/decidim/action_delegator/consultations/vote_form_override.rb +0 -15
- data/app/helpers/decidim/action_delegator/delegation_helper.rb +0 -13
- data/app/jobs/decidim/action_delegator/export_consultation_results_job.rb +0 -51
- data/app/models/concerns/decidim/action_delegator/consultations/question_override.rb +0 -18
- data/app/models/concerns/decidim/action_delegator/consultations/vote_override.rb +0 -15
- data/app/models/decidim/action_delegator/unversioned_vote.rb +0 -19
- data/app/models/decidim/action_delegator/whodunnit_vote.rb +0 -28
- data/app/overrides/decidim/consultations/admin/consultations/results/add_ongoing_warning.html.erb.deface +0 -3
- data/app/overrides/decidim/consultations/consultations/_question/add_delegation_link.html.erb.deface +0 -3
- data/app/overrides/decidim/consultations/consultations/_regular_questions/prevent_empty_questions.html.erb.deface +0 -10
- data/app/overrides/decidim/consultations/consultations/_regular_questions/remove_highlighted_scopes.html.erb.deface +0 -5
- data/app/overrides/decidim/consultations/question_multiple_votes/_form/add_delegation_notice.html.erb.deface +0 -8
- data/app/overrides/decidim/consultations/questions/_vote_button/add_delegations_link.html.erb.deface +0 -3
- data/app/overrides/decidim/consultations/questions/_vote_button/add_modal.html.erb.deface +0 -3
- data/app/overrides/decidim/consultations/questions/_vote_button/add_modal_javascript.html.erb.deface +0 -4
- data/app/overrides/decidim/consultations/questions/_vote_button/replace_delegation_to_multivote_link.html.erb.deface +0 -8
- data/app/overrides/decidim/consultations/questions/_vote_modal/add_delegation_callout.html.erb.deface +0 -3
- data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_delegation_callout.html.erb.deface +0 -3
- data/app/overrides/decidim/consultations/questions/_vote_modal_confirm/add_hidden_field.html.erb.deface +0 -3
- data/app/overrides/layouts/decidim/admin/remove_deprecation.rb +0 -10
- data/app/packs/entrypoints/decidim_action_delegator.scss +0 -1
- data/app/packs/entrypoints/decidim_action_delegator_questions.js +0 -5
- data/app/packs/src/decidim/action_delegator/questions.js +0 -33
- data/app/packs/stylesheets/decidim/action_delegator/questions.scss +0 -26
- data/app/permissions/concerns/decidim/action_delegator/consultations/permissions_override.rb +0 -35
- data/app/presenters/decidim/action_delegator/question_with_totals.rb +0 -24
- data/app/queries/decidim/action_delegator/consultation_delegations.rb +0 -25
- data/app/queries/decidim/action_delegator/delegates_votes_by_consultation.rb +0 -24
- data/app/queries/decidim/action_delegator/delegates_votes_by_question.rb +0 -26
- data/app/queries/decidim/action_delegator/delegation_votes.rb +0 -30
- data/app/queries/decidim/action_delegator/grantee_delegations.rb +0 -24
- data/app/queries/decidim/action_delegator/organization_delegations.rb +0 -26
- data/app/queries/decidim/action_delegator/organization_settings.rb +0 -31
- data/app/queries/decidim/action_delegator/responses.rb +0 -24
- data/app/queries/decidim/action_delegator/responses_by_membership.rb +0 -58
- data/app/queries/decidim/action_delegator/scrutiny.rb +0 -87
- data/app/queries/decidim/action_delegator/setting_delegations.rb +0 -19
- data/app/queries/decidim/action_delegator/sum_of_membership_weight.rb +0 -44
- data/app/queries/decidim/action_delegator/sum_of_weights.rb +0 -25
- data/app/queries/decidim/action_delegator/type_and_weight.rb +0 -26
- data/app/queries/decidim/action_delegator/voted_with_ponderations.rb +0 -30
- data/app/queries/decidim/action_delegator/votes_count_aggregation.rb +0 -34
- data/app/serializers/decidim/action_delegator/consultation_results_serializer.rb +0 -19
- data/app/views/decidim/action_delegator/admin/consultations/_ongoing_consultation_warning.html.erb +0 -3
- data/app/views/decidim/action_delegator/admin/consultations/results.html.erb +0 -65
- data/app/views/decidim/action_delegator/admin/consultations/weighted_results.html.erb +0 -66
- data/app/views/decidim/action_delegator/consultations/_link_to_question.html.erb +0 -11
- data/app/views/decidim/action_delegator/consultations/questions/_callout.html.erb +0 -5
- data/app/views/decidim/action_delegator/consultations/questions/_delegations_modal.html.erb +0 -34
- data/app/views/decidim/action_delegator/consultations/questions/_link_to_delegations.html.erb +0 -11
- data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_active.html.erb +0 -32
- data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_finished.html.erb +0 -9
- data/app/views/decidim/action_delegator/consultations/questions/_vote_delegated_upcoming.html.erb +0 -8
- data/app/views/decidim/consultations/question_votes/update_vote_button.js.erb +0 -82
- data/lib/tasks/import_direct_verification.rake +0 -30
@@ -7,7 +7,7 @@ module Decidim
|
|
7
7
|
include NeedsPermission
|
8
8
|
include Decidim::Paginable
|
9
9
|
|
10
|
-
helper ::Decidim::ActionDelegator::Admin::
|
10
|
+
helper ::Decidim::ActionDelegator::Admin::SettingsHelper
|
11
11
|
helper_method :organization_settings, :current_setting
|
12
12
|
|
13
13
|
layout "decidim/admin/users"
|
@@ -15,22 +15,23 @@ module Decidim
|
|
15
15
|
def new
|
16
16
|
enforce_permission_to :create, :participant
|
17
17
|
|
18
|
+
@form = CsvImportForm.from_params(params)
|
18
19
|
@errors = []
|
19
20
|
end
|
20
21
|
|
21
22
|
def create
|
22
23
|
enforce_permission_to :create, :participant
|
23
24
|
|
24
|
-
@
|
25
|
-
redirect_to seting_manage_participants_path && return if @csv_file.blank?
|
25
|
+
@form = CsvImportForm.from_params(params)
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
if @form.valid?
|
28
|
+
csv = @form.csv_file.download.force_encoding("utf-8").encode("utf-8")
|
29
|
+
@import_summary = ImportCsvJob.perform_now("ParticipantsCsvImporter", csv, current_user, current_setting)
|
30
|
+
flash[:notice] = t(".success")
|
31
|
+
redirect_to setting_participants_path(current_setting)
|
32
|
+
else
|
33
|
+
render :new
|
34
|
+
end
|
34
35
|
end
|
35
36
|
|
36
37
|
def destroy_all
|
@@ -43,16 +44,6 @@ module Decidim
|
|
43
44
|
flash[:notice] = I18n.t("participants.remove_census.success", scope: "decidim.action_delegator.admin", participants_count: participants_to_remove.count)
|
44
45
|
redirect_to setting_participants_path(current_setting)
|
45
46
|
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
47
|
end
|
57
48
|
end
|
58
49
|
end
|
@@ -7,7 +7,7 @@ module Decidim
|
|
7
7
|
include NeedsPermission
|
8
8
|
include Decidim::Paginable
|
9
9
|
|
10
|
-
helper ::Decidim::ActionDelegator::Admin::
|
10
|
+
helper ::Decidim::ActionDelegator::Admin::SettingsHelper
|
11
11
|
helper_method :current_setting, :participants
|
12
12
|
|
13
13
|
layout "decidim/admin/users"
|
@@ -88,14 +88,6 @@ module Decidim
|
|
88
88
|
def collection
|
89
89
|
@collection ||= current_setting.participants
|
90
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
91
|
end
|
100
92
|
end
|
101
93
|
end
|
@@ -4,36 +4,13 @@ module Decidim
|
|
4
4
|
module ActionDelegator
|
5
5
|
module Admin
|
6
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
7
|
def sync
|
25
8
|
enforce_permission_to :update, :setting
|
26
9
|
|
27
|
-
SyncParticipantsJob.perform_later(
|
10
|
+
SyncParticipantsJob.perform_later(current_setting)
|
28
11
|
notice = I18n.t("permissions.sync.started", scope: "decidim.action_delegator.admin")
|
29
12
|
redirect_to decidim_admin_action_delegator.settings_path, notice: notice
|
30
13
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def setting
|
35
|
-
@setting ||= Decidim::ActionDelegator::Setting.find(params[:setting_id])
|
36
|
-
end
|
37
14
|
end
|
38
15
|
end
|
39
16
|
end
|
@@ -87,14 +87,6 @@ module Decidim
|
|
87
87
|
def collection
|
88
88
|
@collection ||= current_setting.ponderations
|
89
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
90
|
end
|
99
91
|
end
|
100
92
|
end
|
@@ -4,12 +4,12 @@ module Decidim
|
|
4
4
|
module ActionDelegator
|
5
5
|
module Admin
|
6
6
|
class SettingsController < ActionDelegator::Admin::ApplicationController
|
7
|
-
helper ::Decidim::ActionDelegator::Admin::
|
7
|
+
helper ::Decidim::ActionDelegator::Admin::SettingsHelper
|
8
8
|
include Filterable
|
9
9
|
include Paginable
|
10
10
|
|
11
11
|
layout "decidim/admin/users"
|
12
|
-
helper_method :
|
12
|
+
helper_method :settings_select_options, :copy_from_setting, :settings
|
13
13
|
|
14
14
|
def index
|
15
15
|
enforce_permission_to :index, :setting
|
@@ -42,7 +42,7 @@ module Decidim
|
|
42
42
|
def edit
|
43
43
|
enforce_permission_to :update, :setting
|
44
44
|
|
45
|
-
@form = form(SettingForm).from_model(
|
45
|
+
@form = form(SettingForm).from_model(current_setting)
|
46
46
|
end
|
47
47
|
|
48
48
|
def update
|
@@ -50,7 +50,7 @@ module Decidim
|
|
50
50
|
|
51
51
|
@form = form(SettingForm).from_params(params)
|
52
52
|
|
53
|
-
UpdateSetting.call(@form,
|
53
|
+
UpdateSetting.call(@form, current_setting, copy_from_setting) do
|
54
54
|
on(:ok) do
|
55
55
|
notice = I18n.t("settings.update.success", scope: "decidim.action_delegator.admin")
|
56
56
|
redirect_to decidim_admin_action_delegator.settings_path, notice: notice
|
@@ -64,9 +64,9 @@ module Decidim
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def destroy
|
67
|
-
enforce_permission_to :destroy, :setting, resource:
|
67
|
+
enforce_permission_to :destroy, :setting, resource: current_setting
|
68
68
|
|
69
|
-
if
|
69
|
+
if current_setting.destroy
|
70
70
|
flash[:notice] = I18n.t("settings.destroy.success", scope: "decidim.action_delegator.admin")
|
71
71
|
else
|
72
72
|
flash[:error] = I18n.t("settings.destroy.error", scope: "decidim.action_delegator.admin")
|
@@ -78,15 +78,15 @@ module Decidim
|
|
78
78
|
private
|
79
79
|
|
80
80
|
def setting_params
|
81
|
-
params.require(:setting).permit(:max_grants
|
81
|
+
params.require(:setting).permit(:max_grants)
|
82
82
|
end
|
83
83
|
|
84
84
|
def build_setting
|
85
85
|
Setting.new(setting_params)
|
86
86
|
end
|
87
87
|
|
88
|
-
def
|
89
|
-
@
|
88
|
+
def current_setting
|
89
|
+
@current_setting ||= collection.find_by(id: params[:id])
|
90
90
|
end
|
91
91
|
|
92
92
|
def settings
|
@@ -94,15 +94,15 @@ module Decidim
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def collection
|
97
|
-
|
97
|
+
organization_settings
|
98
98
|
end
|
99
99
|
|
100
100
|
def settings_select_options
|
101
|
-
collection.to_h { |setting| [setting.
|
101
|
+
collection.to_h { |setting| [setting.id, translated_attribute(setting.title)] }
|
102
102
|
end
|
103
103
|
|
104
104
|
def copy_from_setting
|
105
|
-
@copy_from_setting ||= Setting.find_by(
|
105
|
+
@copy_from_setting ||= Setting.find_by(id: params[:setting][:copy_from_setting_id])
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -6,9 +6,9 @@ module Decidim
|
|
6
6
|
# this engine inherit.
|
7
7
|
#
|
8
8
|
class ApplicationController < Decidim::ApplicationController
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def permission_class_chain
|
10
|
+
[::Decidim::ActionDelegator::Permissions] + super
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
module Elections
|
6
|
+
module Admin
|
7
|
+
class ResultsController < ActionDelegator::Admin::ApplicationController
|
8
|
+
include ::Decidim::ActionDelegator::SettingsHelper
|
9
|
+
|
10
|
+
# TODO: authentication
|
11
|
+
def by_type_and_weight
|
12
|
+
render json: {
|
13
|
+
id: election.id,
|
14
|
+
ongoing: election.ongoing?,
|
15
|
+
questions: election.questions.map do |question|
|
16
|
+
{
|
17
|
+
id: question.id,
|
18
|
+
response_options: elections_question_responses_by_type(question)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def sum_of_weights
|
25
|
+
render json: {
|
26
|
+
id: election.id,
|
27
|
+
ongoing: election.ongoing?,
|
28
|
+
questions: election.questions.map do |question|
|
29
|
+
{
|
30
|
+
id: question.id,
|
31
|
+
response_options: elections_question_weighted_responses(question)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def totals
|
38
|
+
render json: {
|
39
|
+
id: election.id,
|
40
|
+
ongoing: election.ongoing?,
|
41
|
+
questions: election.questions.map do |question|
|
42
|
+
{ id: question.id }.merge(
|
43
|
+
elections_question_stats(question)
|
44
|
+
)
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def election
|
52
|
+
@election ||= Decidim::Elections::Election.includes(questions: { votes: :versions }).find(params[:id])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
module Elections
|
6
|
+
class ResultsController < ActionDelegator::ApplicationController
|
7
|
+
include ::Decidim::ActionDelegator::SettingsHelper
|
8
|
+
|
9
|
+
# TODO: authentication, ensure published results
|
10
|
+
def sum_of_weights
|
11
|
+
render json: {
|
12
|
+
id: election.id,
|
13
|
+
ongoing: election.ongoing?,
|
14
|
+
questions: election.questions.map do |question|
|
15
|
+
{
|
16
|
+
id: question.id,
|
17
|
+
body: translated_attribute(question.body),
|
18
|
+
published_results: question.published_results?,
|
19
|
+
response_options: elections_question_weighted_responses(question).map do |option|
|
20
|
+
option.slice!(:id, :question_id, :body) unless election.result_published_questions.include?(question)
|
21
|
+
option
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def election
|
31
|
+
@election ||= Decidim::Elections::Election.published.includes(questions: { votes: :versions }).find(params[:id])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -8,27 +8,26 @@ module Decidim
|
|
8
8
|
include Decidim::FormFactory
|
9
9
|
include Decidim::Verifications::Renewable
|
10
10
|
|
11
|
-
helper_method :authorization, :
|
11
|
+
helper_method :authorization, :active_settings
|
12
12
|
|
13
13
|
before_action do
|
14
|
-
unless
|
14
|
+
unless active_settings
|
15
15
|
flash[:alert] = t("verifications.delegations_verifier.not_active", scope: "decidim.action_delegator")
|
16
16
|
redirect
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def new
|
21
|
-
|
20
|
+
def new # rubocop:disable Metrics/CyclomaticComplexity
|
21
|
+
authorization.destroy! if authorization&.persisted? && !authorization&.granted?
|
22
22
|
|
23
23
|
enforce_permission_to :create, :authorization, authorization: authorization
|
24
|
-
@form = form(DelegationsVerifierForm).instance(
|
25
|
-
participant = @form&.participant
|
24
|
+
@form = delegation_form = form(DelegationsVerifierForm).instance(active_settings: active_settings)
|
26
25
|
|
27
|
-
return unless ActionDelegator.authorize_on_login && setting&.verify_with_email?
|
26
|
+
return unless ActionDelegator.authorize_on_login && @form&.setting&.verify_with_email?
|
28
27
|
|
29
28
|
Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do
|
30
29
|
on(:ok) do
|
31
|
-
grant_and_redirect(participant)
|
30
|
+
grant_and_redirect(delegation_form&.participant)
|
32
31
|
end
|
33
32
|
on(:invalid) do
|
34
33
|
render :new
|
@@ -39,17 +38,16 @@ module Decidim
|
|
39
38
|
def create
|
40
39
|
enforce_permission_to :create, :authorization, authorization: authorization
|
41
40
|
|
42
|
-
@form = form(DelegationsVerifierForm).from_params(params,
|
43
|
-
participant = @form&.participant
|
41
|
+
@form = delegation_form = form(DelegationsVerifierForm).from_params(params, active_settings: active_settings)
|
44
42
|
|
45
43
|
Decidim::Verifications::PerformAuthorizationStep.call(authorization, @form) do
|
46
44
|
on(:ok) do
|
47
|
-
if setting
|
45
|
+
if delegation_form&.setting&.phone_required?
|
48
46
|
flash[:notice] = t("authorizations.create.success", scope: "decidim.verifications.sms")
|
49
47
|
authorization_method = Decidim::Verifications::Adapter.from_element(authorization.name)
|
50
48
|
redirect_to authorization_method.resume_authorization_path(redirect_url: redirect_url)
|
51
49
|
else
|
52
|
-
grant_and_redirect(participant)
|
50
|
+
grant_and_redirect(delegation_form&.participant)
|
53
51
|
end
|
54
52
|
end
|
55
53
|
on(:invalid) do
|
@@ -96,6 +94,8 @@ module Decidim
|
|
96
94
|
private
|
97
95
|
|
98
96
|
def grant_and_redirect(participant)
|
97
|
+
return unless participant
|
98
|
+
|
99
99
|
authorization.grant!
|
100
100
|
participant.update!(decidim_user: authorization.user)
|
101
101
|
flash[:notice] = t("authorizations.update.success", scope: "decidim.verifications.sms")
|
@@ -117,12 +117,8 @@ module Decidim
|
|
117
117
|
)
|
118
118
|
end
|
119
119
|
|
120
|
-
def
|
121
|
-
@
|
122
|
-
end
|
123
|
-
|
124
|
-
def all_settings
|
125
|
-
@all_settings ||= OrganizationSettings.new(current_user.organization).active
|
120
|
+
def active_settings
|
121
|
+
@active_settings ||= Setting.where(organization: current_user.organization).active
|
126
122
|
end
|
127
123
|
end
|
128
124
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
module Admin
|
6
|
+
# A form object that extends the internal users census form with setting selection.
|
7
|
+
class ActionDelegatorCensusForm < Decidim::Elections::Admin::Censuses::InternalUsersForm
|
8
|
+
attribute :setting_id, Integer
|
9
|
+
|
10
|
+
validates :setting_id, presence: true
|
11
|
+
validate :setting_exists_and_belongs_to_organization
|
12
|
+
|
13
|
+
# Returns the settings that need to be persisted in the census.
|
14
|
+
def census_settings
|
15
|
+
super.merge("setting_id" => setting_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def available_settings
|
19
|
+
@available_settings ||= Decidim::ActionDelegator::Setting
|
20
|
+
.where(organization: current_organization, active: true)
|
21
|
+
.order(:title)
|
22
|
+
end
|
23
|
+
|
24
|
+
def settings_for_select
|
25
|
+
available_settings.map { |setting| [setting.presenter.translated_title, setting.id] }
|
26
|
+
end
|
27
|
+
|
28
|
+
def setting
|
29
|
+
@setting ||= available_settings.find_by(id: setting_id) if setting_id.present?
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def setting_exists_and_belongs_to_organization
|
35
|
+
return if setting_id.blank?
|
36
|
+
|
37
|
+
return if available_settings.exists?(id: setting_id)
|
38
|
+
|
39
|
+
errors.add(:setting_id, :invalid)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# app/forms/decidim/action_delegator/admin/delegation_import_form.rb
|
4
|
+
module Decidim
|
5
|
+
module ActionDelegator
|
6
|
+
module Admin
|
7
|
+
class CsvImportForm < Decidim::Form
|
8
|
+
include Decidim::HasUploadValidations
|
9
|
+
|
10
|
+
attribute :csv_file, Decidim::Attributes::Blob
|
11
|
+
attribute :setting_id, Integer
|
12
|
+
|
13
|
+
validates :csv_file, presence: true, file_content_type: { allow: ["text/csv"] }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -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
|
|
@@ -9,7 +9,8 @@ module Decidim
|
|
9
9
|
attribute :weight, Decimal, default: 1.0
|
10
10
|
attribute :name, String
|
11
11
|
|
12
|
-
validates :
|
12
|
+
validates :name, presence: true
|
13
|
+
validates :weight, presence: true, numericality: { greater_than: 0 }
|
13
14
|
validate :name_uniqueness
|
14
15
|
|
15
16
|
def name_uniqueness
|
@@ -3,24 +3,30 @@
|
|
3
3
|
module Decidim
|
4
4
|
module ActionDelegator
|
5
5
|
module Admin
|
6
|
-
class SettingForm < Form
|
6
|
+
class SettingForm < Decidim::Form
|
7
|
+
include TranslatableAttributes
|
8
|
+
|
7
9
|
mimic :setting
|
8
10
|
|
11
|
+
translatable_attribute :title, String
|
12
|
+
translatable_attribute :description, String
|
9
13
|
attribute :max_grants, Integer
|
10
|
-
attribute :decidim_consultation_id, Integer
|
11
14
|
attribute :authorization_method, String
|
12
15
|
attribute :copy_from_setting_id, Integer
|
16
|
+
attribute :active, Boolean, default: false
|
13
17
|
|
14
|
-
validates :max_grants,
|
15
|
-
|
18
|
+
validates :max_grants, presence: true
|
19
|
+
validates :max_grants, numericality: { greater_than: 0 }
|
20
|
+
validates :title, translatable_presence: true
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
validate :only_one_active_setting_per_phone_required
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def only_one_active_setting_per_phone_required
|
27
|
+
return unless active && authorization_method.in?(%w(phone both))
|
21
28
|
|
22
|
-
|
23
|
-
Setting.where.not(id: id)
|
29
|
+
errors.add(:base, :only_one_active_setting_per_phone_required) if Setting.active.phone_required.where.not(id: id).any?
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ActionDelegator
|
5
|
+
module Censuses
|
6
|
+
# This class does the same as Decidim::Elections::Censuses::InternalUsersForm
|
7
|
+
# but it provides the extra explanations from the authorizer
|
8
|
+
# hopefully this will be not needed form Decidim v0.32 onwards
|
9
|
+
class InternalUsersForm < Decidim::Elections::Censuses::InternalUsersForm
|
10
|
+
delegate :organization, to: :current_user
|
11
|
+
|
12
|
+
attr_reader :authorization_status
|
13
|
+
|
14
|
+
def authorization_handlers
|
15
|
+
@authorization_handlers ||= election.census_settings&.fetch("authorization_handlers", {})&.slice(*organization.available_authorizations)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def user_authenticated
|
21
|
+
return errors.add(:base, I18n.t("decidim.elections.censuses.internal_users_form.invalid")) unless in_census?
|
22
|
+
|
23
|
+
@authorization_status = Decidim::ActionAuthorizer::AuthorizationStatusCollection.new(authorization_handlers, current_user, election.component, election)
|
24
|
+
|
25
|
+
return if @authorization_status.ok?
|
26
|
+
|
27
|
+
errors.add(:base, I18n.t("decidim.elections.censuses.internal_users_form.invalid"))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|