Class: Thredded::PostPolicy
- Inherits:
-
Object
- Object
- Thredded::PostPolicy
- Defined in:
- app/policies/thredded/post_policy.rb
Defined Under Namespace
Classes: Scope
Instance Method Summary collapse
- #create? ⇒ Boolean
- #destroy? ⇒ Boolean
-
#initialize(user, post) ⇒ PostPolicy
constructor
A new instance of PostPolicy.
- #read? ⇒ Boolean
- #update? ⇒ Boolean
Constructor Details
#initialize(user, post) ⇒ PostPolicy
Returns a new instance of 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
#create? ⇒ Boolean
28 29 30 |
# File 'app/policies/thredded/post_policy.rb', line 28 def create? @user.thredded_admin? || !@post.postable.locked? && .post? end |
#destroy? ⇒ Boolean
40 41 42 |
# File 'app/policies/thredded/post_policy.rb', line 40 def destroy? @post.postable.first_post != @post && update? end |
#read? ⇒ 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
36 37 38 |
# File 'app/policies/thredded/post_policy.rb', line 36 def update? @user.thredded_admin? || own_post? || .moderate? end |