mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 17:41:43 -05:00
keepViewableFields -> restrictViewableFields (clearer name); always capitalize collection names; export new Collections array
This commit is contained in:
parent
f9386a07bd
commit
dd76442ab3
14 changed files with 29 additions and 20 deletions
|
@ -18,6 +18,7 @@
|
|||
"classnames": "^2.2.3",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"crypto-js": "^3.1.9-1",
|
||||
"dataloader": "^1.3.0",
|
||||
"deepmerge": "^1.2.0",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"express": "^4.14.0",
|
||||
|
|
|
@ -30,7 +30,7 @@ const resolvers = {
|
|||
|
||||
resolver(root, {documentId}, context) {
|
||||
const document = context.Comments.findOne({_id: documentId});
|
||||
return context.Users.keepViewableFields(context.currentUser, context.Comments, document);
|
||||
return context.Users.restrictViewableFields(context.currentUser, context.Comments, document);
|
||||
},
|
||||
|
||||
},
|
||||
|
|
|
@ -30,7 +30,7 @@ const resolvers = {
|
|||
|
||||
resolver(root, {documentId}, context) {
|
||||
const document = context.Pics.findOne({_id: documentId});
|
||||
return context.Users.keepViewableFields(context.currentUser, context.Pics, document);
|
||||
return context.Users.restrictViewableFields(context.currentUser, context.Pics, document);
|
||||
},
|
||||
|
||||
},
|
||||
|
|
|
@ -30,7 +30,7 @@ const resolvers = {
|
|||
|
||||
resolver(root, {documentId}, context) {
|
||||
const document = context.Movies.findOne({_id: documentId});
|
||||
return context.Users.keepViewableFields(context.currentUser, context.Movies, document);
|
||||
return context.Users.restrictViewableFields(context.currentUser, context.Movies, document);
|
||||
},
|
||||
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@ import { createCollection } from 'meteor/vulcan:core';
|
|||
*/
|
||||
const Categories = createCollection({
|
||||
|
||||
collectionName: 'categories',
|
||||
collectionName: 'Categories',
|
||||
|
||||
typeName: 'Category',
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { createCollection } from 'meteor/vulcan:core';
|
|||
*/
|
||||
const Comments = createCollection({
|
||||
|
||||
collectionName: 'comments',
|
||||
collectionName: 'Comments',
|
||||
|
||||
typeName: 'Comment',
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ export {
|
|||
// components
|
||||
Components, registerComponent, replaceComponent, getRawComponent, getComponent, copyHoCs, populateComponentsApp,
|
||||
// collections
|
||||
createCollection,
|
||||
Collections, createCollection,
|
||||
// fragments
|
||||
Fragments, registerFragment, getFragment, getFragmentName, extendFragment,
|
||||
// graphql
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import { Mongo } from 'meteor/mongo';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { GraphQLSchema } from './graphql.js';
|
||||
import { Utils } from './utils.js';
|
||||
import { runCallbacks } from './callbacks.js';
|
||||
|
||||
export const Collections = [];
|
||||
|
||||
SimpleSchema.extendOptions([
|
||||
'viewableBy',
|
||||
'insertableBy',
|
||||
|
@ -99,7 +102,7 @@ export const createCollection = options => {
|
|||
const {collectionName, typeName, schema, resolvers, mutations, generateGraphQLSchema = true, dbCollectionName } = options;
|
||||
|
||||
// initialize new Mongo collection
|
||||
const collection = collectionName === 'users' ? Meteor.users : new Mongo.Collection(dbCollectionName ? dbCollectionName : collectionName.toLowerCase());
|
||||
const collection = collectionName === 'Users' ? Meteor.users : new Mongo.Collection(dbCollectionName ? dbCollectionName : collectionName.toLowerCase());
|
||||
|
||||
// decorate collection with options
|
||||
collection.options = options;
|
||||
|
@ -212,5 +215,7 @@ export const createCollection = options => {
|
|||
return parameters;
|
||||
}
|
||||
|
||||
Collections.push(collection);
|
||||
|
||||
return collection;
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ import './icons.js';
|
|||
import './mongo_redux.js';
|
||||
|
||||
export { Components, registerComponent, replaceComponent, getRawComponent, getComponent, copyHoCs, populateComponentsApp } from './components.js';
|
||||
export { createCollection } from './collections.js';
|
||||
export { Collections, createCollection } from './collections.js';
|
||||
export { Callbacks, addCallback, removeCallback, runCallbacks, runCallbacksAsync } from './callbacks.js';
|
||||
export { GraphQLSchema, addGraphQLSchema, addGraphQLQuery, addGraphQLMutation, addGraphQLResolvers, removeGraphQLResolver, addToGraphQLContext } from './graphql.js';
|
||||
export { Routes, addRoute, getRoute, populateRoutesApp } from './routes.js';
|
||||
|
|
|
@ -21,10 +21,10 @@ const resolver = {
|
|||
if(context.currentUser && Users.isAdminById(context.currentUser._id))
|
||||
return Newsletters.send(true);
|
||||
},
|
||||
addUserNewsletter(root, args, context) {
|
||||
addUserNewsletter(root, {userId}, context) {
|
||||
|
||||
const currentUser = context.currentUser;
|
||||
const user = Users.findOne({_id: args.userId});
|
||||
const user = Users.findOne({_id: userId});
|
||||
if (!user || !Users.options.mutations.edit.check(currentUser, user)) {
|
||||
throw new Error(Utils.encodeIntlError({id: "app.noPermission"}));
|
||||
}
|
||||
|
@ -35,8 +35,7 @@ const resolver = {
|
|||
throw new Error(errorMessage);
|
||||
}
|
||||
},
|
||||
addEmailNewsletter(root, args, context) {
|
||||
const email = args.email;
|
||||
addEmailNewsletter(root, {email}, context) {
|
||||
try {
|
||||
return Newsletters.subscribeEmail(email, true);
|
||||
} catch (error) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { createCollection } from 'meteor/vulcan:core';
|
|||
*/
|
||||
const Posts = createCollection({
|
||||
|
||||
collectionName: 'posts',
|
||||
collectionName: 'Posts',
|
||||
|
||||
typeName: 'Post',
|
||||
|
||||
|
@ -22,7 +22,7 @@ const Posts = createCollection({
|
|||
|
||||
});
|
||||
|
||||
// refacto: moved here from schema.js
|
||||
// refactor: moved here from schema.js
|
||||
Posts.config = {};
|
||||
|
||||
Posts.config.STATUS_PENDING = 1;
|
||||
|
|
|
@ -11,7 +11,7 @@ const Users = createCollection({
|
|||
|
||||
collection: Meteor.users,
|
||||
|
||||
collectionName: 'users',
|
||||
collectionName: 'Users',
|
||||
|
||||
typeName: 'User',
|
||||
|
||||
|
|
|
@ -211,13 +211,17 @@ Users.helpers({
|
|||
});
|
||||
|
||||
/**
|
||||
* @summary For a given document, keep only fields viewable by current user
|
||||
* @summary For a given document or list of documents, keep only fields viewable by current user
|
||||
* @param {Object} user - The user performing the action
|
||||
* @param {Object} collection - The collection
|
||||
* @param {Object} document - The document being returned by the resolver
|
||||
*/
|
||||
Users.keepViewableFields = function (user, collection, document) {
|
||||
return document && document._id && _.pick(document, _.keys(Users.getViewableFields(user, collection, document)));
|
||||
Users.restrictViewableFields = function (user, collection, docOrDocs) {
|
||||
|
||||
const restrictDoc = document => _.pick(document, _.keys(Users.getViewableFields(user, collection, document)));
|
||||
|
||||
return Array.isArray(docOrDocs) ? docOrDocs.map(restrictDoc) : restrictDoc(docOrDocs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,7 @@ const resolvers = {
|
|||
const selector = documentId ? {_id: documentId} : {'slug': slug};
|
||||
// get the user first so we can get a list of viewable fields specific to this user document
|
||||
const user = context.Users.findOne(selector);
|
||||
return context.Users.keepViewableFields(context.currentUser, context.Users, user);
|
||||
return context.Users.restrictViewableFields(context.currentUser, context.Users, user);
|
||||
},
|
||||
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue