module Decidim::ParticipatorySpaceResourceable

Participatory Space Resourceable is a concern with the features needed when you want to link a space (for example `Participatory Process`) to another space (`Assembly`).

The main difference between the two concerns `Resourceable` and `ParticipatorySpaceResourceable` is that the first one is linking component types between them, for example `Budgets` with `Proposals` and therefore depend on a `Component`.

The second one, `ParticipatorySpaceResourceable`, it is used for linking `ParticipatorySpaces` to each other, and therefore don't depend on a `Component` but rather that they depend to the `Organization`.

Public Instance Methods

linked_participatory_space_resources(resource_name, link_name) click to toggle source

Finds all the linked resources to or from this model for a given resource name and link name.

resource_name - The String name of the resource manifest exposed by a feature. link_name - The String name of the link between this model and the target resource.

# File lib/decidim/participatory_space_resourceable.rb, line 39
def linked_participatory_space_resources(resource_name, link_name)
  klass = "Decidim::#{resource_name.to_s.classify}"
  klass = klass.constantize
  from = klass
         .joins(:participatory_space_resource_links_from)
         .where(decidim_participatory_space_links: { name: link_name, to_id: id, to_type: self.class.name })

  to = klass
       .joins(:participatory_space_resource_links_to)
       .where(decidim_participatory_space_links: { name: link_name, from_id: id, from_type: self.class.name })

  klass.where(id: from).or(klass.where(id: to))
end
participatory_space_sibling_scope(participatory_space_name) click to toggle source
# File lib/decidim/participatory_space_resourceable.rb, line 53
def participatory_space_sibling_scope(participatory_space_name)
  manifest = Decidim.find_participatory_space_manifest(participatory_space_name)
  return self.class.none unless manifest

  manifest.participatory_spaces.call(organization)
end
resource_description() click to toggle source

Public: This method will be used to represent this participatory space in other contexts, like cards or search results.

# File lib/decidim/participatory_space_resourceable.rb, line 90
def resource_description
  try(:description) || try(:body) || try(:content)
end
resource_manifest() click to toggle source

Finds the resource manifest for the model.

Returns a Decidim::ResourceManifest

# File lib/decidim/participatory_space_resourceable.rb, line 138
def resource_manifest
  Decidim.find_resource_manifest(self)
end
resource_title() click to toggle source

Public: This method will be used to represent this participatory space in other contexts, like cards or search results.

# File lib/decidim/participatory_space_resourceable.rb, line 84
def resource_title
  try(:title) || try(:name)
end
user_role_config_for(user, role_name) click to toggle source
# File lib/decidim/participatory_space_resourceable.rb, line 116
def user_role_config_for(user, role_name)
  case role_name.to_sym
  when :organization_admin
    Decidim::ParticipatorySpaceRoleConfig::Admin.new(user)
  when :admin # ParticipatorySpace admin
    Decidim::ParticipatorySpaceRoleConfig::ParticipatorySpaceAdmin.new(user)
  when :valuator
    Decidim::ParticipatorySpaceRoleConfig::Valuator.new(user)
  when :moderator
    Decidim::ParticipatorySpaceRoleConfig::Moderator.new(user)
  when :collaborator
    Decidim::ParticipatorySpaceRoleConfig::Collaborator.new(user)
  else
    Decidim::ParticipatorySpaceRoleConfig::NullObject.new(user)
  end
end
user_roles(_role_name = nil) click to toggle source

Defines a way to get the user roles for the current participatory space. You should overwrite this method in the implementer class to define how to get the correct values.

role_name - A symbol or string identifying the role name

Returns an ActiveRecord::Relation with one role for each combination of `ParticipatorySpace` and `*UserRole`. `*` meaning that the concrete implementation of the `UserRole` may change depending on the `ParticipatorySpace` where it belongs to.

# File lib/decidim/participatory_space_resourceable.rb, line 112
def user_roles(_role_name = nil)
  self.class.none
end
visible?() click to toggle source

Checks if this ParticipatorySpace should be visible in the public views. i.e. checks

  • is published

  • is not private

# File lib/decidim/participatory_space_resourceable.rb, line 98
def visible?
  published? && !try(:private_space?)
end