docbrown/app/policies/article_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

53 lines
1,017 B
Ruby

class ArticlePolicy < ApplicationPolicy
def update?
user_is_author? || user_admin? || user_org_admin? || minimal_admin?
end
def new?
true
end
def create?
!user_is_banned?
end
def delete_confirm?
update?
end
def destroy?
update?
end
def preview?
true
end
def analytics_index?
(user_is_author? && user_can_view_analytics?) || user_org_admin?
end
def permitted_attributes
%i[title body_html body_markdown main_image published canonical_url
description allow_small_edits allow_big_edits tag_list publish_under_org
video video_code video_source_url video_thumbnail_url receive_notifications]
end
private
def user_is_author?
if record.instance_of?(Article)
record.user_id == user.id
else
record.pluck(:user_id).uniq == [user.id]
end
end
def user_org_admin?
user.org_admin && user.organization_id == record.organization_id
end
def user_can_view_analytics?
user.can_view_analytics?
end
end