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
-
.child_assemblies ⇒ Object
Return child assemblies.
- .log_presenter_class_for(_log) ⇒ Object
-
.parent_assemblies ⇒ Object
Return parent assemblies.
-
.promoted ⇒ Object
Scope to return only the promoted assemblies.
-
.public_spaces ⇒ Object
Overwriting existing method Decidim::HasPrivateUsers.public_spaces.
-
.visible_for(user) ⇒ Object
Overwriting existing method Decidim::HasPrivateUsers.visible_for.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #can_participate?(user) ⇒ Boolean
- #closed? ⇒ Boolean
- #hashtag ⇒ Object
- #self_and_ancestors ⇒ Object
- #to_param ⇒ Object
- #translated_title ⇒ Object
Class Method Details
.child_assemblies ⇒ Object
Return child assemblies.
104 105 106 |
# File 'app/models/decidim/assembly.rb', line 104 def self.child_assemblies where.not(parent_id: nil) end |
.log_presenter_class_for(_log) ⇒ Object
108 109 110 |
# File 'app/models/decidim/assembly.rb', line 108 def self.log_presenter_class_for(_log) Decidim::Assemblies::AdminLog::AssemblyPresenter end |
.parent_assemblies ⇒ Object
Return parent assemblies.
99 100 101 |
# File 'app/models/decidim/assembly.rb', line 99 def self.parent_assemblies where(parent_id: nil) end |
.promoted ⇒ Object
Scope to return only the promoted assemblies.
Returns an ActiveRecord::Relation.
94 95 96 |
# File 'app/models/decidim/assembly.rb', line 94 def self.promoted where(promoted: true) end |
.public_spaces ⇒ Object
Overwriting existing method Decidim::HasPrivateUsers.public_spaces
87 88 89 |
# File 'app/models/decidim/assembly.rb', line 87 def self.public_spaces where(private_space: false).or(where(private_space: true).where(is_transparent: true)) end |
.visible_for(user) ⇒ Object
Overwriting existing method Decidim::HasPrivateUsers.visible_for
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/decidim/assembly.rb', line 72 def self.visible_for(user) if user return all if user.admin? left_outer_joins(:participatory_space_private_users).where( %{private_space = false OR (private_space = true AND is_transparent = true) OR decidim_participatory_space_private_users.decidim_user_id = ?}, user.id ).distinct else public_spaces end end |
Instance Method Details
#ancestors ⇒ Object
124 125 126 |
# File 'app/models/decidim/assembly.rb', line 124 def ancestors self_and_ancestors.where.not(id: id) end |
#can_participate?(user) ⇒ Boolean
128 129 130 131 132 133 |
# File 'app/models/decidim/assembly.rb', line 128 def can_participate?(user) return true unless private_space? return false unless user users.include?(user) end |
#closed? ⇒ Boolean
139 140 141 142 143 |
# File 'app/models/decidim/assembly.rb', line 139 def closed? return false if closing_date.blank? closing_date < Date.current end |
#hashtag ⇒ Object
112 113 114 |
# File 'app/models/decidim/assembly.rb', line 112 def hashtag attributes["hashtag"].to_s.delete("#") end |
#self_and_ancestors ⇒ Object
120 121 122 |
# File 'app/models/decidim/assembly.rb', line 120 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
116 117 118 |
# File 'app/models/decidim/assembly.rb', line 116 def to_param slug end |
#translated_title ⇒ Object
135 136 137 |
# File 'app/models/decidim/assembly.rb', line 135 def translated_title Decidim::AssemblyPresenter.new(self).translated_title end |