Class: Decidim::Assembly

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Followable, HasAttachmentCollections, HasAttachments, HasPrivateUsers, HasReference, Loggable, Participable, ParticipatorySpaceResourceable, Publicable, Scopable, Traceable
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
ASSEMBLY_TYPES =
%w(government executive consultative_advisory participatory working_group commission others).freeze
CREATED_BY =
%w(city_council public others).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



84
85
86
# File 'app/models/decidim/assembly.rb', line 84

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

.private_assembliesObject



104
105
106
# File 'app/models/decidim/assembly.rb', line 104

def self.private_assemblies
  where(private_space: true)
end

Scope to return only the promoted assemblies.

Returns an ActiveRecord::Relation.



80
81
82
# File 'app/models/decidim/assembly.rb', line 80

def self.promoted
  where(promoted: true)
end

.public_spacesObject



108
109
110
# File 'app/models/decidim/assembly.rb', line 108

def self.public_spaces
  super.where(private_space: false).or(Decidim::Assembly.where(private_space: true).where(is_transparent: true))
end

Instance Method Details

#ancestorsObject



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

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

#can_participate?(user) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
115
116
# File 'app/models/decidim/assembly.rb', line 112

def can_participate?(user)
  return true unless private_space?
  return true if private_space? && users.include?(user)
  return false if private_space? && is_transparent?
end

#hashtagObject



88
89
90
# File 'app/models/decidim/assembly.rb', line 88

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

#self_and_ancestorsObject



96
97
98
# File 'app/models/decidim/assembly.rb', line 96

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



92
93
94
# File 'app/models/decidim/assembly.rb', line 92

def to_param
  slug
end

#translated_titleObject



118
119
120
# File 'app/models/decidim/assembly.rb', line 118

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