Class: Decidim::Assembly

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

Instance Method Summary collapse

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

#followers

Methods included from Publicable

#previously_published?, #publish!, #published?, #unpublish!

Class Method Details

.child_assembliesObject

Return child assemblies.



115
116
117
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 115

def self.child_assemblies
  where.not(parent_id: nil)
end

.log_presenter_class_for(_log) ⇒ Object



119
120
121
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 119

def self.log_presenter_class_for(_log)
  Decidim::Assemblies::AdminLog::AssemblyPresenter
end

.parent_assembliesObject

Return parent assemblies.



110
111
112
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 110

def self.parent_assemblies
  where(parent_id: nil)
end

Scope to return only the promoted assemblies.

Returns an ActiveRecord::Relation.



105
106
107
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 105

def self.promoted
  where(promoted: true)
end

.public_spacesObject

Overwriting existing method Decidim::HasPrivateUsers.public_spaces



98
99
100
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 98

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



181
182
183
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 181

def self.ransackable_associations(_auth_object = nil)
  %w(area assembly_type scope parent children categories)
end

.ransackable_attributes(auth_object = nil) ⇒ Object



173
174
175
176
177
178
179
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 173

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 decidim_assemblies_type_id)
end

.ransackable_scopes(_auth_object = nil) ⇒ Object



165
166
167
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 165

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_taxonomies, :with_any_type]
end

Instance Method Details

#ancestorsObject



140
141
142
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 140

def ancestors
  self_and_ancestors.where.not(id:)
end

#attachment_contextObject



161
162
163
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 161

def attachment_context
  :admin
end

#closed?Boolean

Returns:

  • (Boolean)


148
149
150
151
152
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 148

def closed?
  return false if closing_date.blank?

  closing_date < Date.current
end

#hashtagObject



128
129
130
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 128

def hashtag
  attributes["hashtag"].to_s.delete("#")
end

#self_and_ancestorsObject



136
137
138
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 136

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



169
170
171
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 169

def shareable_url(share_token)
  EngineRouter.main_proxy(self).assembly_url(self, share_token: share_token.token)
end

#to_paramObject



132
133
134
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 132

def to_param
  slug
end

#translated_titleObject



144
145
146
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 144

def translated_title
  Decidim::AssemblyPresenter.new(self).translated_title
end

#user_roles(role_name = nil) ⇒ Object



154
155
156
157
158
159
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 154

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?

Returns:

  • (Boolean)


124
125
126
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 124

def visible?
  published? && (!private_space? || (private_space? && is_transparent?))
end