Class: Decidim::Assembly
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Decidim::Assembly
- Includes:
- FilterableResource, Followable, HasArea, HasAttachmentCollections, HasAttachments, HasPrivateUsers, HasReference, HasUploadValidations, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, ScopableParticipatorySpace, Searchable, ShareableWithToken, SoftDeletable, Taxonomizable, Traceable, TranslatableResource
- Defined in:
- app/models/decidim/assembly.rb
Overview
Interaction between a user and an organization can be done via an Assembly. It is 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
- 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_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(auth_object = nil) ⇒ Object
- .ransackable_scopes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #ancestors ⇒ Object
- #attachment_context ⇒ Object
- #closed? ⇒ Boolean
- #self_and_ancestors ⇒ Object
- #shareable_url(share_token) ⇒ Object
- #to_param ⇒ Object
- #translated_title ⇒ Object
- #user_roles(role_name = nil) ⇒ Object
-
#visible? ⇒ Boolean
This is a overwrite for Decidim::ParticipatorySpaceResourceable.visible?.
Class Method Details
.child_assemblies ⇒ Object
Return child assemblies.
113 114 115 |
# File 'app/models/decidim/assembly.rb', line 113 def self.child_assemblies where.not(parent_id: nil) end |
.log_presenter_class_for(_log) ⇒ Object
117 118 119 |
# File 'app/models/decidim/assembly.rb', line 117 def self.log_presenter_class_for(_log) Decidim::Assemblies::AdminLog::AssemblyPresenter end |
.parent_assemblies ⇒ Object
Return parent assemblies.
108 109 110 |
# File 'app/models/decidim/assembly.rb', line 108 def self.parent_assemblies where(parent_id: nil) end |
.promoted ⇒ Object
Scope to return only the promoted assemblies.
Returns an ActiveRecord::Relation.
103 104 105 |
# File 'app/models/decidim/assembly.rb', line 103 def self.promoted where(promoted: true) end |
.public_spaces ⇒ Object
Overwriting existing method Decidim::HasPrivateUsers.public_spaces
96 97 98 |
# File 'app/models/decidim/assembly.rb', line 96 def self.public_spaces where(private_space: false).or(where(private_space: true).where(is_transparent: true)).published end |
.ransackable_associations(_auth_object = nil) ⇒ Object
175 176 177 |
# File 'app/models/decidim/assembly.rb', line 175 def self.ransackable_associations(_auth_object = nil) %w(parent children taxonomies) end |
.ransackable_attributes(auth_object = nil) ⇒ Object
167 168 169 170 171 172 173 |
# File 'app/models/decidim/assembly.rb', line 167 def self.ransackable_attributes(auth_object = nil) base = %w(title short_description description id) return base unless auth_object&.admin? base + %w(published_at private_space parent_id) end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
159 160 161 |
# File 'app/models/decidim/assembly.rb', line 159 def self.ransackable_scopes(_auth_object = nil) [:with_any_taxonomies] end |
Instance Method Details
#ancestors ⇒ Object
134 135 136 |
# File 'app/models/decidim/assembly.rb', line 134 def ancestors self_and_ancestors.where.not(id:) end |
#attachment_context ⇒ Object
155 156 157 |
# File 'app/models/decidim/assembly.rb', line 155 def :admin end |
#closed? ⇒ Boolean
142 143 144 145 146 |
# File 'app/models/decidim/assembly.rb', line 142 def closed? return false if closing_date.blank? closing_date < Date.current end |
#self_and_ancestors ⇒ Object
130 131 132 |
# File 'app/models/decidim/assembly.rb', line 130 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 |
#shareable_url(share_token) ⇒ Object
163 164 165 |
# File 'app/models/decidim/assembly.rb', line 163 def shareable_url(share_token) EngineRouter.main_proxy(self).assembly_url(self, share_token: share_token.token) end |
#to_param ⇒ Object
126 127 128 |
# File 'app/models/decidim/assembly.rb', line 126 def to_param slug end |
#translated_title ⇒ Object
138 139 140 |
# File 'app/models/decidim/assembly.rb', line 138 def translated_title Decidim::AssemblyPresenter.new(self).translated_title end |
#user_roles(role_name = nil) ⇒ Object
148 149 150 151 152 153 |
# File 'app/models/decidim/assembly.rb', line 148 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 |
#visible? ⇒ Boolean
This is a overwrite for Decidim::ParticipatorySpaceResourceable.visible?
122 123 124 |
# File 'app/models/decidim/assembly.rb', line 122 def visible? published? && (!private_space? || (private_space? && is_transparent?)) end |