Sha256: fec6ea06a86e6053ea1aec328669fb2ee8f7ac15b7a54b0c3db6e44a6d6a5267

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    # The data store for a trustee in the Decidim::Elections component. It stores a
    # public key and has a reference to Decidim::User.
    class Trustee < ApplicationRecord
      belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"
      belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
      has_many :elections_trustees, foreign_key: "decidim_elections_trustee_id", dependent: :destroy
      has_many :elections, through: :elections_trustees
      has_many :trustees_participatory_spaces, inverse_of: :trustee, foreign_key: "decidim_elections_trustee_id", dependent: :destroy

      def self.trustee?(user)
        exists?(user: user)
      end

      def self.for(user)
        find_by(user: user)
      end

      def slug
        name.parameterize
      end

      # The bulletin_board_slug is used as `unique_id` on the Bulletin Board, where
      # the "authority.name" gets added as identification. If the organization
      # name would be missing, it could result in an error, when two organizations
      # inside the same "authority" have a trustee with the same name.
      def bulletin_board_slug
        "#{organization.name.parameterize}-#{slug}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-elections-0.25.2 app/models/decidim/elections/trustee.rb
decidim-elections-0.25.1 app/models/decidim/elections/trustee.rb
decidim-elections-0.25.0 app/models/decidim/elections/trustee.rb
decidim-elections-0.25.0.rc4 app/models/decidim/elections/trustee.rb
decidim-elections-0.25.0.rc3 app/models/decidim/elections/trustee.rb
decidim-elections-0.25.0.rc2 app/models/decidim/elections/trustee.rb
decidim-elections-0.25.0.rc1 app/models/decidim/elections/trustee.rb