mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
commit
8c60de4b78
4 changed files with 133 additions and 12 deletions
|
@ -108,7 +108,7 @@ export const createMutator = async ({ collection, document, data, currentUser, v
|
|||
// }
|
||||
|
||||
// run sync callbacks
|
||||
newDocument = await runCallbacks({ name: `${typeName}.create.before`, iterator: newDocument, properties: { currentUser }});
|
||||
newDocument = await runCallbacks({ name: `${typeName.toLowerCase()}.create.before`, iterator: newDocument, properties: { currentUser }});
|
||||
newDocument = await runCallbacks({ name: `*.create.before`, iterator: newDocument, properties: { currentUser }});
|
||||
// OpenCRUD backwards compatibility
|
||||
newDocument = await runCallbacks(`${collectionName.toLowerCase()}.new.before`, newDocument, currentUser);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createMutator, updateMutator, deleteMutator, Utils, Connectors } from 'meteor/vulcan:lib';
|
||||
import { createMutator, updateMutator, deleteMutator, Utils, Connectors, registerCallback } from 'meteor/vulcan:lib';
|
||||
import Users from './collection'; // TODO: circular dependency?
|
||||
|
||||
const performCheck = (mutation, user, document) => {
|
||||
|
@ -19,7 +19,7 @@ const createMutation = {
|
|||
|
||||
mutation(root, { data }, context) {
|
||||
const { Users, currentUser } = context;
|
||||
performCheck(this, currentUser, document);
|
||||
performCheck(this, currentUser, data);
|
||||
|
||||
return createMutator({
|
||||
collection: Users,
|
||||
|
@ -95,3 +95,121 @@ const mutations = {
|
|||
};
|
||||
|
||||
export default mutations;
|
||||
|
||||
registerCallback({
|
||||
name:'user.create.validate',
|
||||
iterator: {document:'the document being inserted'},
|
||||
properties: [
|
||||
{ document: 'The document being inserted' },
|
||||
{ currentUser: 'The current user' },
|
||||
{ validationErrors: 'An object that can be used to accumulate validation errors' },
|
||||
],
|
||||
runs: 'sync',
|
||||
returns: 'document',
|
||||
description: `Validate a document before insertion (can be skipped when inserting directly on server).`,
|
||||
});
|
||||
registerCallback({
|
||||
name:'user.create.before',
|
||||
iterator: {document:'the document being inserted'},
|
||||
properties: [
|
||||
{ document: 'The document being inserted' },
|
||||
{ currentUser: 'The current user' },
|
||||
{ validationErrors: 'An object that can be used to accumulate validation errors' },
|
||||
],
|
||||
runs: 'sync',
|
||||
returns: 'document',
|
||||
description: `Perform operations on a new document before it's inserted in the database.`,
|
||||
});
|
||||
registerCallback({
|
||||
name:'user.create.after',
|
||||
iterator: {document:'the document after being inserted in the database'},
|
||||
properties: [
|
||||
{ currentUser: 'The current user' },
|
||||
],
|
||||
runs: 'sync',
|
||||
returns: 'document',
|
||||
description: `Perform operations on a new document after it's inserted in the database but *before* the mutation returns it.`,
|
||||
});
|
||||
registerCallback({
|
||||
name:'user.create.async',
|
||||
iterator: {data:'the document after being inserted in the database'},
|
||||
properties: [
|
||||
{insertedDocument: 'The document that was inserted to the collection'},
|
||||
{ currentUser: 'The current user' },
|
||||
{collection: 'The Users collection'}
|
||||
],
|
||||
runs: 'async',
|
||||
returns: 'document',
|
||||
description: `Perform operations on a new document after it's inserted in the database asynchronously.`,
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.update.validate',
|
||||
iterator: {data: 'The client data'},
|
||||
properties: [
|
||||
{document: 'The document being updated'},
|
||||
{currentUser: 'The current user.'},
|
||||
{validationErrors: 'an object that can be used to accumulate validation errors.'},
|
||||
],
|
||||
runs: 'sync',
|
||||
description: 'Validate a document before update (can be skipped when updating directly on server).'
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.update.before',
|
||||
iterator: {data:'The client data'},
|
||||
properties: [
|
||||
{document: 'The document being edited'},
|
||||
{currentUser: 'The current user'},
|
||||
{newDocument: 'A preview of the future document'},
|
||||
],
|
||||
runs: 'sync',
|
||||
description: `Perform operations on a document before it's updated on the database.`,
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.update.after',
|
||||
iterator: {newdocument: 'The document after the update'},
|
||||
properties: [
|
||||
{document: 'The document before the update'},
|
||||
{currentUser: 'The current user'},
|
||||
],
|
||||
runs: 'sync',
|
||||
description: `Perform operations on a document after it's updated in the database but *before* the mutation returns it.`
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.update.async',
|
||||
properties: [
|
||||
{newDocument: 'The document after the update'},
|
||||
{document: 'The document before the update'},
|
||||
{currentUser: 'The current user'},
|
||||
{collection: 'The Users collection'},
|
||||
],
|
||||
runs: 'async',
|
||||
description: `Perform operations on a document after it's updated in the database asynchronously.`
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.delete.validate',
|
||||
iterator: {document: 'The document being deleted'},
|
||||
properties: [
|
||||
{currentUser: 'The current user'},
|
||||
],
|
||||
runs: 'sync',
|
||||
description: `Validate a document before deletion (can be skipped when deleting directly on the server)`
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.delete.before',
|
||||
iterator: {document: 'The document being deleted'},
|
||||
properties: [
|
||||
{currentUser: 'The current user'},
|
||||
],
|
||||
runs: 'sync',
|
||||
description: `Perform operations on a document before it's deleted from the database`,
|
||||
});
|
||||
registerCallback({
|
||||
name: 'user.delete.async',
|
||||
properties:[
|
||||
{document: 'The document being deleted'},
|
||||
{currentUser: 'The current user'},
|
||||
{collection: 'The Users collection'},
|
||||
],
|
||||
runs: 'async',
|
||||
description: `Perform operations on a document after it's deleted from the database asynchronously.`
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ function onCreateUserCallback(options, user) {
|
|||
delete options.password; // we don't need to store the password digest
|
||||
delete options.username; // username is already in user object
|
||||
|
||||
options = runCallbacks(`user.new.validate.before`, options);
|
||||
options = runCallbacks({name: `user.create.validate.before`, iterator: options});
|
||||
// OpenCRUD backwards compatibility
|
||||
options = runCallbacks(`users.new.validate.before`, options);
|
||||
|
||||
|
@ -33,7 +33,7 @@ function onCreateUserCallback(options, user) {
|
|||
user = Object.assign(user, options);
|
||||
|
||||
// run validation callbacks
|
||||
user = runCallbacks(`user.new.validate`, user);
|
||||
user = runCallbacks({name:`user.create.validate`, iterator: user});
|
||||
// OpenCRUD backwards compatibility
|
||||
user = runCallbacks(`users.new.validate`, user);
|
||||
|
||||
|
@ -52,10 +52,10 @@ function onCreateUserCallback(options, user) {
|
|||
user[fieldName] = autoValue;
|
||||
}
|
||||
}
|
||||
|
||||
user = runCallbacks({ name: 'user.create.before', iterator: user });
|
||||
user = runCallbacks('users.new.sync', user);
|
||||
|
||||
runCallbacksAsync("user.new.async", user);
|
||||
runCallbacksAsync({name: "user.create.async", properties: {data: user}});
|
||||
// OpenCRUD backwards compatibility
|
||||
runCallbacksAsync("users.new.async", user);
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
if (typeof Accounts !== 'undefined') {
|
||||
Accounts.urls.resetPassword = (token) => Meteor.absoluteUrl(`reset-password/${token}`);
|
||||
Accounts.urls.enrollAccount = (token) => Meteor.absoluteUrl(`enroll-account/${token}`);
|
||||
}
|
||||
Meteor.startup(() => {
|
||||
console.log(typeof Accounts);
|
||||
if (typeof Accounts !== 'undefined') {
|
||||
Accounts.urls.resetPassword = token => Meteor.absoluteUrl(`reset-password/${token}`);
|
||||
Accounts.urls.enrollAccount = token => Meteor.absoluteUrl(`enroll-account/${token}`);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue