Class: Decidim::Assembly

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

Methods included from HasUploadValidations

#maximum_avatar_size, #maximum_upload_size

Methods included from Searchable

searchable_resources, 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

#publish!, #published?, #unpublish!

Class Method Details

.child_assembliesObject

Return child assemblies.


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

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

.log_presenter_class_for(_log) ⇒ Object


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

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

.parent_assembliesObject

Return parent assemblies.


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

def self.parent_assemblies
  where(parent_id: nil)
end

Scope to return only the promoted assemblies.

Returns an ActiveRecord::Relation.


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

def self.promoted
  where(promoted: true)
end

.public_spacesObject

Overwriting existing method Decidim::HasPrivateUsers.public_spaces


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

def self.public_spaces
  where(private_space: false).or(where(private_space: true).where(is_transparent: true)).published
end

.visible_for(user) ⇒ Object

Overwriting existing method Decidim::HasPrivateUsers.visible_for


97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'decidim-assemblies/app/models/decidim/assembly.rb', line 97

def self.visible_for(user)
  if user
    return all if user.admin?

    left_outer_joins(:participatory_space_private_users).where(
      %{private_space = false OR
      (private_space = true AND is_transparent = true) OR
      decidim_participatory_space_private_users.decidim_user_id = ?}, user.id
    ).distinct
  else
    public_spaces
  end
end

Instance Method Details

#ancestorsObject


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

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

#attachment_contextObject


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

def attachment_context
  :admin
end

#closed?Boolean

Returns:

  • (Boolean)

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

def closed?
  return false if closing_date.blank?

  closing_date < Date.current
end

#hashtagObject


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

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

#self_and_ancestorsObject


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

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


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

def to_param
  slug
end

#translated_titleObject


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

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

#user_roles(role_name = nil) ⇒ Object


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

def user_roles(role_name = nil)
  roles = Decidim::AssemblyUserRole.where(assembly: self)
  return roles if role_name.blank?

  roles.where(role: role_name)
end