Class: Decidim::Proposals::Admin::ValuationAssignmentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb', line 7

def create
  @form = form(Admin::ValuationAssignmentForm).from_params(params)

  @form.proposals.each do |proposal|
    enforce_permission_to :assign_to_valuator, :proposals, proposal:
  end

  Admin::AssignProposalsToValuator.call(@form) do
    on(:ok) do |_proposal|
      flash[:notice] = I18n.t("valuation_assignments.create.success", scope: "decidim.proposals.admin")
      redirect_to EngineRouter.admin_proxy(current_component).root_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("valuation_assignments.create.invalid", scope: "decidim.proposals.admin")
      redirect_to EngineRouter.admin_proxy(current_component).root_path
    end
  end
end

#destroyObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb', line 27

def destroy
  @form = form(Admin::ValuationAssignmentForm).from_params(params)

  @form.valuator_roles.each do |valuator_role|
    enforce_permission_to :unassign_from_valuator, :proposals, valuator: valuator_role.user
  end

  Admin::UnassignProposalsFromValuator.call(@form) do
    on(:ok) do |_proposal|
      flash.keep[:notice] = I18n.t("valuation_assignments.delete.success", scope: "decidim.proposals.admin")
      redirect_back fallback_location: EngineRouter.admin_proxy(current_component).root_path
    end

    on(:invalid) do
      flash.keep[:alert] = I18n.t("valuation_assignments.delete.invalid", scope: "decidim.proposals.admin")
      redirect_back fallback_location: EngineRouter.admin_proxy(current_component).root_path
    end
  end
end