Class: Decidim::Assembly
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Decidim::Assembly
- 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
- .log_presenter_class_for(_log) ⇒ Object
- .private_assemblies ⇒ Object
-
.promoted ⇒ Object
Scope to return only the promoted assemblies.
- .public_spaces ⇒ Object
Instance Method Summary collapse
- #ancestors ⇒ Object
- #can_participate?(user) ⇒ Boolean
- #hashtag ⇒ Object
- #self_and_ancestors ⇒ Object
- #to_param ⇒ Object
- #translated_title ⇒ Object
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
84 85 86 |
# File 'app/models/decidim/assembly.rb', line 84 def self.log_presenter_class_for(_log) Decidim::Assemblies::AdminLog::AssemblyPresenter end |
.private_assemblies ⇒ Object
104 105 106 |
# File 'app/models/decidim/assembly.rb', line 104 def self.private_assemblies where(private_space: true) end |
.promoted ⇒ Object
Scope to return only the promoted assemblies.
Returns an ActiveRecord::Relation.
80 81 82 |
# File 'app/models/decidim/assembly.rb', line 80 def self.promoted where(promoted: true) end |
Instance Method Details
#ancestors ⇒ Object
100 101 102 |
# File 'app/models/decidim/assembly.rb', line 100 def ancestors self_and_ancestors.where.not(id: id) end |
#can_participate?(user) ⇒ Boolean
112 113 114 115 116 |
# File 'app/models/decidim/assembly.rb', line 112 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 |
#hashtag ⇒ Object
88 89 90 |
# File 'app/models/decidim/assembly.rb', line 88 def hashtag attributes["hashtag"].to_s.delete("#") end |
#self_and_ancestors ⇒ Object
96 97 98 |
# File 'app/models/decidim/assembly.rb', line 96 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_param ⇒ Object
92 93 94 |
# File 'app/models/decidim/assembly.rb', line 92 def to_param slug end |
#translated_title ⇒ Object
118 119 120 |
# File 'app/models/decidim/assembly.rb', line 118 def translated_title Decidim::AssemblyPresenter.new(self).translated_title end |