Sha256: f6424692fef59dcd6a623acb0ff6877ef8179c286a05443100e1f3128efdb884

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Decidim
  # Interaction between a user and an organization can be done via an Assembly.
  # It's a unit of action from the Organization point of view that groups
  # several features (proposals, debates...) that can be enabled or disabled.
  class Assembly < ApplicationRecord
    include Decidim::HasAttachments
    include Decidim::Participable
    include Decidim::Publicable
    include Decidim::Scopable

    belongs_to :organization,
               foreign_key: "decidim_organization_id",
               class_name: "Decidim::Organization"
    belongs_to :scope,
               foreign_key: "decidim_scope_id",
               class_name: "Decidim::Scope",
               optional: true
    has_many :categories,
             foreign_key: "decidim_participatory_space_id",
             foreign_type: "decidim_participatory_space_type",
             dependent: :destroy,
             as: :participatory_space

    has_many :features, as: :participatory_space, dependent: :destroy

    validates :slug, uniqueness: { scope: :organization }
    validates :slug, presence: true, format: { with: Decidim::Assembly.slug_format }

    mount_uploader :hero_image, Decidim::HeroImageUploader
    mount_uploader :banner_image, Decidim::BannerImageUploader

    # Scope to return only the promoted assemblies.
    #
    # Returns an ActiveRecord::Relation.
    def self.promoted
      where(promoted: true)
    end

    def hashtag
      attributes["hashtag"].to_s.delete("#")
    end

    def to_param
      slug
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-assemblies-0.8.4 app/models/decidim/assembly.rb
decidim-assemblies-0.8.3 app/models/decidim/assembly.rb
decidim-assemblies-0.8.2 app/models/decidim/assembly.rb
decidim-assemblies-0.8.1 app/models/decidim/assembly.rb
decidim-assemblies-0.8.0 app/models/decidim/assembly.rb