Module: WithResponsibleModerator

Extended by:
ActiveSupport::Concern
Included in:
Discussion
Defined in:
app/models/concerns/with_responsible_moderator.rb

Constant Summary collapse

MODERATOR_MAX_RESPONSIBLE_TIME =
45.minutes

Instance Method Summary collapse

Instance Method Details

#any_responsible?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/models/concerns/with_responsible_moderator.rb', line 14

def any_responsible?
  responsible_moderator_at.present? && (responsible_moderator_at + MODERATOR_MAX_RESPONSIBLE_TIME).future?
end

#can_toggle_responsible?(user) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/concerns/with_responsible_moderator.rb', line 30

def can_toggle_responsible?(user)
  can_have_responsible? && user_can_be_responsible?(user)
end

#current_responsible_visible_for?(user) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/concerns/with_responsible_moderator.rb', line 26

def current_responsible_visible_for?(user)
  user&.moderator_here? && any_responsible?
end

#no_current_responsible?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/concerns/with_responsible_moderator.rb', line 18

def no_current_responsible?
  !any_responsible?
end

#responsible?(moderator) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/concerns/with_responsible_moderator.rb', line 22

def responsible?(moderator)
  any_responsible? && responsible_moderator_by == moderator
end

#toggle_responsible!(moderator) ⇒ Object



6
7
8
9
10
11
12
# File 'app/models/concerns/with_responsible_moderator.rb', line 6

def toggle_responsible!(moderator)
  if responsible?(moderator)
    no_responsible!
  elsif no_current_responsible?
    responsible! moderator
  end
end