Class: Decidim::Assembly

Inherits:
ApplicationRecord
  • Object
show all
Includes:
FilterableResource, Followable, HasArea, HasAttachmentCollections, HasAttachments, HasPrivateUsers, HasReference, HasUploadValidations, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, ScopableParticipatorySpace, Searchable, Traceable, TranslatableResource
Defined in:
app/models/decidim/assembly.rb

Overview

Interaction between a user and an organization can be done via an Assembly. It’s 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

SOCIAL_HANDLERS =
[:twitter, :facebook, :instagram, :youtube, :github].freeze
CREATED_BY =
%w(city_council public others).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.child_assembliesObject

Return child assemblies.



116
117
118
# File 'app/models/decidim/assembly.rb', line 116

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

.log_presenter_class_for(_log) ⇒ Object



120
121
122
# File 'app/models/decidim/assembly.rb', line 120

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

.parent_assembliesObject

Return parent assemblies.



111
112
113
# File 'app/models/decidim/assembly.rb', line 111

def self.parent_assemblies
  where(parent_id: nil)
end

Scope to return only the promoted assemblies.

Returns an ActiveRecord::Relation.



106
107
108
# File 'app/models/decidim/assembly.rb', line 106

def self.promoted
  where(promoted: true)
end

.public_spacesObject

Overwriting existing method Decidim::HasPrivateUsers.public_spaces



99
100
101
# File 'app/models/decidim/assembly.rb', line 99

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



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

def self.ransackable_scopes(_auth_object = nil)
  [:with_area, :with_scope]
end

Instance Method Details

#ancestorsObject



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

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

#attachment_contextObject



157
158
159
# File 'app/models/decidim/assembly.rb', line 157

def attachment_context
  :admin
end

#closed?Boolean

Returns:

  • (Boolean)


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

def closed?
  return false if closing_date.blank?

  closing_date < Date.current
end

#hashtagObject



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

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

#self_and_ancestorsObject



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

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



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

def to_param
  slug
end

#translated_titleObject



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

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

#user_roles(role_name = nil) ⇒ Object



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

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