Sha256: 6c6e2887186bd589364909f9a4c3f74eed1d130d7275014a0d543d8a038571d8

Contents?: true

Size: 1 KB

Versions: 47

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    module Admin
      class ValuationAssignmentForm < Decidim::Form
        mimic :valuator_role

        attribute :id, Integer
        attribute :proposal_ids, Array

        validates :valuator_role, :proposals, :current_component, presence: true
        validate :same_participatory_space

        def proposals
          @proposals ||= Decidim::Proposals::Proposal.where(component: current_component, id: proposal_ids).uniq
        end

        def valuator_role
          @valuator_role ||= current_component.participatory_space.user_roles(:valuator).find_by(id: id)
        end

        def valuator_user
          return unless valuator_role

          @valuator_user ||= valuator_role.user
        end

        def same_participatory_space
          return if !valuator_role || !current_component

          errors.add(:id, :invalid) if current_component.participatory_space != valuator_role.participatory_space
        end
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
decidim-proposals-0.27.9 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.8 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.7 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.6 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.10 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.9 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.5 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.8 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.4 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.3 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.7 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.5 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.2 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.1 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.4 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.0 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.3 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.0.rc2 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.27.0.rc1 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.26.2 app/forms/decidim/proposals/admin/valuation_assignment_form.rb