Class: Decidim::Assembly
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Decidim::Assembly
- Includes:
- FilterableResource, Followable, HasArea, HasAttachmentCollections, HasAttachments, HasPrivateUsers, HasReference, HasUploadValidations, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, ScopableParticipatorySpace, Searchable, Traceable, TranslatableResource
- 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
- 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.
- .ransackable_scopes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #ancestors ⇒ Object
- #attachment_context ⇒ Object
- #closed? ⇒ Boolean
- #hashtag ⇒ Object
- #self_and_ancestors ⇒ Object
- #to_param ⇒ Object
- #translated_title ⇒ Object
- #user_roles(role_name = nil) ⇒ Object
Class Method Details
.child_assemblies ⇒ Object
Return child assemblies.
116 117 118 |
# File 'app/models/decidim/assembly.rb', line 116 def self.child_assemblies where.not(parent_id: nil) end |
.log_presenter_class_for(_log) ⇒ Object
120 121 122 |
# File 'app/models/decidim/assembly.rb', line 120 def self.log_presenter_class_for(_log) Decidim::Assemblies::AdminLog::AssemblyPresenter end |
.parent_assemblies ⇒ Object
Return parent assemblies.
111 112 113 |
# File 'app/models/decidim/assembly.rb', line 111 def self.parent_assemblies where(parent_id: nil) end |
.promoted ⇒ Object
Scope to return only the promoted assemblies.
Returns an ActiveRecord::Relation.
106 107 108 |
# File 'app/models/decidim/assembly.rb', line 106 def self.promoted where(promoted: true) end |
.public_spaces ⇒ Object
Overwriting existing method Decidim::HasPrivateUsers.public_spaces
99 100 101 |
# File 'app/models/decidim/assembly.rb', line 99 def self.public_spaces where(private_space: false).or(where(private_space: true).where(is_transparent: true)).published end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
161 162 163 |
# File 'app/models/decidim/assembly.rb', line 161 def self.ransackable_scopes(_auth_object = nil) [:with_area, :with_scope] end |
Instance Method Details
#ancestors ⇒ Object
136 137 138 |
# File 'app/models/decidim/assembly.rb', line 136 def ancestors self_and_ancestors.where.not(id: id) end |
#attachment_context ⇒ Object
157 158 159 |
# File 'app/models/decidim/assembly.rb', line 157 def :admin end |
#closed? ⇒ Boolean
144 145 146 147 148 |
# File 'app/models/decidim/assembly.rb', line 144 def closed? return false if closing_date.blank? closing_date < Date.current end |
#hashtag ⇒ Object
124 125 126 |
# File 'app/models/decidim/assembly.rb', line 124 def hashtag attributes["hashtag"].to_s.delete("#") end |
#self_and_ancestors ⇒ Object
132 133 134 |
# File 'app/models/decidim/assembly.rb', line 132 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
128 129 130 |
# File 'app/models/decidim/assembly.rb', line 128 def to_param slug end |
#translated_title ⇒ Object
140 141 142 |
# File 'app/models/decidim/assembly.rb', line 140 def translated_title Decidim::AssemblyPresenter.new(self).translated_title end |
#user_roles(role_name = nil) ⇒ Object
150 151 152 153 154 155 |
# File 'app/models/decidim/assembly.rb', line 150 def user_roles(role_name = nil) roles = Decidim::AssemblyUserRole.where(assembly: self_and_ancestors) return roles if role_name.blank? roles.where(role: role_name) end |