Class: Thredded::TopicPolicy

Inherits:
Object
  • Object
show all
Defined in:
app/policies/thredded/topic_policy.rb

Defined Under Namespace

Classes: Scope

Instance Method Summary collapse

Constructor Details

#initialize(user, topic) ⇒ TopicPolicy

Returns a new instance of TopicPolicy.

Parameters:



23
24
25
26
27
# File 'app/policies/thredded/topic_policy.rb', line 23

def initialize(user, topic)
  @user                = user
  @topic               = topic
  @messageboard_policy = Thredded::MessageboardPolicy.new(user, topic.messageboard)
end

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/policies/thredded/topic_policy.rb', line 29

def create?
  @messageboard_policy.post?
end

#destroy?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/policies/thredded/topic_policy.rb', line 41

def destroy?
  @user.thredded_admin?
end

#moderate?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/policies/thredded/topic_policy.rb', line 45

def moderate?
  @messageboard_policy.moderate?
end

#read?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/policies/thredded/topic_policy.rb', line 33

def read?
  @messageboard_policy.read? && @topic.moderation_state_visible_to_user?(@user)
end

#update?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/policies/thredded/topic_policy.rb', line 37

def update?
  @user.thredded_admin? || @topic.user_id == @user.id || moderate?
end