Class: Decidim::ParticipatoryProcess

Inherits:
ApplicationRecord
  • Object
show all
Includes:
FilterableResource, Followable, HasArea, HasAttachmentCollections, HasAttachments, HasReference, HasUploadValidations, Loggable, Participable, Decidim::ParticipatorySpace::HasMembers, ParticipatorySpaceResourceable, Publicable, ScopableParticipatorySpace, Searchable, ShareableWithToken, SoftDeletable, Taxonomizable, Traceable, TranslatableResource
Defined in:
app/models/decidim/participatory_process.rb

Overview

Interaction between a user and an organization is done via a ParticipatoryProcess. It is a unit of action from the Organization point of view that groups several components (proposals, debates…) distributed in steps that get enabled or disabled depending on which step is currently active.

Constant Summary collapse

ACCESS_MODES =

Access modes are consistent across participatory spaces (assemblies and processes) open: visible and accessible for all transparent: visible for all but the actions require to be a member of the space restricted: visible and accessible only for members fo the space

{ open: 0, transparent: 1, restricted: 2 }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.active_spacesObject



138
139
140
# File 'app/models/decidim/participatory_process.rb', line 138

def self.active_spaces
  active
end

.future_spacesObject



142
143
144
# File 'app/models/decidim/participatory_process.rb', line 142

def self.future_spaces
  upcoming
end

.group_idsObject

Pluck all ParticipatoryProcessGroup ID’s



177
178
179
# File 'app/models/decidim/participatory_process.rb', line 177

def self.group_ids
  pluck(:decidim_participatory_process_group_id)
end

.groupedObject

Return processes that belong to a process group.



134
135
136
# File 'app/models/decidim/participatory_process.rb', line 134

def self.grouped
  where.not(decidim_participatory_process_group_id: nil)
end

.grouplessObject

Return processes that DO NOT belong to a process group.



129
130
131
# File 'app/models/decidim/participatory_process.rb', line 129

def self.groupless
  where(decidim_participatory_process_group_id: nil)
end

.log_presenter_class_for(_log) ⇒ Object



150
151
152
# File 'app/models/decidim/participatory_process.rb', line 150

def self.log_presenter_class_for(_log)
  Decidim::ParticipatoryProcesses::AdminLog::ParticipatoryProcessPresenter
end

.moderators(organization) ⇒ Object



194
195
196
# File 'app/models/decidim/participatory_process.rb', line 194

def self.moderators(organization)
  "#{admin_module_name}::Moderators".constantize.for_organization(organization)
end

.past_spacesObject



146
147
148
# File 'app/models/decidim/participatory_process.rb', line 146

def self.past_spaces
  past
end

Scope to return only the promoted processes.

Returns an ActiveRecord::Relation.



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

def self.promoted
  where(promoted: true)
end

.ransackable_associations(_auth_object = nil) ⇒ Object



227
228
229
# File 'app/models/decidim/participatory_process.rb', line 227

def self.ransackable_associations(_auth_object = nil)
  %w(participatory_process_group taxonomies)
end

.ransackable_attributes(auth_object = nil) ⇒ Object



220
221
222
223
224
225
# File 'app/models/decidim/participatory_process.rb', line 220

def self.ransackable_attributes(auth_object = nil)
  base = %w(title short_description description id)
  return base unless auth_object&.admin?

  base + %w(published_at created_at decidim_participatory_process_group_id access_mode)
end

.ransackable_scopes(_auth_object = nil) ⇒ Object



216
217
218
# File 'app/models/decidim/participatory_process.rb', line 216

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

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


158
159
160
161
162
# File 'app/models/decidim/participatory_process.rb', line 158

def active?
  return false if start_date.blank?

  start_date <= Date.current && (end_date.blank? || end_date >= Date.current)
end

#attachment_contextObject



205
206
207
# File 'app/models/decidim/participatory_process.rb', line 205

def attachment_context
  :admin
end

#closed?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'app/models/decidim/participatory_process.rb', line 181

def closed?
  past?
end

#moderatorsObject

Overrides the moderators methods from ‘Participable`.



190
191
192
# File 'app/models/decidim/participatory_process.rb', line 190

def moderators
  "#{admin_module_name}::Moderators".constantize.for(self)
end

#past?Boolean

Returns:

  • (Boolean)


164
165
166
167
168
# File 'app/models/decidim/participatory_process.rb', line 164

def past?
  return false if end_date.blank?

  end_date < Date.current
end

#presenterObject



154
155
156
# File 'app/models/decidim/participatory_process.rb', line 154

def presenter
  @presenter ||= Decidim::ParticipatoryProcesses::ParticipatoryProcessPresenter.new(self)
end

#shareable_url(share_token) ⇒ Object



209
210
211
# File 'app/models/decidim/participatory_process.rb', line 209

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

#to_paramObject



185
186
187
# File 'app/models/decidim/participatory_process.rb', line 185

def to_param
  slug
end

#upcoming?Boolean

Returns:

  • (Boolean)


170
171
172
173
174
# File 'app/models/decidim/participatory_process.rb', line 170

def upcoming?
  return false if start_date.blank?

  start_date > Date.current
end

#user_roles(role_name = nil) ⇒ Object



198
199
200
201
202
203
# File 'app/models/decidim/participatory_process.rb', line 198

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

  roles.where(role: role_name)
end