Class: Decidim::Meetings::Meeting

Inherits:
ApplicationRecord show all
Includes:
ActsAsAuthor, Authorable, Comments::CommentableWithComponent, Comments::HasAvailabilityAttributes, FilterableResource, Followable, Forms::HasQuestionnaire, HasAttachmentCollections, HasAttachments, HasCategory, HasComponent, HasReference, Loggable, Paddable, Publicable, Reportable, Resourceable, ScopableResource, Searchable, Traceable, TranslatableResource
Defined in:
app/models/decidim/meetings/meeting.rb

Overview

The data store for a Meeting in the Decidim::Meetings component. It stores a title, description and any other useful information to render a custom meeting.

Constant Summary collapse

TYPE_OF_MEETING =
%w(in_person online hybrid).freeze
REGISTRATION_TYPE =
%w(registration_disabled on_this_platform on_different_platform).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



171
172
173
# File 'app/models/decidim/meetings/meeting.rb', line 171

def self.log_presenter_class_for(_log)
  Decidim::Meetings::AdminLog::MeetingPresenter
end

.participants_iframe_embed_typesObject



156
157
158
# File 'app/models/decidim/meetings/meeting.rb', line 156

def self.participants_iframe_embed_types
  iframe_embed_types.except(:open_in_live_event_page)
end

.ransack(params = {}, options = {}) ⇒ Object



387
388
389
# File 'app/models/decidim/meetings/meeting.rb', line 387

def self.ransack(params = {}, options = {})
  MeetingSearch.new(self, params, options)
end

.ransackable_scopes(_auth_object = nil) ⇒ Object



383
384
385
# File 'app/models/decidim/meetings/meeting.rb', line 383

def self.ransackable_scopes(_auth_object = nil)
  [:with_any_type, :with_any_date, :with_any_space, :with_any_origin, :with_any_scope, :with_any_category, :with_any_global_category]
end

.sort_by_translated_title_ascObject



361
362
363
364
# File 'app/models/decidim/meetings/meeting.rb', line 361

def self.sort_by_translated_title_asc
  field = Arel::Nodes::InfixOperation.new("->>", arel_table[:title], Arel::Nodes.build_quoted(I18n.locale))
  order(Arel::Nodes::InfixOperation.new("", field, Arel.sql("ASC")))
end

.sort_by_translated_title_descObject



366
367
368
369
# File 'app/models/decidim/meetings/meeting.rb', line 366

def self.sort_by_translated_title_desc
  field = Arel::Nodes::InfixOperation.new("->>", arel_table[:title], Arel::Nodes.build_quoted(I18n.locale))
  order(Arel::Nodes::InfixOperation.new("", field, Arel.sql("DESC")))
end

Instance Method Details

#accepts_new_comments?Boolean

Public: Overrides the ‘accepts_new_comments?` CommentableWithComponent concern method.

Returns:

  • (Boolean)


215
216
217
# File 'app/models/decidim/meetings/meeting.rb', line 215

def accepts_new_comments?
  commentable? && !component.current_settings.comments_blocked && comments_allowed?
end

#allow_resource_permissions?Boolean

Public: Overrides the ‘allow_resource_permissions?` Resourceable concern method.

Returns:

  • (Boolean)


220
221
222
# File 'app/models/decidim/meetings/meeting.rb', line 220

def allow_resource_permissions?
  component.settings.resources_permissions_enabled
end

#authored_proposalsObject



300
301
302
303
304
305
306
307
308
309
310
311
# File 'app/models/decidim/meetings/meeting.rb', line 300

def authored_proposals
  return [] unless Decidim::Meetings.enable_proposal_linking

  Decidim::Proposals::Proposal
    .joins(:coauthorships)
    .where(
      decidim_coauthorships: {
        decidim_author_type: "Decidim::Meetings::Meeting",
        decidim_author_id: id
      }
    )
end

#can_be_joined_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


