Class: Decidim::Assembly

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Followable, HasAttachmentCollections, HasAttachments, HasPrivateUsers, HasReference, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, Scopable, Traceable
Defined in:
app/models/decidim/assembly.rb

Overview

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 components (proposals, debates…) that can be enabled or disabled.

An assembly can have children. This is implemented using a PostgreSQL extension: LTREE The LTREE extension allows us to save, query on and manipulate trees (hierarchical data structures). It uses the path enumeration algorithm, which calls for each node in the tree to record the path from the root you would have to follow to reach that node.

We use the ‘parents_path` column to save the path and query the tree. Example:

A (root assembly) parent = null, parents_path = A B (root assembly) parent = null, parents_path = B |- C (child assembly of B, descendant of B) parent = B, parents_path = B.C

|- D (child assembly of C, descendant of B,C) parent = C, parents_path = B.C.D
|- E (child assembly of C, descendant of B,C) parent = C, parents_path = B.C.E
   |- F (child assembly of E, descendant of B,C,E) parent = E, parents_path = B.C.E.F

Constant Summary collapse

SOCIAL_HANDLERS =
[:twitter, :facebook, :instagram, :youtube, :github].freeze
ASSEMBLY_TYPES =
%w(government executive consultative_advisory participatory working_group commission others).freeze
CREATED_BY =
%w(city_council public others).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



93
94
95
# File 'app/models/decidim/assembly.rb', line 93

def self.log_presenter_class_for(_log)
  Decidim::Assemblies::AdminLog::AssemblyPresenter
end

.private_assembliesObject



85
86
87
# File 'app/models/decidim/assembly.rb', line 85

def self.private_assemblies
  where(private_space: true)
end

Scope to return only the promoted assemblies.

Returns an ActiveRecord::Relation.



81
82
83
# File 'app/models/decidim/assembly.rb', line 81

def self.promoted
  where(promoted: true)
end

.public_spacesObject



89
90
91
# File 'app/models/decidim/assembly.rb', line 89

def self.public_spaces
  super.where(private_space: false).or(Decidim::Assembly.where(private_space: true).where(is_transparent: true))
end

Instance Method Details

#ancestorsObject



109
110
111
# File 'app/models/decidim/assembly.rb', line 109

def ancestors
  self_and_ancestors.where.not(id: id)
end

#can_participate?(user) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
117
# File 'app/models/decidim/assembly.rb', line 113

def can_participate?(user)
  return true unless private_space?
  return true if private_space? && users.include?(user)
  return false if private_space? && is_transparent?
end

#hashtagObject



97
98
99
# File 'app/models/decidim/assembly.rb', line 97

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

#self_and_ancestorsObject



105
106
107
# File 'app/models/decidim/assembly.rb', line 105

def self_and_ancestors
  self.class.where("#{self.class.table_name}.parents_path @> ?", parents_path).order(Arel.sql("string_to_array(#{self.class.table_name}.parents_path::text, '.')"))
end

#to_paramObject



101
102
103
# File 'app/models/decidim/assembly.rb', line 101

def to_param
  slug
end

#translated_titleObject



119
120
121
# File 'app/models/decidim/assembly.rb', line 119

def translated_title
  Decidim::AssemblyPresenter.new(self).translated_title
end