Sha256: 5737d84683095a868db5d89dc02a93aa6e0c2e5036a90685b4ac3363516b1904

Contents?: true

Size: 1 KB

Versions: 7

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:)
        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

7 entries across 7 versions & 1 rubygems

Version Path
decidim-proposals-0.28.4 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.28.3 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.28.2 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.28.1 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.28.0 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.28.0.rc5 app/forms/decidim/proposals/admin/valuation_assignment_form.rb
decidim-proposals-0.28.0.rc4 app/forms/decidim/proposals/admin/valuation_assignment_form.rb