Sha256: 4fab88a3416ea3a66491a0d660a2f4557c0c813f45ee79ba5fdabfb3b6965452

Contents?: true

Size: 1.34 KB

Versions: 25

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Decidim
  # Areas are used in Assemblies to help users know which is
  # the Area of a participatory space.
  class Area < ApplicationRecord
    include Traceable
    include Loggable
    include Decidim::TranslatableResource

    translatable_fields :name

    belongs_to :organization,
               foreign_key: "decidim_organization_id",
               class_name: "Decidim::Organization",
               inverse_of: :areas

    belongs_to :area_type,
               class_name: "Decidim::AreaType",
               inverse_of: :areas,
               optional: true

    validates :name, :organization, presence: true
    validates :name, uniqueness: { scope: [:organization, :area_type] }

    before_destroy :abort_if_dependencies

    def self.log_presenter_class_for(_log)
      Decidim::AdminLog::AreaPresenter
    end

    def translated_name
      Decidim::AreaPresenter.new(self).translated_name
    end

    def has_dependencies?
      Decidim.participatory_space_registry.manifests.any? do |manifest|
        manifest
          .participatory_spaces
          .call(organization)
          .any? do |space|
          space.respond_to?(:area) && space.decidim_area_id == id
        end
      end
    end

    # used on before_destroy
    def abort_if_dependencies
      throw(:abort) if has_dependencies?
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/models/decidim/area.rb
decidim-core-0.26.9 app/models/decidim/area.rb
decidim-core-0.26.8 app/models/decidim/area.rb
decidim-core-0.26.7 app/models/decidim/area.rb
decidim-core-0.26.5 app/models/decidim/area.rb
decidim-core-0.26.4 app/models/decidim/area.rb
decidim-core-0.26.3 app/models/decidim/area.rb
decidim-core-0.26.2 app/models/decidim/area.rb
decidim-core-0.26.1 app/models/decidim/area.rb
decidim-core-0.26.0 app/models/decidim/area.rb
decidim-core-0.26.0.rc2 app/models/decidim/area.rb
decidim-core-0.26.0.rc1 app/models/decidim/area.rb
decidim-core-0.25.2 app/models/decidim/area.rb
decidim-core-0.25.1 app/models/decidim/area.rb
decidim-core-0.25.0 app/models/decidim/area.rb
decidim-core-0.25.0.rc4 app/models/decidim/area.rb
decidim-core-0.25.0.rc3 app/models/decidim/area.rb
decidim-core-0.25.0.rc2 app/models/decidim/area.rb
decidim-core-0.25.0.rc1 app/models/decidim/area.rb
decidim-core-0.24.3 app/models/decidim/area.rb