Class: Thredded::PostPolicy

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

Defined Under Namespace

Classes: Scope

Instance Method Summary collapse

Constructor Details

#initialize(user, post) ⇒ PostPolicy

Returns a new instance of PostPolicy.

Parameters:



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

def initialize(user, post)
  @user = user
  @post = post
end

Instance Method Details

#create?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/policies/thredded/post_policy.rb', line 28

def create?
  @user.thredded_admin? || !@post.postable.locked? && messageboard_policy.post?
end

#destroy?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/policies/thredded/post_policy.rb', line 40

def destroy?
  @post.postable.first_post != @post && update?
end

#read?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/policies/thredded/post_policy.rb', line 32

def read?
  TopicPolicy.new(@user, @post.postable).read? && @post.moderation_state_visible_to_user?(@user)
end

#update?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/policies/thredded/post_policy.rb', line 36

def update?
  @user.thredded_admin? || own_post? || messageboard_policy.moderate?
end