mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
parent
4b6f8ce06d
commit
57a5b6a188
11 changed files with 223 additions and 33 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
// # DB API
|
||||||
|
// API for DB operations
|
||||||
var dataExport = require('../data/export'),
|
var dataExport = require('../data/export'),
|
||||||
dataImport = require('../data/import'),
|
dataImport = require('../data/import'),
|
||||||
dataProvider = require('../models'),
|
dataProvider = require('../models'),
|
||||||
|
@ -11,10 +13,22 @@ var dataExport = require('../data/export'),
|
||||||
api = {},
|
api = {},
|
||||||
db;
|
db;
|
||||||
|
|
||||||
api.notifications = require('./notifications');
|
|
||||||
api.settings = require('./settings');
|
api.settings = require('./settings');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ## DB API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
db = {
|
db = {
|
||||||
|
/**
|
||||||
|
* ### Export Content
|
||||||
|
* Generate the JSON to export
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise} Ghost Export JSON format
|
||||||
|
*/
|
||||||
'exportContent': function (options) {
|
'exportContent': function (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
@ -29,6 +43,14 @@ db = {
|
||||||
return when.reject(new errors.NoPermissionError('You do not have permission to export data. (no rights)'));
|
return when.reject(new errors.NoPermissionError('You do not have permission to export data. (no rights)'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* ### Import Content
|
||||||
|
* Import posts, tags etc from a JSON blob
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise} Success
|
||||||
|
*/
|
||||||
'importContent': function (options) {
|
'importContent': function (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var databaseVersion;
|
var databaseVersion;
|
||||||
|
@ -108,6 +130,14 @@ db = {
|
||||||
return when.reject(new errors.NoPermissionError('You do not have permission to export data. (no rights)'));
|
return when.reject(new errors.NoPermissionError('You do not have permission to export data. (no rights)'));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* ### Delete All Content
|
||||||
|
* Remove all posts and tags
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise} Success
|
||||||
|
*/
|
||||||
'deleteAllContent': function (options) {
|
'deleteAllContent': function (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// # Ghost Data API
|
// # Ghost Data API
|
||||||
// Provides access to the data model
|
// Provides access from anywhere to the Ghost data layer.
|
||||||
|
//
|
||||||
|
// Ghost's JSON API is integral to the workings of Ghost, regardless of whether you want to access data internally,
|
||||||
|
// from a theme, an app, or from an external app, you'll use the Ghost JSON API to do so.
|
||||||
|
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
|
@ -251,3 +254,22 @@ module.exports = {
|
||||||
users: users,
|
users: users,
|
||||||
slugs: slugs
|
slugs: slugs
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ## API Methods
|
||||||
|
*
|
||||||
|
* Most API methods follow the BREAD pattern, although not all BREAD methods are available for all resources.
|
||||||
|
* Most API methods have a similar signature, they either take just `options`, or both `object` and `options`.
|
||||||
|
* For RESTful resources `object` is always a model object of the correct type in the form `name: [{object}]`
|
||||||
|
* `options` is an object with several named properties, the possibilities are listed for each method.
|
||||||
|
*
|
||||||
|
* Read / Edit / Destroy routes expect some sort of identifier (id / slug / key) for which object they are handling
|
||||||
|
*
|
||||||
|
* All API methods take a context object as one of the options:
|
||||||
|
*
|
||||||
|
* @typedef context
|
||||||
|
* Context provides information for determining permissions. Usually a user, but sometimes an app, or the internal flag
|
||||||
|
* @param {Number} user (optional)
|
||||||
|
* @param {String} app (optional)
|
||||||
|
* @param {Boolean} internal (optional)
|
||||||
|
*/
|
||||||
|
|
|
@ -1,33 +1,51 @@
|
||||||
|
// # Mail API
|
||||||
|
// API for sending Mail
|
||||||
var when = require("when"),
|
var when = require("when"),
|
||||||
config = require('../config'),
|
config = require('../config'),
|
||||||
errors = require('../errors'),
|
errors = require('../errors'),
|
||||||
mail;
|
mail;
|
||||||
|
|
||||||
// ## Mail
|
/**
|
||||||
|
* ## Mail API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
* @typedef Mail
|
||||||
|
* @param mail
|
||||||
|
*/
|
||||||
mail = {
|
mail = {
|
||||||
|
/**
|
||||||
// #### Send
|
* ### Send
|
||||||
// **takes:** a json object representing an email.
|
* Send an email
|
||||||
send: function (postData) {
|
*
|
||||||
|
* @public
|
||||||
|
* @param {Mail} object details of the email to send
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
send: function (object) {
|
||||||
var mailer = require('../mail');
|
var mailer = require('../mail');
|
||||||
|
|
||||||
// **returns:** a promise from the mailer with the number of successfully sent emails
|
// TODO: permissions
|
||||||
return mailer.send(postData.mail[0].message)
|
return mailer.send(object.mail[0].message)
|
||||||
.then(function (data) {
|
.then(function (data) {
|
||||||
delete postData.mail[0].options;
|
delete object.mail[0].options;
|
||||||
// Sendmail returns extra details we don't need and that don't convert to JSON
|
// Sendmail returns extra details we don't need and that don't convert to JSON
|
||||||
delete postData.mail[0].message.transport;
|
delete object.mail[0].message.transport;
|
||||||
postData.mail[0].status = {
|
object.mail[0].status = {
|
||||||
message: data.message
|
message: data.message
|
||||||
};
|
};
|
||||||
return postData;
|
return object;
|
||||||
})
|
})
|
||||||
.otherwise(function (error) {
|
.otherwise(function (error) {
|
||||||
return when.reject(new errors.EmailError(error.message));
|
return when.reject(new errors.EmailError(error.message));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// #### SendTest
|
/**
|
||||||
// **takes:** nothing
|
* ### SendTest
|
||||||
|
* Send a test email
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
sendTest: function () {
|
sendTest: function () {
|
||||||
var html = '<p><strong>Hello there!</strong></p>' +
|
var html = '<p><strong>Hello there!</strong></p>' +
|
||||||
'<p>Excellent!' +
|
'<p>Excellent!' +
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// # Notifications API
|
||||||
|
// RESTful API for creating notifications
|
||||||
var when = require('when'),
|
var when = require('when'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
errors = require('../errors'),
|
errors = require('../errors'),
|
||||||
|
@ -8,13 +10,29 @@ var when = require('when'),
|
||||||
notificationCounter = 0,
|
notificationCounter = 0,
|
||||||
notifications;
|
notifications;
|
||||||
|
|
||||||
// ## Notifications
|
/**
|
||||||
|
* ## Notification API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
notifications = {
|
notifications = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### Browse
|
||||||
|
* Fetch all notifications
|
||||||
|
* @returns {Promise(Notifications)}
|
||||||
|
*/
|
||||||
browse: function browse() {
|
browse: function browse() {
|
||||||
return when({ 'notifications': notificationsStore });
|
return when({ 'notifications': notificationsStore });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### Destroy
|
||||||
|
* Remove a specific notification
|
||||||
|
*
|
||||||
|
* @param {{id (required), context}} options
|
||||||
|
* @returns {Promise(Notifications)}
|
||||||
|
*/
|
||||||
destroy: function destroy(options) {
|
destroy: function destroy(options) {
|
||||||
var notification = _.find(notificationsStore, function (element) {
|
var notification = _.find(notificationsStore, function (element) {
|
||||||
return element.id === parseInt(options.id, 10);
|
return element.id === parseInt(options.id, 10);
|
||||||
|
@ -33,10 +51,16 @@ notifications = {
|
||||||
notificationsStore = _.reject(notificationsStore, function (element) {
|
notificationsStore = _.reject(notificationsStore, function (element) {
|
||||||
return element.id === parseInt(options.id, 10);
|
return element.id === parseInt(options.id, 10);
|
||||||
});
|
});
|
||||||
// **returns:** a promise for the deleted object
|
|
||||||
return when({notifications: [notification]});
|
return when({notifications: [notification]});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### DestroyAll
|
||||||
|
* Clear all notifications, used for tests
|
||||||
|
*
|
||||||
|
* @private Not exposed over HTTP
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
destroyAll: function destroyAll() {
|
destroyAll: function destroyAll() {
|
||||||
notificationsStore = [];
|
notificationsStore = [];
|
||||||
notificationCounter = 0;
|
notificationCounter = 0;
|
||||||
|
@ -73,7 +97,6 @@ notifications = {
|
||||||
});
|
});
|
||||||
|
|
||||||
notificationsStore.push(notification);
|
notificationsStore.push(notification);
|
||||||
// **returns:** a promise of the new notification object
|
|
||||||
return when({ notifications: [notification]});
|
return when({ notifications: [notification]});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// # Posts API
|
// # Posts API
|
||||||
|
// RESTful API for the Post resource
|
||||||
var when = require('when'),
|
var when = require('when'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
dataProvider = require('../models'),
|
dataProvider = require('../models'),
|
||||||
|
@ -24,19 +25,31 @@ function prepareInclude(include) {
|
||||||
return include;
|
return include;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ## API Methods
|
/**
|
||||||
|
* ## Posts API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
posts = {
|
posts = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ### Browse
|
* ### Browse
|
||||||
* Find a paginated set of posts
|
* Find a paginated set of posts
|
||||||
|
*
|
||||||
|
* Will only return published posts unless we have an authenticated user and an alternative status
|
||||||
|
* parameter.
|
||||||
|
*
|
||||||
|
* Will return without static pages unless told otherwise
|
||||||
|
*
|
||||||
|
* Can return posts for a particular tag by passing a tag slug in
|
||||||
|
*
|
||||||
|
* @public
|
||||||
* @param {{context, page, limit, status, staticPages, tag}} options (optional)
|
* @param {{context, page, limit, status, staticPages, tag}} options (optional)
|
||||||
* @returns {Promise(Posts)} Posts Collection with Meta
|
* @returns {Promise(Posts)} Posts Collection with Meta
|
||||||
*/
|
*/
|
||||||
browse: function browse(options) {
|
browse: function browse(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
// only published posts if no user is present
|
|
||||||
if (!(options.context && options.context.user)) {
|
if (!(options.context && options.context.user)) {
|
||||||
options.status = 'published';
|
options.status = 'published';
|
||||||
}
|
}
|
||||||
|
@ -51,6 +64,8 @@ posts = {
|
||||||
/**
|
/**
|
||||||
* ### Read
|
* ### Read
|
||||||
* Find a post, by ID or Slug
|
* Find a post, by ID or Slug
|
||||||
|
*
|
||||||
|
* @public
|
||||||
* @param {{id_or_slug (required), context, status, include, ...}} options
|
* @param {{id_or_slug (required), context, status, include, ...}} options
|
||||||
* @return {Promise(Post)} Post
|
* @return {Promise(Post)} Post
|
||||||
*/
|
*/
|
||||||
|
@ -81,6 +96,8 @@ posts = {
|
||||||
/**
|
/**
|
||||||
* ### Edit
|
* ### Edit
|
||||||
* Update properties of a post
|
* Update properties of a post
|
||||||
|
*
|
||||||
|
* @public
|
||||||
* @param {Post} object Post or specific properties to update
|
* @param {Post} object Post or specific properties to update
|
||||||
* @param {{id (required), context, include,...}} options
|
* @param {{id (required), context, include,...}} options
|
||||||
* @return {Promise(Post)} Edited Post
|
* @return {Promise(Post)} Edited Post
|
||||||
|
@ -114,6 +131,8 @@ posts = {
|
||||||
/**
|
/**
|
||||||
* ### Add
|
* ### Add
|
||||||
* Create a new post along with any tags
|
* Create a new post along with any tags
|
||||||
|
*
|
||||||
|
* @public
|
||||||
* @param {Post} object
|
* @param {Post} object
|
||||||
* @param {{context, include,...}} options
|
* @param {{context, include,...}} options
|
||||||
* @return {Promise(Post)} Created Post
|
* @return {Promise(Post)} Created Post
|
||||||
|
@ -146,6 +165,8 @@ posts = {
|
||||||
/**
|
/**
|
||||||
* ### Destroy
|
* ### Destroy
|
||||||
* Delete a post, cleans up tag relations, but not unused tags
|
* Delete a post, cleans up tag relations, but not unused tags
|
||||||
|
*
|
||||||
|
* @public
|
||||||
* @param {{id (required), context,...}} options
|
* @param {{id (required), context,...}} options
|
||||||
* @return {Promise(Post)} Deleted Post
|
* @return {Promise(Post)} Deleted Post
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// # Settings API
|
// # Settings API
|
||||||
|
// RESTful API for the Setting resource
|
||||||
var _ = require('lodash'),
|
var _ = require('lodash'),
|
||||||
dataProvider = require('../models'),
|
dataProvider = require('../models'),
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
|
@ -209,7 +210,11 @@ canEditAllSettings = function (settingsInfo, options) {
|
||||||
return when.all(checks);
|
return when.all(checks);
|
||||||
};
|
};
|
||||||
|
|
||||||
// ## API Methods
|
/**
|
||||||
|
* ## Settings API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
settings = {
|
settings = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,26 +1,32 @@
|
||||||
|
// # Slug API
|
||||||
|
// RESTful API for the Slug resource
|
||||||
var canThis = require('../permissions').canThis,
|
var canThis = require('../permissions').canThis,
|
||||||
dataProvider = require('../models'),
|
dataProvider = require('../models'),
|
||||||
errors = require('../errors'),
|
errors = require('../errors'),
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
|
|
||||||
slugs,
|
slugs,
|
||||||
// `allowedTypes` is used to define allowed slug types and map them against it's model class counterpart
|
// `allowedTypes` is used to define allowed slug types and map them against its model class counterpart
|
||||||
allowedTypes = {
|
allowedTypes = {
|
||||||
post: dataProvider.Post,
|
post: dataProvider.Post,
|
||||||
tag: dataProvider.Tag
|
tag: dataProvider.Tag
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Generate Slug
|
* ## Slugs API Methods
|
||||||
* Create a unique slug for a given post title
|
*
|
||||||
* @param {{type (required), context}} options
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
* @param {{title (required), transacting}} options
|
|
||||||
* @returns {Promise(String)} Unique string
|
|
||||||
*/
|
*/
|
||||||
slugs = {
|
slugs = {
|
||||||
|
|
||||||
// #### Generate slug
|
/**
|
||||||
// **takes:** a string to generate the slug from
|
* ## Generate Slug
|
||||||
|
* Create a unique slug for a given post title
|
||||||
|
* TODO: make it generic for all objects: post, tag, user
|
||||||
|
*
|
||||||
|
* @param {{type (required), title (required), context, transacting}} options
|
||||||
|
* @returns {Promise(String)} Unique string
|
||||||
|
*/
|
||||||
generate: function (options) {
|
generate: function (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
|
// # Tag API
|
||||||
|
// RESTful API for the Tag resource
|
||||||
var dataProvider = require('../models'),
|
var dataProvider = require('../models'),
|
||||||
tags;
|
tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ## Tags API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
tags = {
|
tags = {
|
||||||
|
/**
|
||||||
|
* ### Browse
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise(Tags)}
|
||||||
|
*/
|
||||||
browse: function browse(options) {
|
browse: function browse(options) {
|
||||||
return dataProvider.Tag.findAll(options).then(function (result) {
|
return dataProvider.Tag.findAll(options).then(function (result) {
|
||||||
return { tags: result.toJSON() };
|
return { tags: result.toJSON() };
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// # Themes API
|
||||||
|
// RESTful API for Themes
|
||||||
var when = require('when'),
|
var when = require('when'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
canThis = require('../permissions').canThis,
|
canThis = require('../permissions').canThis,
|
||||||
|
@ -7,9 +9,18 @@ var when = require('when'),
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
themes;
|
themes;
|
||||||
|
|
||||||
// ## Themes
|
/**
|
||||||
|
* ## Themes API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
themes = {
|
themes = {
|
||||||
|
/**
|
||||||
|
* ### Browse
|
||||||
|
* Get a list of all the available themes
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise(Themes)}
|
||||||
|
*/
|
||||||
browse: function browse(options) {
|
browse: function browse(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
@ -50,6 +61,13 @@ themes = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### Edit
|
||||||
|
* Change the active theme
|
||||||
|
* @param {Theme} object
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise(Theme)}
|
||||||
|
*/
|
||||||
edit: function edit(object, options) {
|
edit: function edit(object, options) {
|
||||||
var themeName;
|
var themeName;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// # Users API
|
||||||
|
// RESTful API for the User resource
|
||||||
var when = require('when'),
|
var when = require('when'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
dataProvider = require('../models'),
|
dataProvider = require('../models'),
|
||||||
|
@ -10,12 +12,18 @@ var when = require('when'),
|
||||||
ONE_DAY = 86400000,
|
ONE_DAY = 86400000,
|
||||||
users;
|
users;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ## Posts API Methods
|
||||||
|
*
|
||||||
|
* **See:** [API Methods](index.js.html#api%20methods)
|
||||||
|
*/
|
||||||
users = {
|
users = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ## Browse
|
* ## Browse
|
||||||
* Fetch all users
|
* Fetch all users
|
||||||
* @param {object} options (optional)
|
* @param {{context}} options (optional)
|
||||||
* @returns {Promise(Users)} Users Collection
|
* @returns {Promise(Users)} Users Collection
|
||||||
*/
|
*/
|
||||||
browse: function browse(options) {
|
browse: function browse(options) {
|
||||||
|
@ -29,6 +37,11 @@ users = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### Read
|
||||||
|
* @param {{id, context}} options
|
||||||
|
* @returns {Promise(User)} User
|
||||||
|
*/
|
||||||
read: function read(options) {
|
read: function read(options) {
|
||||||
var attrs = ['id'],
|
var attrs = ['id'],
|
||||||
data = _.pick(options, attrs);
|
data = _.pick(options, attrs);
|
||||||
|
@ -48,6 +61,12 @@ users = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### Edit
|
||||||
|
* @param {User} object the user details to edit
|
||||||
|
* @param {{id, context}} options
|
||||||
|
* @returns {Promise(User)}
|
||||||
|
*/
|
||||||
edit: function edit(object, options) {
|
edit: function edit(object, options) {
|
||||||
if (options.id === 'me' && options.context && options.context.user) {
|
if (options.id === 'me' && options.context && options.context.user) {
|
||||||
options.id = options.context.user;
|
options.id = options.context.user;
|
||||||
|
@ -68,6 +87,12 @@ users = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ### Add
|
||||||
|
* @param {User} object the user to create
|
||||||
|
* @param {{context}} options
|
||||||
|
* @returns {Promise(User}} Newly created user
|
||||||
|
*/
|
||||||
add: function add(object, options) {
|
add: function add(object, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
|
@ -89,6 +114,7 @@ users = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// TODO complete documentation as part of #2822
|
||||||
register: function register(object) {
|
register: function register(object) {
|
||||||
// TODO: if we want to prevent users from being created with the signup form this is the right place to do it
|
// TODO: if we want to prevent users from being created with the signup form this is the right place to do it
|
||||||
return users.add(object, {context: {internal: true}});
|
return users.add(object, {context: {internal: true}});
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
|
// # API Utils
|
||||||
|
// Shared helpers for working with the API
|
||||||
var when = require('when'),
|
var when = require('when'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
utils;
|
utils;
|
||||||
|
|
||||||
utils = {
|
utils = {
|
||||||
|
/**
|
||||||
|
* ### Check Object
|
||||||
|
* Check an object passed to the API is in the correct format
|
||||||
|
*
|
||||||
|
* @param {Object} object
|
||||||
|
* @param {String} docName
|
||||||
|
* @returns {Promise(Object)} resolves to the original object if it checks out
|
||||||
|
*/
|
||||||
checkObject: function (object, docName) {
|
checkObject: function (object, docName) {
|
||||||
if (_.isEmpty(object) || _.isEmpty(object[docName]) || _.isEmpty(object[docName][0])) {
|
if (_.isEmpty(object) || _.isEmpty(object[docName]) || _.isEmpty(object[docName][0])) {
|
||||||
return when.reject({type: 'BadRequest', message: 'No root key (\'' + docName + '\') provided.'});
|
return when.reject({type: 'BadRequest', message: 'No root key (\'' + docName + '\') provided.'});
|
||||||
|
|
Loading…
Add table
Reference in a new issue