Class: Decidim::Assembly
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- 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:
- decidim-assemblies/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
- #hashtag ⇒ Object
- #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?.
Methods included from HasUploadValidations
#attached_uploader, #maximum_avatar_size, #maximum_upload_size
Methods included from Searchable
searchable_resources, searchable_resources_by_type, searchable_resources_of_type_comment, searchable_resources_of_type_component, searchable_resources_of_type_participant, searchable_resources_of_type_participatory_space
Methods included from Followable
Methods included from Publicable
#previously_published?, #publish!, #published?, #unpublish!
Class Method Details
.child_assemblies ⇒ Object
Return child assemblies.
113 114 115 |
# File 'decidim-assemblies/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 'decidim-assemblies/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 'decidim-assemblies/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 'decidim-assemblies/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 'decidim-assemblies/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
179 180 181 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 179 def self.ransackable_associations(_auth_object = nil) %w(parent children taxonomies) end |
.ransackable_attributes(auth_object = nil) ⇒ Object
171 172 173 174 175 176 177 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 171 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
163 164 165 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 163 def self.ransackable_scopes(_auth_object = nil) [:with_any_taxonomies] end |
Instance Method Details
#ancestors ⇒ Object
138 139 140 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 138 def ancestors self_and_ancestors.where.not(id:) end |
#attachment_context ⇒ Object
159 160 161 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 159 def :admin end |
#closed? ⇒ Boolean
146 147 148 149 150 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 146 def closed? return false if closing_date.blank? closing_date < Date.current end |
#hashtag ⇒ Object
126 127 128 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 126 def hashtag attributes["hashtag"].to_s.delete("#") end |
#self_and_ancestors ⇒ Object
134 135 136 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 134 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
167 168 169 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 167 def shareable_url(share_token) EngineRouter.main_proxy(self).assembly_url(self, share_token: share_token.token) end |
#to_param ⇒ Object
130 131 132 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 130 def to_param slug end |
#translated_title ⇒ Object
142 143 144 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 142 def translated_title Decidim::AssemblyPresenter.new(self).translated_title end |
#user_roles(role_name = nil) ⇒ Object
152 153 154 155 156 157 |
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 152 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 'decidim-assemblies/app/models/decidim/assembly.rb', line 122 def visible? published? && (!private_space? || (private_space? && is_transparent?)) end |