Class: Decidim::Assembly
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Decidim::Assembly
- Includes:
- FilterableResource, Followable, HasArea, HasAttachmentCollections, HasAttachments, HasReference, HasUploadValidations, Loggable, Participable, ParticipatorySpace::HasMembers, 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
- ACCESS_MODES =
Access modes are consistent across participatory spaces (assemblies and processes) open: visible and accessible for all transparent: visible for all but the actions require to be a member of the space restricted: visible and accessible only for members fo the space
{ open: 0, transparent: 1, restricted: 2 }.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.
- .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.
110 111 112 |
# File 'app/models/decidim/assembly.rb', line 110 def self.child_assemblies where.not(parent_id: nil) end |
.log_presenter_class_for(_log) ⇒ Object
114 115 116 |
# File 'app/models/decidim/assembly.rb', line 114 def self.log_presenter_class_for(_log) Decidim::Assemblies::AdminLog::AssemblyPresenter end |
.parent_assemblies ⇒ Object
Return parent assemblies.
105 106 107 |
# File 'app/models/decidim/assembly.rb', line 105 def self.parent_assemblies where(parent_id: nil) end |
.promoted ⇒ Object
Scope to return only the promoted assemblies.
Returns an ActiveRecord::Relation.
100 101 102 |
# File 'app/models/decidim/assembly.rb', line 100 def self.promoted where(promoted: true) end |
.ransackable_associations(_auth_object = nil) ⇒ Object
172 173 174 |
# File 'app/models/decidim/assembly.rb', line 172 def self.ransackable_associations(_auth_object = nil) %w(parent children taxonomies) end |
.ransackable_attributes(auth_object = nil) ⇒ Object
164 165 166 167 168 169 170 |
# File 'app/models/decidim/assembly.rb', line 164 def self.ransackable_attributes(auth_object = nil) base = %w(title short_description description id) return base unless auth_object&.admin? base + %w(published_at created_at parent_id access_mode) end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
156 157 158 |
# File 'app/models/decidim/assembly.rb', line 156 def self.ransackable_scopes(_auth_object = nil) [:with_any_taxonomies, :with_any_access_mode] end |
Instance Method Details
#ancestors ⇒ Object
131 132 133 |
# File 'app/models/decidim/assembly.rb', line 131 def ancestors self_and_ancestors.where.not(id:) end |
#attachment_context ⇒ Object
152 153 154 |
# File 'app/models/decidim/assembly.rb', line 152 def :admin 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 |
#self_and_ancestors ⇒ Object
127 128 129 |
# File 'app/models/decidim/assembly.rb', line 127 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
160 161 162 |
# File 'app/models/decidim/assembly.rb', line 160 def shareable_url(share_token) EngineRouter.main_proxy(self).assembly_url(self, share_token: share_token.token) end |
#to_param ⇒ Object
123 124 125 |
# File 'app/models/decidim/assembly.rb', line 123 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 |
#user_roles(role_name = nil) ⇒ Object
145 146 147 148 149 150 |
# File 'app/models/decidim/assembly.rb', line 145 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?
119 120 121 |
# File 'app/models/decidim/assembly.rb', line 119 def visible? published? && (open? || transparent?) end |