Sha256: f192a93e020be1484c31bdddc4a7c23ee4413c9a69d9dcc4eaa2038c30ca874f

Contents?: true

Size: 787 Bytes

Versions: 24

Compression:

Stored size: 787 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # A proposal can include a vote per user.
    class ProposalVote < ApplicationRecord
      belongs_to :proposal, foreign_key: "decidim_proposal_id", class_name: "Decidim::Proposals::Proposal", counter_cache: true
      belongs_to :author, foreign_key: "decidim_author_id", class_name: "Decidim::User"

      validates :proposal, uniqueness: { scope: :author }
      validate :author_and_proposal_same_organization

      private

      # Private: check if the proposal and the author have the same organization
      def author_and_proposal_same_organization
        return if !proposal || !author
        errors.add(:proposal, :invalid) unless author.organization == proposal.organization
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
decidim-proposals-0.6.1 app/models/decidim/proposals/proposal_vote.rb
decidim-0.6.1 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.6.0 app/models/decidim/proposals/proposal_vote.rb
decidim-0.6.0 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.5.1 app/models/decidim/proposals/proposal_vote.rb
decidim-0.5.1 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.5.0 app/models/decidim/proposals/proposal_vote.rb
decidim-0.5.0 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.4.4 app/models/decidim/proposals/proposal_vote.rb
decidim-0.4.4 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.4.3 app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.4.2 app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.4.1 app/models/decidim/proposals/proposal_vote.rb
decidim-0.4.3 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-0.4.2 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-0.4.1 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.4.0 app/models/decidim/proposals/proposal_vote.rb
decidim-0.4.0 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb
decidim-proposals-0.3.2 app/models/decidim/proposals/proposal_vote.rb
decidim-0.3.2 decidim-proposals/app/models/decidim/proposals/proposal_vote.rb