175
176
177
# File 'app/models/decidim/meetings/meeting.rb', line 175

def can_be_joined_by?(user)
  !closed? && registrations_enabled? && can_participate?(user)
end

#can_participate?(user) ⇒ Boolean

Returns:

  • (Boolean)


239
240
241
# File 'app/models/decidim/meetings/meeting.rb', line 239

def can_participate?(user)
  can_participate_in_space?(user) && can_participate_in_meeting?(user)
end

#can_register_invitation?(user) ⇒ Boolean

Returns:

  • (Boolean)


179
180
181
182
# File 'app/models/decidim/meetings/meeting.rb', line 179

def can_register_invitation?(user)
  !closed? && registrations_enabled? &&
    can_participate_in_space?(user) && user_has_invitation_for_meeting?(user)
end

#closed?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'app/models/decidim/meetings/meeting.rb', line 184

def closed?
  closed_at.present?
end

#comments_have_alignment?Boolean

Public: Overrides the ‘comments_have_alignment?` Commentable concern method.

Returns:

  • (Boolean)


225
226
227
# File 'app/models/decidim/meetings/meeting.rb', line 225

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

Public: Overrides the ‘comments_have_votes?` Commentable concern method.

Returns:

  • (Boolean)


230
231
232
# File 'app/models/decidim/meetings/meeting.rb', line 230

def comments_have_votes?
  true
end

#current_user_can_visit_meeting?(user) ⇒ Boolean

Returns:

  • (Boolean)


243
244
245
# File 'app/models/decidim/meetings/meeting.rb', line 243

def current_user_can_visit_meeting?(user)
  Decidim::Meetings::Meeting.visible_for(user).exists?(id: id)
end

#emendation?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'app/models/decidim/meetings/meeting.rb', line 192

def emendation?
  false
end

#has_attendees?Boolean

Returns:

  • (Boolean)


350
351
352
# File 'app/models/decidim/meetings/meeting.rb', line 350

def has_attendees?
  !!attendees_count && attendees_count.positive?
end

#has_available_slots?Boolean

Returns:

  • (Boolean)


196
197
198
199
200
# File 'app/models/decidim/meetings/meeting.rb', line 196

def has_available_slots?
  return true if available_slots.zero?

  (available_slots - reserved_slots) > registrations.count
end

#has_contributions?Boolean

Returns:

  • (Boolean)


346
347
348
# File 'app/models/decidim/meetings/meeting.rb', line 346

def has_contributions?
  !!contributions_count && contributions_count.positive?
end

#has_registration_for?(user) ⇒ Boolean

Returns:

  • (Boolean)


206
207
208
# File 'app/models/decidim/meetings/meeting.rb', line 206

def has_registration_for?(user)
  registrations.where(user: user).any?
end

#iframe_access_level_allowed_for_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


247
248
249
250
251
252
253
254
255
256
# File 'app/models/decidim/meetings/meeting.rb', line 247

def iframe_access_level_allowed_for_user?(user)
  case iframe_access_level
  when "all"
    true
  when "signed_in"
    user.present?
  else
    has_registration_for?(user)
  end
end

#live?Boolean

Returns:

  • (Boolean)


354
355
356
357
358
359
# File 'app/models/decidim/meetings/meeting.rb', line 354

def live?
  start_time &&
    end_time &&
    Time.current >= (start_time - 10.minutes) &&
    Time.current <= end_time
end

#maps_enabled?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'app/models/decidim/meetings/meeting.rb', line 210

def maps_enabled?
  component.settings.maps_enabled?
end

#meeting_durationObject

Return the duration of the meeting in minutes



259
260
261
# File 'app/models/decidim/meetings/meeting.rb', line 259

def meeting_duration
  @meeting_duration ||= ((end_time - start_time) / 1.minute).abs
end

#on_different_platform?Boolean

Returns:

  • (Boolean)


342
343
344
# File 'app/models/decidim/meetings/meeting.rb', line 342

def on_different_platform?
  registration_type == "on_different_platform"
end

#on_this_platform?Boolean

Returns:

  • (Boolean)


338
339
340
# File 'app/models/decidim/meetings/meeting.rb', line 338

def on_this_platform?
  registration_type == "on_this_platform"
end

#pad_is_visible?Boolean

Overwrites method from Paddable to add custom rules in order to know when to display a pad or not.

Returns:

  • (Boolean)


286
287
288
289
290
# File 'app/models/decidim/meetings/meeting.rb', line 286

def pad_is_visible?
  return false unless pad

  (start_time - Time.current) <= 24.hours
end

#pad_is_writable?Boolean

Overwrites method from Paddable to add custom rules in order to know when a pad is writable or not.

Returns:

  • (Boolean)


294
295
296
297
298
# File 'app/models/decidim/meetings/meeting.rb', line 294

def pad_is_writable?
  return false unless pad_is_visible?

  (Time.current - end_time) < 72.hours
end

#past?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'app/models/decidim/meetings/meeting.rb', line 188

def past?
  end_time < Time.current
end

#presenterObject

Returns the presenter for this author, to be used in the views. Required by ActsAsAuthor.



167
168
169
# File 'app/models/decidim/meetings/meeting.rb', line 167

def presenter
  Decidim::Meetings::MeetingPresenter.new(self)
end

#registration_disabled?Boolean

Returns:

  • (Boolean)


334
335
336
# File 'app/models/decidim/meetings/meeting.rb', line 334

def registration_disabled?
  registration_type == "registration_disabled"
end

#remaining_slotsObject



202
203
204
# File 'app/models/decidim/meetings/meeting.rb', line 202

def remaining_slots
  available_slots - reserved_slots - registrations.count
end

#reported_attributesObject

Public: Overrides the ‘reported_attributes` Reportable concern method.



319
320
321
# File 'app/models/decidim/meetings/meeting.rb', line 319

def reported_attributes
  [:description]
end

#reported_content_urlObject

Public: Overrides the ‘reported_content_url` Reportable concern method.



314
315
316
# File 'app/models/decidim/meetings/meeting.rb', line 314

def reported_content_url
  ResourceLocatorPresenter.new(self).url
end

#reported_searchable_content_extrasObject

Public: Overrides the ‘reported_searchable_content_extras` Reportable concern method.



324
325
326
# File 'app/models/decidim/meetings/meeting.rb', line 324

def reported_searchable_content_extras
  [normalized_author.name]
end

#resource_visible?Boolean

Returns:

  • (Boolean)


263
264
265
266
267
# File 'app/models/decidim/meetings/meeting.rb', line 263

def resource_visible?
  return false if hidden?

  !private_meeting? || transparent?
end

#user_group_registrationsObject

Return registrations of a particular meeting made by users representing a group



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

def user_group_registrations
  registrations.where.not(decidim_user_group_id: nil)
end

#users_to_notify_on_comment_createdObject

Public: Override Commentable concern method ‘users_to_notify_on_comment_created`



235
236
237
# File 'app/models/decidim/meetings/meeting.rb', line 235

def users_to_notify_on_comment_created
  followers
end

#withdrawable_by?(user) ⇒ Boolean

Checks whether the user can withdraw the given meeting.

user - the user to check for withdrawability. past meetings cannot be withdrawn

Returns:

  • (Boolean)


280
281
282
# File 'app/models/decidim/meetings/meeting.rb', line 280

def withdrawable_by?(user)
  user && !withdrawn? && !past? && authored_by?(user)
end

#withdrawn?Boolean

Public: Checks if the author has withdrawn the meeting.

Returns Boolean.

Returns:

  • (Boolean)


272
273
274
# File 'app/models/decidim/meetings/meeting.rb', line 272

def withdrawn?
  state == "withdrawn"
end