Class: Decidim::Meetings::Meeting

Inherits:
ApplicationRecord show all
Includes:
Comments::Commentable, Followable, Forms::HasQuestionnaire, HasAttachmentCollections, HasAttachments, HasCategory, HasComponent, HasReference, Hashtaggable, Loggable, Paddable, Resourceable, ScopableComponent, Searchable, Traceable
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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_presenter_class_for(_log) ⇒ Object



59
60
61
# File 'app/models/decidim/meetings/meeting.rb', line 59

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

Instance Method Details

#accepts_new_comments?Boolean

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

Returns:

  • (Boolean)


90
91
92
# File 'app/models/decidim/meetings/meeting.rb', line 90

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

#allow_resource_permissions?Boolean

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

Returns:

  • (Boolean)


95
96
97
# File 'app/models/decidim/meetings/meeting.rb', line 95

def allow_resource_permissions?
  component.settings.resources_permissions_enabled
end

#can_be_joined_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/decidim/meetings/meeting.rb', line 63

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

#can_participate?(user) ⇒ Boolean

rubocop:disable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity

Returns:

  • (Boolean)


115
116
117
118
119
120
121
122
123
# File 'app/models/decidim/meetings/meeting.rb', line 115

def can_participate?(user)
  return true unless participatory_space.try(:private_space?) || private_meeting?
  return true if (participatory_space.try(:private_space?) &&
                  participatory_space.users.include?(user)) ||
                 (private_meeting? && registrations.exists?(decidim_user_id: user.try(:id)))
  return false if (participatory_space.try(:private_space?) &&
                  participatory_space.try(:transparent?)) ||
                  (private_meeting? && transparent?)
end

#closed?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/decidim/meetings/meeting.rb', line 67

def closed?
  closed_at.present?
end

#commentable?Boolean

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

Returns:

  • (Boolean)


85
86
87
# File 'app/models/decidim/meetings/meeting.rb', line 85

def commentable?
  component.settings.comments_enabled?
end

#comments_have_alignment?Boolean

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

Returns:

  • (Boolean)


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

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)


105
106
107
# File 'app/models/decidim/meetings/meeting.rb', line 105

def comments_have_votes?
  true
end

#current_user_can_visit_meeting?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


135
136
137
138
# File 'app/models/decidim/meetings/meeting.rb', line 135

def current_user_can_visit_meeting?(current_user)
  (private_meeting? && registrations.exists?(decidim_user_id: current_user.try(:id))) ||
    !private_meeting? || (private_meeting? && transparent?)
end

#has_available_slots?Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'app/models/decidim/meetings/meeting.rb', line 71

def has_available_slots?
  return true if available_slots.zero?
  (available_slots - reserved_slots) > registrations.count
end

#has_registration_for?(user) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#meeting_durationObject

Return the duration of the meeting in minutes



141
142
143
# File 'app/models/decidim/meetings/meeting.rb', line 141

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

#official?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'app/models/decidim/meetings/meeting.rb', line 131

def official?
  organizer.nil?
end

#organizer_belongs_to_organizationObject

rubocop:enable Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity



126
127
128
129
# File 'app/models/decidim/meetings/meeting.rb', line 126

def organizer_belongs_to_organization
  return if !organizer || !organization
  errors.add(:organizer, :invalid) unless organizer.organization == organization
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)


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

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)


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

def pad_is_writable?
  return false unless pad_is_visible?

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

#remaining_slotsObject



76
77
78
# File 'app/models/decidim/meetings/meeting.rb', line 76

def remaining_slots
  available_slots - reserved_slots - registrations.count
end

#resource_visible?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'app/models/decidim/meetings/meeting.rb', line 145

def resource_visible?
  !private_meeting? || transparent?
end

#users_to_notify_on_comment_createdObject

Public: Override Commentable concern method ‘users_to_notify_on_comment_created`



110
111
112
# File 'app/models/decidim/meetings/meeting.rb', line 110

def users_to_notify_on_comment_created
  followers
end