Sha256: 37d906720aae78ce0dc8490236c5f512487890a78f6d1c84f94d0de2670bbbbd
Contents?: true
Size: 1.54 KB
Versions: 35
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module Decidim module Proposals module Admin # A command with all the business logic to unassign proposals from a given # valuator. class UnassignProposalsFromValuator < Rectify::Command # Public: Initializes the command. # # form - A form object with the params. def initialize(form) @form = form end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if the form wasn't valid and we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) unless form.valid? unassign_proposals broadcast(:ok) end private attr_reader :form def unassign_proposals transaction do form.proposals.flat_map do |proposal| assignment = find_assignment(proposal) unassign(assignment) if assignment end end end def find_assignment(proposal) Decidim::Proposals::ValuationAssignment.find_by( proposal: proposal, valuator_role: form.valuator_role ) end def unassign(assignment) Decidim.traceability.perform_action!( :delete, assignment, form.current_user, proposal_title: assignment.proposal.title ) do assignment.destroy! end end end end end end
Version data entries
35 entries across 35 versions & 1 rubygems