Skip to content
Snippets Groups Projects
Commit 97e0662c authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'bugs' into 'master'

Bugs - Collections

See merge request !417
parents 4d58eaa6 65a9d2f8
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
......
......@@ -7,8 +7,12 @@ class CollectionPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if !user.nil? && user.is_admin?
scope.all
if !user.nil?
if user.is_admin?
scope.all
else
scope.includes(:collection_items).where.not(:collection_items => {:collection_id => nil}).where("privacy = ? OR owner_id = ?", 'public', user.id)
end
else
scope.includes(:collection_items).where.not(:collection_items => {:collection_id => nil}).where(privacy: 'public')
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