docbrown/app/policies/comment_policy.rb
Andy Zhao c4677071a7 Mute notifications for a comment thread (#1636)
* Use idempotent update instead of toggle

* Update editor guide with new comment instructions

* Render the settings button on page load

* Add settings button to comment dropdown

* Update styles to properly render

* Add comment mute function and settings page

* Clean up erb spacing

* Remove unneccessary user_id param

* Add receive_notifications for policy spec

* Update name for accuracy

* Add request spec for comments_mute

* Remove unused permitted attributes

* Add actually used permitted attributes
2019-01-24 17:20:38 -05:00

51 lines
726 B
Ruby

class CommentPolicy < ApplicationPolicy
def edit?
user_is_author?
end
def create?
!user_is_banned? && !user_is_comment_banned?
end
def update?
edit?
end
def destroy?
edit?
end
def delete_confirm?
edit?
end
def settings?
edit?
end
def preview?
true
end
def permitted_attributes_for_update
%i[body_markdown receive_notifications]
end
def permitted_attributes_for_preview
%i[body_markdown]
end
def permitted_attributes_for_create
%i[body_markdown commentable_id commentable_type parent_id]
end
private
def user_is_comment_banned?
user.has_role? :comment_banned
end
def user_is_author?
record.user_id == user.id
end
end