docbrown/app/controllers/internal/comments_controller.rb
Mac Siri d976eb7ab6 Create InternalPolicy (#4380)
* Ensure verify_authorized in internal

* Create internal_policy

* Replace ArticlePolicy usage with InternalPolicy

* Replace BufferUpdate&CommentPolicy with InternalPolicy

* Remove verbose authorize_admin

* Forgot to remove coresponding specs

* Create specs for InternalPolicy

* Expand policy access on internal's broadcast

* Refactor

* Create shared spec

* Create request specs

* Add additional test cases
2019-10-17 14:21:43 -04:00

28 lines
917 B
Ruby

class Internal::CommentsController < Internal::ApplicationController
layout "internal"
def index
@comments = if params[:state]&.start_with?("toplast-")
Comment.
includes(:user).
includes(:commentable).
includes(:reactions).
order("positive_reactions_count DESC").
where("created_at > ?", params[:state].split("-").last.to_i.days.ago).
page(params[:page] || 1).per(50)
else
Comment.
includes(:user).
includes(:commentable).
includes(:reactions).
order("created_at DESC").
page(params[:page] || 1).per(50)
end
end
private
def authorize_admin
authorize Comment, :access?, policy_class: InternalPolicy
end
end