Improved publications to be reactive to permission changes
This commit is contained in:
@@ -49,3 +49,4 @@ aldeed:schema-index
|
||||
akryum:vue-component
|
||||
accounts-patreon
|
||||
bozhao:link-accounts
|
||||
peerlibrary:reactive-publish
|
||||
|
||||
@@ -27,6 +27,8 @@ caching-html-compiler@1.1.3
|
||||
callback-hook@1.3.0
|
||||
check@1.3.1
|
||||
chuangbo:marked@0.3.5_1
|
||||
coffeescript@2.4.1
|
||||
coffeescript-compiler@2.4.1
|
||||
dburles:collection-helpers@1.1.0
|
||||
dburles:mongo-collection-instances@0.3.5
|
||||
ddp@1.4.0
|
||||
@@ -91,6 +93,12 @@ observe-sequence@1.0.16
|
||||
ongoworks:speakingurl@9.0.0
|
||||
ordered-dict@1.1.0
|
||||
patreon-oauth@0.1.0
|
||||
peerlibrary:assert@0.3.0
|
||||
peerlibrary:extend-publish@0.6.0
|
||||
peerlibrary:fiber-utils@0.10.0
|
||||
peerlibrary:reactive-mongo@0.4.0
|
||||
peerlibrary:reactive-publish@0.10.0
|
||||
peerlibrary:server-autorun@0.8.0
|
||||
percolate:migrations@0.9.8
|
||||
percolate:synced-cron@1.3.2
|
||||
promise@0.11.2
|
||||
|
||||
@@ -2,37 +2,41 @@ import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import Parties from '/imports/api/campaign/Parties.js';
|
||||
|
||||
Meteor.publish('characterList', function(){
|
||||
var userId = this.userId;
|
||||
if (!userId) {
|
||||
return [];
|
||||
}
|
||||
const user = Meteor.user();
|
||||
const subs = user && user.subscribedCharacters || [];
|
||||
return [
|
||||
Creatures.find({
|
||||
$or: [
|
||||
{readers: userId},
|
||||
{writers: userId},
|
||||
{owner: userId},
|
||||
{_id: {$in: subs}},
|
||||
],
|
||||
type: 'pc',
|
||||
}, {
|
||||
fields: {
|
||||
name: 1,
|
||||
initial: 1,
|
||||
alignment: 1,
|
||||
gender: 1,
|
||||
readers: 1,
|
||||
writers:1,
|
||||
owner: 1,
|
||||
color: 1,
|
||||
picture: 1,
|
||||
avatarPicture: 1,
|
||||
public: 1,
|
||||
}
|
||||
}
|
||||
),
|
||||
Parties.find({owner: userId}),
|
||||
];
|
||||
this.autorun(function (){
|
||||
var userId = this.userId;
|
||||
if (!userId) {
|
||||
return this.ready();
|
||||
}
|
||||
const user = Meteor.users.findOne(this.userId, {
|
||||
fields: {subscribedCharacters: 1}
|
||||
});
|
||||
const subs = user && user.subscribedCharacters || [];
|
||||
return [
|
||||
Creatures.find({
|
||||
$or: [
|
||||
{readers: userId},
|
||||
{writers: userId},
|
||||
{owner: userId},
|
||||
{_id: {$in: subs}},
|
||||
],
|
||||
type: 'pc',
|
||||
}, {
|
||||
fields: {
|
||||
name: 1,
|
||||
initial: 1,
|
||||
alignment: 1,
|
||||
gender: 1,
|
||||
readers: 1,
|
||||
writers:1,
|
||||
owner: 1,
|
||||
color: 1,
|
||||
picture: 1,
|
||||
avatarPicture: 1,
|
||||
public: 1,
|
||||
}
|
||||
}
|
||||
),
|
||||
Parties.find({owner: userId}),
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,44 +1,61 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import Libraries from '/imports/api/library/Libraries.js';
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||
|
||||
const standardLibraryIds = [
|
||||
'SRDLibraryGA3XWsd',
|
||||
'SRDLibraryGA3XWsd',
|
||||
];
|
||||
|
||||
Meteor.publish('standardLibraries', function(){
|
||||
return Libraries.find({_id: {$in: standardLibraryIds}});
|
||||
return Libraries.find({_id: {$in: standardLibraryIds}});
|
||||
});
|
||||
|
||||
Meteor.publish('libraries', function(){
|
||||
if (!this.userId) return [];
|
||||
const user = Meteor.user();
|
||||
const subs = user && user.subscribedLibraries || [];
|
||||
return Libraries.find({
|
||||
$or: [
|
||||
{owner: this.userId},
|
||||
{writers: this.userId},
|
||||
{readers: this.userId},
|
||||
{_id: {$in: subs}},
|
||||
]
|
||||
});
|
||||
this.autorun(function (){
|
||||
if (!this.userId) {
|
||||
return this.ready();
|
||||
}
|
||||
const user = Meteor.users.findOne(this.userId, {
|
||||
fields: {subscribedLibraries: 1}
|
||||
});
|
||||
const subs = user && user.subscribedLibraries || [];
|
||||
return Libraries.find({
|
||||
$or: [
|
||||
{owner: this.userId},
|
||||
{writers: this.userId},
|
||||
{readers: this.userId},
|
||||
{_id: {$in: subs}},
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
let libraryIdSchema = new SimpleSchema({
|
||||
libraryId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish('library', function(libraryId){
|
||||
if (!this.userId) return [];
|
||||
let libraryCursor = Libraries.find({
|
||||
_id: libraryId,
|
||||
$or: [
|
||||
{owner: this.userId},
|
||||
{writers: this.userId},
|
||||
{readers: this.userId},
|
||||
{public: true},
|
||||
],
|
||||
});
|
||||
if (!libraryCursor.count()) return [];
|
||||
return [
|
||||
libraryCursor,
|
||||
LibraryNodes.find({
|
||||
'ancestors.id': libraryId,
|
||||
}),
|
||||
];
|
||||
libraryIdSchema.validate({libraryId});
|
||||
this.autorun(function (){
|
||||
if (!this.userId) return [];
|
||||
let libraryCursor = Libraries.find({
|
||||
_id: libraryId,
|
||||
$or: [
|
||||
{owner: this.userId},
|
||||
{writers: this.userId},
|
||||
{readers: this.userId},
|
||||
{public: true},
|
||||
],
|
||||
});
|
||||
if (!libraryCursor.count()) return this.ready();
|
||||
return [
|
||||
libraryCursor,
|
||||
LibraryNodes.find({
|
||||
'ancestors.id': libraryId,
|
||||
}),
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
Meteor.publish('singleCharacter', function(charId){
|
||||
let userId = this.userId;
|
||||
var char = Creatures.findOne({
|
||||
_id: charId,
|
||||
$or: [
|
||||
{readers: userId},
|
||||
{writers: userId},
|
||||
{owner: userId},
|
||||
{public: true},
|
||||
],
|
||||
});
|
||||
if (char){
|
||||
return [
|
||||
Creatures.find({_id: charId}),
|
||||
CreatureProperties.find({
|
||||
'ancestors.id': charId,
|
||||
}),
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
let schema = new SimpleSchema({
|
||||
creatureId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.publish('singleCharacter', function(creatureId){
|
||||
schema.validate({ creatureId });
|
||||
this.autorun(function (){
|
||||
let userId = this.userId;
|
||||
let creatureCursor = Creatures.find({
|
||||
_id: creatureId,
|
||||
$or: [
|
||||
{readers: userId},
|
||||
{writers: userId},
|
||||
{owner: userId},
|
||||
{public: true},
|
||||
],
|
||||
});
|
||||
if (!creatureCursor.count()) return this.ready();
|
||||
return [
|
||||
creatureCursor,
|
||||
CreatureProperties.find({
|
||||
'ancestors.id': creatureId,
|
||||
}),
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import '/imports/api/users/Users.js';
|
||||
import Invites from '/imports/api/users/Invites.js';
|
||||
|
||||
@@ -32,8 +33,19 @@ Meteor.publish('user', function(){
|
||||
];
|
||||
});
|
||||
|
||||
let userIdsSchema = new SimpleSchema({
|
||||
ids: {
|
||||
type: Array
|
||||
},
|
||||
'ids.$':{
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
}
|
||||
})
|
||||
|
||||
Meteor.publish('userPublicProfiles', function(ids){
|
||||
if (!this.userId || !Array.isArray(ids)) return [];
|
||||
userIdsSchema.validate({ids});
|
||||
if (!this.userId) return this.ready();
|
||||
return Meteor.users.find({
|
||||
_id: {$in: ids}
|
||||
},{
|
||||
|
||||
Reference in New Issue
Block a user