Skip to content
Snippets Groups Projects
Commit 02b7b1a1 authored by Clarissa's avatar Clarissa
Browse files

#214: fix bug - Dont show private collection inside a public collection

parent 59e8fb3f
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,14 @@ class CollectionItem < ApplicationRecord
collection
end
def public?
collectionable.privacy == 'public'
end
def owner?(candidate)
collectionable.owner == candidate
end
def thumbnail
collectionable_type == 'LearningObject' ? LearningObject.find(collectionable_id).default_thumbnail : Collection.find(collectionable_id).thumbnail
end
......
class CollectionItemSerializer < ActiveModel::Serializer
cache key: 'collection_item', expires_in: 24.hours
def collectionable
serializer = object.collectionable_type == "LearningObject" ? ::LearningObjectSerializer : ::CollectionMinSerializer
serializer.new(object.collectionable, {scope: current_user, scope_name: :current_user}).serializable_hash
if ( object.collectionable_type == "LearningObject" )
serializer = ::LearningObjectSerializer
elsif ( object.public? || (current_user && ( object.owner?(current_user) || current_user.is_admin? )) )
serializer = ::CollectionMinSerializer
end
if ( !serializer.blank? )
serializer.new(object.collectionable, {scope: current_user, scope_name: :current_user}).serializable_hash
end
end
belongs_to :collectionable, polymorphic: true
attributes :id, :position, :collectionable, :collectionable_type
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment