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


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

#anonymous?Boolean


48
49
50
# File 'app/policies/thredded/post_policy.rb', line 48

def anonymous?
  @user.thredded_anonymous?
end

#create?Boolean


28
29
30
31
32
33
34
# File 'app/policies/thredded/post_policy.rb', line 28

def create?
  @user.thredded_admin? ||
    !@post.postable.locked? &&
      # Users are allowed to post in unlocked topics of a locked messageboard
      # only if they would be allowed to post if the messageboard wasn't locked.
      @user.thredded_can_write_messageboards.include?(@post.messageboard)
end

#destroy?Boolean


44
45
46
# File 'app/policies/thredded/post_policy.rb', line 44

def destroy?
  !@post.first_post_in_topic? && update?
end

#read?Boolean


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

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

#update?Boolean


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

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