decidim-proposals 0.20.1 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/decidim/proposals/admin/proposals.es6 +24 -11
- data/app/cells/decidim/proposals/cost_report/show.erb +35 -0
- data/app/cells/decidim/proposals/cost_report_cell.rb +42 -0
- data/app/cells/decidim/proposals/proposal_m_cell.rb +9 -1
- data/app/cells/decidim/proposals/proposal_tags/show.erb +12 -10
- data/app/cells/decidim/proposals/proposal_tags_cell.rb +5 -0
- data/app/commands/decidim/proposals/admin/answer_proposal.rb +24 -46
- data/app/commands/decidim/proposals/admin/assign_proposals_to_valuator.rb +61 -0
- data/app/commands/decidim/proposals/admin/create_proposal.rb +5 -0
- data/app/commands/decidim/proposals/admin/notify_proposal_answer.rb +85 -0
- data/app/commands/decidim/proposals/admin/publish_answers.rb +67 -0
- data/app/commands/decidim/proposals/admin/unassign_proposals_from_valuator.rb +62 -0
- data/app/commands/decidim/proposals/admin/update_proposal_scope.rb +75 -0
- data/app/controllers/concerns/decidim/proposals/admin/filterable.rb +82 -0
- data/app/controllers/decidim/proposals/admin/proposal_answers_controller.rb +16 -6
- data/app/controllers/decidim/proposals/admin/proposal_notes_controller.rb +8 -9
- data/app/controllers/decidim/proposals/admin/proposals_controller.rb +105 -29
- data/app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb +58 -0
- data/app/controllers/decidim/proposals/collaborative_drafts_controller.rb +19 -3
- data/app/controllers/decidim/proposals/proposals_controller.rb +42 -7
- data/app/controllers/decidim/proposals/versions_controller.rb +4 -1
- data/app/events/decidim/proposals/admin/update_proposal_scope_event.rb +11 -0
- data/app/forms/decidim/proposals/admin/proposal_answer_form.rb +27 -2
- data/app/forms/decidim/proposals/admin/valuation_assignment_form.rb +37 -0
- data/app/forms/decidim/proposals/proposal_wizard_create_step_form.rb +8 -0
- data/app/helpers/decidim/proposals/admin/filterable_helper.rb +17 -0
- data/app/helpers/decidim/proposals/admin/proposal_bulk_actions_helper.rb +35 -0
- data/app/helpers/decidim/proposals/admin/proposal_rankings_helper.rb +63 -0
- data/app/helpers/decidim/proposals/admin/proposals_helper.rb +122 -0
- data/app/helpers/decidim/proposals/application_helper.rb +36 -25
- data/app/helpers/decidim/proposals/collaborative_draft_helper.rb +9 -9
- data/app/helpers/decidim/proposals/proposal_cells_helper.rb +1 -1
- data/app/helpers/decidim/proposals/proposals_helper.rb +18 -0
- data/app/models/decidim/proposals/proposal.rb +163 -16
- data/app/models/decidim/proposals/valuation_assignment.rb +24 -0
- data/app/permissions/decidim/proposals/admin/permissions.rb +77 -11
- data/app/presenters/decidim/proposals/admin_log/proposal_presenter.rb +1 -1
- data/app/presenters/decidim/proposals/admin_log/valuation_assignment_presenter.rb +51 -0
- data/app/presenters/decidim/proposals/admin_log/value_types/valuator_role_user_presenter.rb +19 -0
- data/app/presenters/decidim/proposals/collaborative_draft_presenter.rb +2 -28
- data/app/presenters/decidim/proposals/log/valuation_assignment_presenter.rb +22 -0
- data/app/presenters/decidim/proposals/proposal_presenter.rb +26 -1
- data/app/services/decidim/proposals/collaborative_draft_search.rb +18 -10
- data/app/services/decidim/proposals/proposal_search.rb +33 -40
- data/app/types/decidim/proposals/proposal_input_filter.rb +29 -0
- data/app/types/decidim/proposals/proposal_input_sort.rb +28 -0
- data/app/types/decidim/proposals/proposal_type.rb +35 -4
- data/app/types/decidim/proposals/proposals_type.rb +14 -17
- data/app/views/decidim/proposals/admin/proposal_answers/_form.html.erb +35 -0
- data/app/views/decidim/proposals/admin/proposal_notes/_form.html.erb +1 -1
- data/app/views/decidim/proposals/admin/proposal_notes/_proposal_notes.html.erb +1 -1
- data/app/views/decidim/proposals/admin/proposals/_bulk-actions.html.erb +8 -2
- data/app/views/decidim/proposals/admin/proposals/_form.html.erb +1 -1
- data/app/views/decidim/proposals/admin/proposals/_proposal-tr.html.erb +25 -17
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_assign_to_valuator.html.erb +15 -0
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_dropdown.html.erb +21 -1
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_publish_answers.html.erb +14 -0
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_scope-change.html.erb +25 -0
- data/app/views/decidim/proposals/admin/proposals/bulk_actions/_unassign_from_valuator.html.erb +15 -0
- data/app/views/decidim/proposals/admin/proposals/index.html.erb +16 -7
- data/app/views/decidim/proposals/admin/proposals/publish_answers.js.erb +12 -0
- data/app/views/decidim/proposals/admin/proposals/show.html.erb +186 -0
- data/app/views/decidim/proposals/admin/proposals/update_category.js.erb +3 -2
- data/app/views/decidim/proposals/admin/proposals/update_scope.js.erb +27 -0
- data/app/views/decidim/proposals/collaborative_drafts/_filters.html.erb +3 -3
- data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/_filters.html.erb +12 -12
- data/app/views/decidim/proposals/proposals/_proposal_badge.html.erb +1 -4
- data/app/views/decidim/proposals/proposals/_proposal_preview.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/_vote_button.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/index.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/new.html.erb +1 -1
- data/app/views/decidim/proposals/proposals/show.html.erb +17 -23
- data/config/locales/ar.yml +69 -17
- data/config/locales/ca.yml +113 -18
- data/config/locales/cs.yml +123 -31
- data/config/locales/de.yml +38 -18
- data/config/locales/el.yml +1 -0
- data/config/locales/en.yml +112 -17
- data/config/locales/es-MX.yml +112 -17
- data/config/locales/es-PY.yml +112 -17
- data/config/locales/es.yml +113 -18
- data/config/locales/eu.yml +38 -18
- data/config/locales/fi-plain.yml +113 -18
- data/config/locales/fi.yml +113 -18
- data/config/locales/fr.yml +38 -18
- data/config/locales/gl.yml +38 -18
- data/config/locales/hu.yml +112 -17
- data/config/locales/id-ID.yml +38 -18
- data/config/locales/is-IS.yml +25 -15
- data/config/locales/it.yml +38 -18
- data/config/locales/nl.yml +43 -18
- data/config/locales/no.yml +66 -18
- data/config/locales/pl.yml +38 -18
- data/config/locales/pt-BR.yml +39 -19
- data/config/locales/pt.yml +39 -19
- data/config/locales/ru.yml +25 -17
- data/config/locales/sv.yml +39 -18
- data/config/locales/tr-TR.yml +38 -18
- data/config/locales/uk.yml +25 -17
- data/db/migrate/20200203111239_add_proposal_valuation_assignments.rb +12 -0
- data/db/migrate/20200210135152_add_costs_to_proposals.rb +9 -0
- data/db/migrate/20200212120110_sync_proposals_state_with_amendments_state.rb +28 -0
- data/db/migrate/20200227175922_add_state_published_at_to_proposals.rb +7 -0
- data/db/migrate/20200306123652_publish_existing_proposals_state.rb +15 -0
- data/lib/decidim/proposals.rb +1 -0
- data/lib/decidim/proposals/admin_engine.rb +7 -3
- data/lib/decidim/proposals/component.rb +39 -19
- data/lib/decidim/proposals/engine.rb +1 -1
- data/lib/decidim/proposals/test/factories.rb +55 -0
- data/lib/decidim/proposals/valuatable.rb +21 -0
- data/lib/decidim/proposals/version.rb +1 -1
- metadata +53 -36
- data/app/views/decidim/proposals/admin/proposal_answers/edit.html.erb +0 -22
- data/app/views/decidim/proposals/admin/proposal_notes/index.html.erb +0 -3
- data/app/views/decidim/proposals/admin/shared/_info_proposal.html.erb +0 -20
- data/app/views/decidim/proposals/proposal_widgets/show.html.erb +0 -4
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic to publish many answers at once.
|
7
|
+
class PublishAnswers < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# component - The component that contains the answers.
|
11
|
+
# user - the Decidim::User that is publishing the answers.
|
12
|
+
# proposal_ids - the identifiers of the proposals with the answers to be published.
|
13
|
+
def initialize(component, user, proposal_ids)
|
14
|
+
@component = component
|
15
|
+
@user = user
|
16
|
+
@proposal_ids = proposal_ids
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :ok when everything is valid.
|
22
|
+
# - :invalid if there are not proposals to publish.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
def call
|
26
|
+
return broadcast(:invalid) unless proposals.any?
|
27
|
+
|
28
|
+
proposals.each do |proposal|
|
29
|
+
transaction do
|
30
|
+
mark_proposal_as_answered(proposal)
|
31
|
+
notify_proposal_answer(proposal)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
broadcast(:ok)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :component, :user, :proposal_ids
|
41
|
+
|
42
|
+
def proposals
|
43
|
+
@proposals ||= Decidim::Proposals::Proposal
|
44
|
+
.published
|
45
|
+
.answered
|
46
|
+
.state_not_published
|
47
|
+
.where(component: component)
|
48
|
+
.where(id: proposal_ids)
|
49
|
+
end
|
50
|
+
|
51
|
+
def mark_proposal_as_answered(proposal)
|
52
|
+
Decidim.traceability.perform_action!(
|
53
|
+
"publish_answer",
|
54
|
+
proposal,
|
55
|
+
user
|
56
|
+
) do
|
57
|
+
proposal.update!(state_published_at: Time.current)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def notify_proposal_answer(proposal)
|
62
|
+
NotifyProposalAnswer.call(proposal, nil)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic to unassign proposals from a given
|
7
|
+
# valuator.
|
8
|
+
class UnassignProposalsFromValuator < Rectify::Command
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# form - A form object with the params.
|
12
|
+
def initialize(form)
|
13
|
+
@form = form
|
14
|
+
end
|
15
|
+
|
16
|
+
# Executes the command. Broadcasts these events:
|
17
|
+
#
|
18
|
+
# - :ok when everything is valid.
|
19
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def call
|
23
|
+
return broadcast(:invalid) unless form.valid?
|
24
|
+
|
25
|
+
unassign_proposals
|
26
|
+
broadcast(:ok)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :form
|
32
|
+
|
33
|
+
def unassign_proposals
|
34
|
+
transaction do
|
35
|
+
form.proposals.flat_map do |proposal|
|
36
|
+
assignment = find_assignment(proposal)
|
37
|
+
unassign(assignment) if assignment
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_assignment(proposal)
|
43
|
+
Decidim::Proposals::ValuationAssignment.find_by(
|
44
|
+
proposal: proposal,
|
45
|
+
valuator_role: form.valuator_role
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def unassign(assignment)
|
50
|
+
Decidim.traceability.perform_action!(
|
51
|
+
:delete,
|
52
|
+
assignment,
|
53
|
+
form.current_user,
|
54
|
+
proposal_title: assignment.proposal.title
|
55
|
+
) do
|
56
|
+
assignment.destroy!
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when an admin batch updates proposals scope.
|
7
|
+
class UpdateProposalScope < Rectify::Command
|
8
|
+
include TranslatableAttributes
|
9
|
+
# Public: Initializes the command.
|
10
|
+
#
|
11
|
+
# scope_id - the scope id to update
|
12
|
+
# proposal_ids - the proposals ids to update.
|
13
|
+
def initialize(scope_id, proposal_ids)
|
14
|
+
@scope = Decidim::Scope.find_by id: scope_id
|
15
|
+
@proposal_ids = proposal_ids
|
16
|
+
@response = { scope_name: "", successful: [], errored: [] }
|
17
|
+
end
|
18
|
+
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :update_proposals_scope - when everything is ok, returns @response.
|
22
|
+
# - :invalid_scope - if the scope is blank.
|
23
|
+
# - :invalid_proposal_ids - if the proposal_ids is blank.
|
24
|
+
#
|
25
|
+
# Returns @response hash:
|
26
|
+
#
|
27
|
+
# - :scope_name - the translated_name of the scope assigned
|
28
|
+
# - :successful - Array of names of the updated proposals
|
29
|
+
# - :errored - Array of names of the proposals not updated because they already had the scope assigned
|
30
|
+
def call
|
31
|
+
return broadcast(:invalid_scope) if @scope.blank?
|
32
|
+
return broadcast(:invalid_proposal_ids) if @proposal_ids.blank?
|
33
|
+
|
34
|
+
update_proposals_scope
|
35
|
+
|
36
|
+
broadcast(:update_proposals_scope, @response)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :scope, :proposal_ids
|
42
|
+
|
43
|
+
def update_proposals_scope
|
44
|
+
@response[:scope_name] = translated_attribute(scope.name, scope.organization)
|
45
|
+
Proposal.where(id: proposal_ids).find_each do |proposal|
|
46
|
+
if scope == proposal.scope
|
47
|
+
@response[:errored] << proposal.title
|
48
|
+
else
|
49
|
+
transaction do
|
50
|
+
update_proposal_scope proposal
|
51
|
+
notify_author proposal if proposal.coauthorships.any?
|
52
|
+
end
|
53
|
+
@response[:successful] << proposal.title
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def update_proposal_scope(proposal)
|
59
|
+
proposal.update!(
|
60
|
+
scope: scope
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def notify_author(proposal)
|
65
|
+
Decidim::EventsManager.publish(
|
66
|
+
event: "decidim.events.proposals.proposal_update_scope",
|
67
|
+
event_class: Decidim::Proposals::Admin::UpdateProposalScopeEvent,
|
68
|
+
resource: proposal,
|
69
|
+
affected_users: proposal.notifiable_identities
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Proposals
|
7
|
+
module Admin
|
8
|
+
module Filterable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Admin::Filterable
|
13
|
+
|
14
|
+
helper Decidim::Proposals::Admin::FilterableHelper
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
# Comment about participatory_texts_enabled.
|
19
|
+
def base_query
|
20
|
+
return collection.order(:position) if current_component.settings.participatory_texts_enabled?
|
21
|
+
|
22
|
+
accessible_proposals_collection
|
23
|
+
end
|
24
|
+
|
25
|
+
def accessible_proposals_collection
|
26
|
+
return collection if current_participatory_space.user_roles(:valuator).where(user: current_user).empty?
|
27
|
+
|
28
|
+
collection.with_valuation_assigned_to(current_user, current_participatory_space)
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_field_predicate
|
32
|
+
:id_string_or_title_cont
|
33
|
+
end
|
34
|
+
|
35
|
+
def filters
|
36
|
+
[
|
37
|
+
:is_emendation_true,
|
38
|
+
:state_eq,
|
39
|
+
:state_null,
|
40
|
+
:scope_id_eq,
|
41
|
+
:category_id_eq,
|
42
|
+
:valuator_role_ids_has
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
def filters_with_values
|
47
|
+
{
|
48
|
+
is_emendation_true: %w(true false),
|
49
|
+
state_eq: proposal_states,
|
50
|
+
scope_id_eq: scope_ids_hash(scopes.top_level),
|
51
|
+
category_id_eq: category_ids_hash(categories.first_class),
|
52
|
+
valuator_role_ids_has: valuator_role_ids
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
# Can't user `super` here, because it does not belong to a superclass
|
57
|
+
# but to a concern.
|
58
|
+
def dynamically_translated_filters
|
59
|
+
[:scope_id_eq, :category_id_eq, :valuator_role_ids_has]
|
60
|
+
end
|
61
|
+
|
62
|
+
def valuator_role_ids
|
63
|
+
current_participatory_space.user_roles(:valuator).pluck(:id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def translated_valuator_role_ids_has(valuator_role_id)
|
67
|
+
user_role = current_participatory_space.user_roles(:valuator).find_by(id: valuator_role_id)
|
68
|
+
user_role&.user&.name
|
69
|
+
end
|
70
|
+
|
71
|
+
# An Array<Symbol> of possible values for `state_eq` filter.
|
72
|
+
# Excludes the states that cannot be filtered with the ransack predicate.
|
73
|
+
# A link to filter by "Not answered" will be added in:
|
74
|
+
# Decidim::Proposals::Admin::FilterableHelper#extra_dropdown_submenu_options_items
|
75
|
+
def proposal_states
|
76
|
+
Proposal::POSSIBLE_STATES.without("not_answered")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -7,30 +7,40 @@ module Decidim
|
|
7
7
|
class ProposalAnswersController < Admin::ApplicationController
|
8
8
|
helper_method :proposal
|
9
9
|
|
10
|
+
helper Proposals::ApplicationHelper
|
11
|
+
helper Decidim::Proposals::Admin::ProposalsHelper
|
12
|
+
helper Decidim::Proposals::Admin::ProposalRankingsHelper
|
13
|
+
helper Decidim::Messaging::ConversationHelper
|
14
|
+
|
10
15
|
def edit
|
11
|
-
enforce_permission_to :create, :proposal_answer
|
16
|
+
enforce_permission_to :create, :proposal_answer, proposal: proposal
|
12
17
|
@form = form(Admin::ProposalAnswerForm).from_model(proposal)
|
13
18
|
end
|
14
19
|
|
15
20
|
def update
|
16
|
-
enforce_permission_to :create, :proposal_answer
|
17
|
-
@
|
21
|
+
enforce_permission_to :create, :proposal_answer, proposal: proposal
|
22
|
+
@notes_form = form(ProposalNoteForm).instance
|
23
|
+
@answer_form = form(Admin::ProposalAnswerForm).from_params(params)
|
18
24
|
|
19
|
-
Admin::AnswerProposal.call(@
|
25
|
+
Admin::AnswerProposal.call(@answer_form, proposal) do
|
20
26
|
on(:ok) do
|
21
27
|
flash[:notice] = I18n.t("proposals.answer.success", scope: "decidim.proposals.admin")
|
22
28
|
redirect_to proposals_path
|
23
29
|
end
|
24
30
|
|
25
31
|
on(:invalid) do
|
26
|
-
flash.
|
27
|
-
render
|
32
|
+
flash.keep[:alert] = I18n.t("proposals.answer.invalid", scope: "decidim.proposals.admin")
|
33
|
+
render template: "decidim/proposals/admin/proposals/show"
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
38
|
private
|
33
39
|
|
40
|
+
def skip_manage_component_permission
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
34
44
|
def proposal
|
35
45
|
@proposal ||= Proposal.where(component: current_component).find(params[:id])
|
36
46
|
end
|
@@ -7,30 +7,29 @@ module Decidim
|
|
7
7
|
class ProposalNotesController < Admin::ApplicationController
|
8
8
|
helper_method :proposal
|
9
9
|
|
10
|
-
def index
|
11
|
-
enforce_permission_to :create, :proposal_note
|
12
|
-
@form = form(ProposalNoteForm).instance
|
13
|
-
end
|
14
|
-
|
15
10
|
def create
|
16
|
-
enforce_permission_to :create, :proposal_note
|
11
|
+
enforce_permission_to :create, :proposal_note, proposal: proposal
|
17
12
|
@form = form(ProposalNoteForm).from_params(params)
|
18
13
|
|
19
14
|
CreateProposalNote.call(@form, proposal) do
|
20
15
|
on(:ok) do
|
21
16
|
flash[:notice] = I18n.t("proposal_notes.create.success", scope: "decidim.proposals.admin")
|
22
|
-
redirect_to
|
17
|
+
redirect_to proposal_path(id: proposal.id)
|
23
18
|
end
|
24
19
|
|
25
20
|
on(:invalid) do
|
26
|
-
flash.
|
27
|
-
|
21
|
+
flash.keep[:alert] = I18n.t("proposal_notes.create.error", scope: "decidim.proposals.admin")
|
22
|
+
redirect_to proposal_path(id: proposal.id)
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
32
27
|
private
|
33
28
|
|
29
|
+
def skip_manage_component_permission
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
34
33
|
def proposal
|
35
34
|
@proposal ||= Proposal.where(component: current_component).find(params[:proposal_id])
|
36
35
|
end
|
@@ -6,9 +6,18 @@ module Decidim
|
|
6
6
|
# This controller allows admins to manage proposals in a participatory process.
|
7
7
|
class ProposalsController < Admin::ApplicationController
|
8
8
|
include Decidim::ApplicationHelper
|
9
|
+
include Decidim::Proposals::Admin::Filterable
|
9
10
|
|
10
11
|
helper Proposals::ApplicationHelper
|
11
|
-
|
12
|
+
helper Decidim::Proposals::Admin::ProposalRankingsHelper
|
13
|
+
helper Decidim::Messaging::ConversationHelper
|
14
|
+
helper_method :proposals, :query, :form_presenter, :proposal, :proposal_ids
|
15
|
+
helper Proposals::Admin::ProposalBulkActionsHelper
|
16
|
+
|
17
|
+
def show
|
18
|
+
@notes_form = form(ProposalNoteForm).instance
|
19
|
+
@answer_form = form(Admin::ProposalAnswerForm).from_model(proposal)
|
20
|
+
end
|
12
21
|
|
13
22
|
def new
|
14
23
|
enforce_permission_to :create, :proposal
|
@@ -36,9 +45,8 @@ module Decidim
|
|
36
45
|
|
37
46
|
def update_category
|
38
47
|
enforce_permission_to :update, :proposal_category
|
39
|
-
@proposal_ids = params[:proposal_ids]
|
40
48
|
|
41
|
-
Admin::UpdateProposalCategory.call(params[:category][:id],
|
49
|
+
Admin::UpdateProposalCategory.call(params[:category][:id], proposal_ids) do
|
42
50
|
on(:invalid_category) do
|
43
51
|
flash.now[:error] = I18n.t(
|
44
52
|
"proposals.update_category.select_a_category",
|
@@ -54,9 +62,59 @@ module Decidim
|
|
54
62
|
end
|
55
63
|
|
56
64
|
on(:update_proposals_category) do
|
57
|
-
flash.now[:notice] =
|
58
|
-
flash.now[:alert] =
|
65
|
+
flash.now[:notice] = update_proposals_bulk_response_successful(@response, :category)
|
66
|
+
flash.now[:alert] = update_proposals_bulk_response_errored(@response, :category)
|
67
|
+
end
|
68
|
+
respond_to do |format|
|
69
|
+
format.js
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def publish_answers
|
75
|
+
enforce_permission_to :publish_answers, :proposals
|
76
|
+
|
77
|
+
Decidim::Proposals::Admin::PublishAnswers.call(current_component, current_user, proposal_ids) do
|
78
|
+
on(:invalid) do
|
79
|
+
flash.now[:alert] = t(
|
80
|
+
"proposals.publish_answers.select_a_proposal",
|
81
|
+
scope: "decidim.proposals.admin"
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
on(:ok) do
|
86
|
+
flash.now[:notice] = I18n.t("proposals.publish_answers.success", scope: "decidim")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
respond_to do |format|
|
91
|
+
format.js
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def update_scope
|
96
|
+
enforce_permission_to :update, :proposal_scope
|
97
|
+
|
98
|
+
Admin::UpdateProposalScope.call(params[:scope_id], proposal_ids) do
|
99
|
+
on(:invalid_scope) do
|
100
|
+
flash.now[:error] = t(
|
101
|
+
"proposals.update_scope.select_a_scope",
|
102
|
+
scope: "decidim.proposals.admin"
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
on(:invalid_proposal_ids) do
|
107
|
+
flash.now[:alert] = t(
|
108
|
+
"proposals.update_scope.select_a_proposal",
|
109
|
+
scope: "decidim.proposals.admin"
|
110
|
+
)
|
59
111
|
end
|
112
|
+
|
113
|
+
on(:update_proposals_scope) do
|
114
|
+
flash.now[:notice] = update_proposals_bulk_response_successful(@response, :scope)
|
115
|
+
flash.now[:alert] = update_proposals_bulk_response_errored(@response, :scope)
|
116
|
+
end
|
117
|
+
|
60
118
|
respond_to do |format|
|
61
119
|
format.js
|
62
120
|
end
|
@@ -75,12 +133,12 @@ module Decidim
|
|
75
133
|
@form = form(Admin::ProposalForm).from_params(params)
|
76
134
|
Admin::UpdateProposal.call(@form, @proposal) do
|
77
135
|
on(:ok) do |_proposal|
|
78
|
-
flash[:notice] =
|
136
|
+
flash[:notice] = t("proposals.update.success", scope: "decidim")
|
79
137
|
redirect_to proposals_path
|
80
138
|
end
|
81
139
|
|
82
140
|
on(:invalid) do
|
83
|
-
flash.now[:alert] =
|
141
|
+
flash.now[:alert] = t("proposals.update.error", scope: "decidim")
|
84
142
|
render :edit
|
85
143
|
end
|
86
144
|
end
|
@@ -88,42 +146,60 @@ module Decidim
|
|
88
146
|
|
89
147
|
private
|
90
148
|
|
91
|
-
def
|
92
|
-
@
|
93
|
-
Proposal.where(component: current_component).published.order(:position).ransack(params[:q])
|
94
|
-
else
|
95
|
-
Proposal.where(component: current_component).published.ransack(params[:q])
|
96
|
-
end
|
149
|
+
def collection
|
150
|
+
@collection ||= Proposal.where(component: current_component).published
|
97
151
|
end
|
98
152
|
|
99
153
|
def proposals
|
100
|
-
@proposals ||=
|
154
|
+
@proposals ||= filtered_collection
|
101
155
|
end
|
102
156
|
|
103
157
|
def proposal
|
104
|
-
@proposal ||=
|
158
|
+
@proposal ||= collection.find(params[:id])
|
159
|
+
end
|
160
|
+
|
161
|
+
def proposal_ids
|
162
|
+
@proposal_ids ||= params[:proposal_ids]
|
105
163
|
end
|
106
164
|
|
107
|
-
def
|
165
|
+
def update_proposals_bulk_response_successful(response, subject)
|
108
166
|
return if response[:successful].blank?
|
109
167
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
168
|
+
if subject == :category
|
169
|
+
t(
|
170
|
+
"proposals.update_category.success",
|
171
|
+
subject_name: response[:subject_name],
|
172
|
+
proposals: response[:successful].to_sentence,
|
173
|
+
scope: "decidim.proposals.admin"
|
174
|
+
)
|
175
|
+
elsif subject == :scope
|
176
|
+
t(
|
177
|
+
"proposals.update_scope.success",
|
178
|
+
subject_name: response[:subject_name],
|
179
|
+
proposals: response[:successful].to_sentence,
|
180
|
+
scope: "decidim.proposals.admin"
|
181
|
+
)
|
182
|
+
end
|
116
183
|
end
|
117
184
|
|
118
|
-
def
|
185
|
+
def update_proposals_bulk_response_errored(response, subject)
|
119
186
|
return if response[:errored].blank?
|
120
187
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
188
|
+
if subject == :category
|
189
|
+
t(
|
190
|
+
"proposals.update_category.invalid",
|
191
|
+
subject_name: response[:subject_name],
|
192
|
+
proposals: response[:errored].to_sentence,
|
193
|
+
scope: "decidim.proposals.admin"
|
194
|
+
)
|
195
|
+
elsif subject == :scope
|
196
|
+
t(
|
197
|
+
"proposals.update_scope.invalid",
|
198
|
+
subject_name: response[:subject_name],
|
199
|
+
proposals: response[:errored].to_sentence,
|
200
|
+
scope: "decidim.proposals.admin"
|
201
|
+
)
|
202
|
+
end
|
127
203
|
end
|
128
204
|
|
129
205
|
def form_presenter
|