diff --git a/app/controllers/v1/collections_controller.rb b/app/controllers/v1/collections_controller.rb index b908899964e33658e5a23d95a254b5626c6106eb..a46d143816e313801d8b93606f9ef02c8ea684f3 100644 --- a/app/controllers/v1/collections_controller.rb +++ b/app/controllers/v1/collections_controller.rb @@ -16,7 +16,7 @@ class V1::CollectionsController < ApplicationController # GET /v1/collections # GET /v1/collections.json def index - collections = paginate Collection + collections = paginate policy_scope(Collection) render json: collections end diff --git a/app/policies/collection_policy.rb b/app/policies/collection_policy.rb index 8aeafcd2e3301106ac7b09318f47d12ce57b1593..7ca595c7cd867bdbaf48d7f9c858c140a0fe1a21 100644 --- a/app/policies/collection_policy.rb +++ b/app/policies/collection_policy.rb @@ -6,17 +6,11 @@ class CollectionPolicy < ApplicationPolicy include StageablePolicy class Scope < Scope - def initialize(user, user_id, scope) - @user = user - @user_id = user_id - @scope = scope - end - def resolve - if @user.try(:id) == @user_id || @user.try(:is_admin?) + if !user.nil? && user.is_admin? scope.all else - scope.where(privacy: 'public') + scope.includes(:collection_items).where.not(:collection_items => {:collection_id => nil}).where(privacy: 'public') end end end