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.



117
118
119
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 117

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

.log_presenter_class_for(_log) ⇒ Object



121
122
123
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 121

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

.parent_assembliesObject

Return parent assemblies.



112
113
114
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 112

def self.parent_assemblies
  where(parent_id: nil)
end

Scope to return only the promoted assemblies.

Returns an ActiveRecord::Relation.



107
108
109
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 107

def self.promoted
  where(promoted: true)
end

.public_spacesObject

Overwriting existing method Decidim::HasPrivateUsers.public_spaces



100
101
102
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 100

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



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

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

Instance Method Details

#ancestorsObject



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

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

#attachment_contextObject



158
159
160
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 158

def attachment_context
  :admin
end

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  return false if closing_date.blank?

  closing_date < Date.current
end

#hashtagObject



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

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

#self_and_ancestorsObject



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

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_paramObject



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

def to_param
  slug
end

#translated_titleObject



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

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

#user_roles(role_name = nil) ⇒ Object



151
152
153
154
155
156
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 151

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