Sha256: f5bf5a04f68050cc511b6809ef0ec79df1658bc26d4c97c3ef2ff2e886e4caab

Contents?: true

Size: 1.98 KB

Versions: 54

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      class ValuationAssignmentsController < Admin::ApplicationController
        def create
          enforce_permission_to :assign_to_valuator, :proposals

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

          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

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

          enforce_permission_to :unassign_from_valuator, :proposals, valuator: @form.valuator_user

          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

        private

        def destroy_params
          {
            id: params.dig(:valuator_role, :id) || params[:id],
            proposal_ids: params[:proposal_ids] || [params[:proposal_id]]
          }
        end

        def skip_manage_component_permission
          true
        end
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
decidim-proposals-0.28.4 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.9 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.28.3 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.8 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.28.2 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.7 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.28.1 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.6 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.26.10 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.26.9 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.28.0 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.5 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.28.0.rc5 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.28.0.rc4 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.26.8 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.4 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.3 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.26.7 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.26.5 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb
decidim-proposals-0.27.2 app/controllers/decidim/proposals/admin/valuation_assignments_controller.rb