Substantially improved item libraries UI, locked behind Patreon tier 5

This commit is contained in:
Stefan Zermatten
2019-05-06 14:51:48 +02:00
parent d4864dda5f
commit 81a3ede86e
24 changed files with 493 additions and 248 deletions

View File

@@ -25,16 +25,61 @@ Meteor.publish("standardLibrarySpells", function(level){
});
Meteor.publish("customLibraries", function(){
userId = this.userId;
const userId = this.userId;
let user = Meteor.user()
let subs = user && user.profile && user.profile.librarySubscriptions;
return Libraries.find({
$or: [
{readers: userId},
{writers: userId},
{owner: userId},
{public: true, _id: {$in: subs || []}},
],
});
});
Meteor.publish("singleLibrary", function(id){
const userId = this.userId;
return Libraries.find({
_id: id,
$or: [
{readers: userId},
{writers: userId},
{owner: userId},
{public: true},
],
});
});
Meteor.publish("libraryItems", function(libraryId){
return LibraryItems.find({library: libraryId});
return LibraryItems.find({
library: libraryId
}, {
fields: {
name: 1,
libraryName: 1,
library: 1,
},
});
});
Meteor.publish("libraryItem", function(itemId){
let cursor = LibraryItems.find(itemId);
let item = cursor.fetch()[0];
let userId = Meteor.userId();
if (!item) return [];
let library = Libraries.findOne(item.library);
if (!library) {
throw new Meteor.Error("Library item " + item._id + " is an orphan");
}
if (
library.public ||
library.owner === userId ||
_.contains(library.readers, userId) ||
_.contains(library.writers, userId)
) {
return cursor;
} else {
return [];
}
});