2014-06-03 14:05:25 +01:00
|
|
|
// # Users API
|
|
|
|
// RESTful API for the User resource
|
2014-08-17 06:17:23 +00:00
|
|
|
var Promise = require('bluebird'),
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
_ = require('lodash'),
|
|
|
|
dataProvider = require('../models'),
|
|
|
|
canThis = require('../permissions').canThis,
|
|
|
|
errors = require('../errors'),
|
|
|
|
utils = require('./utils'),
|
2015-06-22 21:11:35 +01:00
|
|
|
pipeline = require('../utils/pipeline'),
|
2015-11-12 13:29:45 +01:00
|
|
|
i18n = require('../i18n'),
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
docName = 'users',
|
2014-07-08 18:00:59 +02:00
|
|
|
// TODO: implement created_by, updated_by
|
2015-11-20 12:04:49 +00:00
|
|
|
allowedIncludes = ['count.posts', 'permissions', 'roles', 'roles.permissions'],
|
2016-09-21 16:48:14 +02:00
|
|
|
users;
|
2014-07-31 01:15:34 +01:00
|
|
|
|
2014-06-03 14:05:25 +01:00
|
|
|
/**
|
2015-06-22 21:11:35 +01:00
|
|
|
* ### Users API Methods
|
2014-06-03 14:05:25 +01:00
|
|
|
*
|
|
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
|
|
*/
|
2013-12-06 09:51:35 +01:00
|
|
|
users = {
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
/**
|
|
|
|
* ## Browse
|
|
|
|
* Fetch all users
|
2014-06-03 14:05:25 +01:00
|
|
|
* @param {{context}} options (optional)
|
2015-06-22 21:11:35 +01:00
|
|
|
* @returns {Promise<Users>} Users Collection
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
*/
|
2013-12-06 09:51:35 +01:00
|
|
|
browse: function browse(options) {
|
2015-10-24 21:39:47 +01:00
|
|
|
var extraOptions = ['status'],
|
2015-07-01 19:17:56 +01:00
|
|
|
permittedOptions = utils.browseDefaultOptions.concat(extraOptions),
|
|
|
|
tasks;
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Model Query
|
|
|
|
* Make the call to the Model layer
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function doQuery(options) {
|
2014-07-20 12:42:03 -04:00
|
|
|
return dataProvider.User.findPage(options);
|
2015-06-22 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push all of our tasks into a `tasks` array in the correct order
|
2015-07-01 19:17:56 +01:00
|
|
|
tasks = [
|
|
|
|
utils.validate(docName, {opts: permittedOptions}),
|
2015-06-27 19:09:25 +01:00
|
|
|
utils.handlePublicPermissions(docName, 'browse'),
|
2015-07-01 19:17:56 +01:00
|
|
|
utils.convertOptions(allowedIncludes),
|
|
|
|
doQuery
|
|
|
|
];
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
// Pipeline calls each task passing the result of one to be the arguments for the next
|
|
|
|
return pipeline(tasks, options);
|
2013-12-06 09:51:35 +01:00
|
|
|
},
|
|
|
|
|
2014-06-03 14:05:25 +01:00
|
|
|
/**
|
2015-06-22 21:11:35 +01:00
|
|
|
* ## Read
|
2014-06-03 14:05:25 +01:00
|
|
|
* @param {{id, context}} options
|
2015-06-22 21:11:35 +01:00
|
|
|
* @returns {Promise<Users>} User
|
2014-06-03 14:05:25 +01:00
|
|
|
*/
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
read: function read(options) {
|
2015-07-01 19:17:56 +01:00
|
|
|
var attrs = ['id', 'slug', 'status', 'email', 'role'],
|
2015-06-22 21:11:35 +01:00
|
|
|
tasks;
|
|
|
|
|
2015-06-27 19:09:25 +01:00
|
|
|
// Special handling for id = 'me'
|
|
|
|
if (options.id === 'me' && options.context && options.context.user) {
|
|
|
|
options.id = options.context.user;
|
2014-07-08 18:00:59 +02:00
|
|
|
}
|
|
|
|
|
2015-06-22 21:11:35 +01:00
|
|
|
/**
|
|
|
|
* ### Model Query
|
|
|
|
* Make the call to the Model layer
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function doQuery(options) {
|
|
|
|
return dataProvider.User.findOne(options.data, _.omit(options, ['data']));
|
2013-12-06 09:51:35 +01:00
|
|
|
}
|
|
|
|
|
2015-06-22 21:11:35 +01:00
|
|
|
// Push all of our tasks into a `tasks` array in the correct order
|
2015-07-01 19:17:56 +01:00
|
|
|
tasks = [
|
|
|
|
utils.validate(docName, {attrs: attrs}),
|
2015-06-27 19:09:25 +01:00
|
|
|
utils.handlePublicPermissions(docName, 'read'),
|
2015-07-01 19:17:56 +01:00
|
|
|
utils.convertOptions(allowedIncludes),
|
|
|
|
doQuery
|
|
|
|
];
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
// Pipeline calls each task passing the result of one to be the arguments for the next
|
|
|
|
return pipeline(tasks, options).then(function formatResponse(result) {
|
2013-12-06 09:51:35 +01:00
|
|
|
if (result) {
|
2015-04-17 22:27:04 +01:00
|
|
|
return {users: [result.toJSON(options)]};
|
2013-12-06 09:51:35 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 13:29:45 +01:00
|
|
|
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.users.userNotFound')));
|
2013-12-06 09:51:35 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-06-03 14:05:25 +01:00
|
|
|
/**
|
2015-06-22 21:11:35 +01:00
|
|
|
* ## Edit
|
2014-06-03 14:05:25 +01:00
|
|
|
* @param {User} object the user details to edit
|
|
|
|
* @param {{id, context}} options
|
2015-06-22 21:11:35 +01:00
|
|
|
* @returns {Promise<User>}
|
2014-06-03 14:05:25 +01:00
|
|
|
*/
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
edit: function edit(object, options) {
|
2015-07-01 19:17:56 +01:00
|
|
|
var extraOptions = ['editRoles'],
|
|
|
|
permittedOptions = extraOptions.concat(utils.idDefaultOptions),
|
|
|
|
tasks;
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
|
2015-07-01 19:17:56 +01:00
|
|
|
if (object.users && object.users[0] && object.users[0].roles && object.users[0].roles[0]) {
|
|
|
|
options.editRoles = true;
|
2014-07-24 10:46:05 +01:00
|
|
|
}
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 13:41:19 +01:00
|
|
|
|
2015-09-23 19:44:38 +01:00
|
|
|
// The password should never be set via this endpoint, if it is passed, ignore it
|
|
|
|
if (object.users && object.users[0] && object.users[0].password) {
|
|
|
|
delete object.users[0].password;
|
|
|
|
}
|
|
|
|
|
2015-06-22 21:11:35 +01:00
|
|
|
/**
|
|
|
|
* ### Handle Permissions
|
|
|
|
* We need to be an authorised user to perform this action
|
|
|
|
* Edit user allows the related role object to be updated as well, with some rules:
|
|
|
|
* - No change permitted to the role of the owner
|
|
|
|
* - no change permitted to the role of the context user (user making the request)
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function handlePermissions(options) {
|
|
|
|
if (options.id === 'me' && options.context && options.context.user) {
|
|
|
|
options.id = options.context.user;
|
|
|
|
}
|
2014-07-08 18:00:59 +02:00
|
|
|
|
2014-07-24 10:46:05 +01:00
|
|
|
return canThis(options.context).edit.user(options.id).then(function () {
|
2015-01-20 19:21:50 +00:00
|
|
|
// if roles aren't in the payload, proceed with the edit
|
2015-06-22 21:11:35 +01:00
|
|
|
if (!(options.data.users[0].roles && options.data.users[0].roles[0])) {
|
|
|
|
return options;
|
2015-01-20 19:21:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 21:11:35 +01:00
|
|
|
// @TODO move role permissions out of here
|
|
|
|
var role = options.data.users[0].roles[0],
|
2015-01-20 19:21:50 +00:00
|
|
|
roleId = parseInt(role.id || role, 10),
|
|
|
|
editedUserId = parseInt(options.id, 10);
|
|
|
|
|
|
|
|
return dataProvider.User.findOne(
|
|
|
|
{id: options.context.user, status: 'all'}, {include: ['roles']}
|
|
|
|
).then(function (contextUser) {
|
2015-04-17 22:27:04 +01:00
|
|
|
var contextRoleId = contextUser.related('roles').toJSON(options)[0].id;
|
2015-01-20 19:21:50 +00:00
|
|
|
|
|
|
|
if (roleId !== contextRoleId && editedUserId === contextUser.id) {
|
2015-11-12 13:29:45 +01:00
|
|
|
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.users.cannotChangeOwnRole')));
|
2015-01-20 19:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dataProvider.User.findOne({role: 'Owner'}).then(function (owner) {
|
|
|
|
if (contextUser.id !== owner.id) {
|
|
|
|
if (editedUserId === owner.id) {
|
|
|
|
if (owner.related('roles').at(0).id !== roleId) {
|
2015-11-12 13:29:45 +01:00
|
|
|
return Promise.reject(new errors.NoPermissionError(i18n.t('errors.api.users.cannotChangeOwnersRole')));
|
2014-08-13 12:12:50 -07:00
|
|
|
}
|
2015-01-20 19:21:50 +00:00
|
|
|
} else if (roleId !== contextRoleId) {
|
|
|
|
return canThis(options.context).assign.role(role).then(function () {
|
2015-06-22 21:11:35 +01:00
|
|
|
return options;
|
2015-01-20 19:21:50 +00:00
|
|
|
});
|
|
|
|
}
|
2014-07-31 01:15:34 +01:00
|
|
|
}
|
|
|
|
|
2015-06-22 21:11:35 +01:00
|
|
|
return options;
|
2014-07-24 10:46:05 +01:00
|
|
|
});
|
2015-01-20 19:21:50 +00:00
|
|
|
});
|
2015-06-22 21:11:35 +01:00
|
|
|
}).catch(function handleError(error) {
|
2015-11-12 13:29:45 +01:00
|
|
|
return errors.formatAndRejectAPIError(error, i18n.t('errors.api.users.noPermissionToEditUser'));
|
2014-06-20 11:15:01 +02:00
|
|
|
});
|
2015-06-22 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Model Query
|
|
|
|
* Make the call to the Model layer
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function doQuery(options) {
|
|
|
|
return dataProvider.User.edit(options.data.users[0], _.omit(options, ['data']));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push all of our tasks into a `tasks` array in the correct order
|
2015-07-01 19:17:56 +01:00
|
|
|
tasks = [
|
|
|
|
utils.validate(docName, {opts: permittedOptions}),
|
|
|
|
handlePermissions,
|
|
|
|
utils.convertOptions(allowedIncludes),
|
|
|
|
doQuery
|
|
|
|
];
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
return pipeline(tasks, object, options).then(function formatResponse(result) {
|
|
|
|
if (result) {
|
|
|
|
return {users: [result.toJSON(options)]};
|
|
|
|
}
|
|
|
|
|
2015-11-12 13:29:45 +01:00
|
|
|
return Promise.reject(new errors.NotFoundError(i18n.t('errors.api.users.userNotFound')));
|
2014-06-20 11:15:01 +02:00
|
|
|
});
|
|
|
|
},
|
2014-04-03 15:03:09 +02:00
|
|
|
|
2014-07-24 10:46:05 +01:00
|
|
|
/**
|
2015-06-22 21:11:35 +01:00
|
|
|
* ## Destroy
|
2014-07-24 10:46:05 +01:00
|
|
|
* @param {{id, context}} options
|
2016-03-20 12:26:42 -05:00
|
|
|
* @returns {Promise}
|
2014-07-24 10:46:05 +01:00
|
|
|
*/
|
|
|
|
destroy: function destroy(options) {
|
2015-06-22 21:11:35 +01:00
|
|
|
var tasks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Handle Permissions
|
|
|
|
* We need to be an authorised user to perform this action
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function handlePermissions(options) {
|
|
|
|
return canThis(options.context).destroy.user(options.id).then(function permissionGranted() {
|
|
|
|
options.status = 'all';
|
|
|
|
return options;
|
|
|
|
}).catch(function handleError(error) {
|
2015-11-12 13:29:45 +01:00
|
|
|
return errors.formatAndRejectAPIError(error, i18n.t('errors.api.users.noPermissionToDestroyUser'));
|
2015-06-22 21:11:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-03-20 12:26:42 -05:00
|
|
|
* ### Delete User
|
2015-06-22 21:11:35 +01:00
|
|
|
* Make the call to the Model layer
|
|
|
|
* @param {Object} options
|
|
|
|
*/
|
2016-03-20 12:26:42 -05:00
|
|
|
function deleteUser(options) {
|
|
|
|
return dataProvider.Base.transaction(function (t) {
|
|
|
|
options.transacting = t;
|
|
|
|
|
|
|
|
return Promise.all([
|
|
|
|
dataProvider.Accesstoken.destroyByUser(options),
|
|
|
|
dataProvider.Refreshtoken.destroyByUser(options),
|
|
|
|
dataProvider.Post.destroyByAuthor(options)
|
|
|
|
]).then(function () {
|
|
|
|
return dataProvider.User.destroy(options);
|
|
|
|
}).return(null);
|
|
|
|
}).catch(function (error) {
|
2015-10-22 15:28:47 +02:00
|
|
|
return errors.formatAndRejectAPIError(error);
|
2014-07-24 10:46:05 +01:00
|
|
|
});
|
2015-06-22 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push all of our tasks into a `tasks` array in the correct order
|
2015-07-01 19:17:56 +01:00
|
|
|
tasks = [
|
|
|
|
utils.validate(docName, {opts: utils.idDefaultOptions}),
|
|
|
|
handlePermissions,
|
|
|
|
utils.convertOptions(allowedIncludes),
|
2016-03-20 12:26:42 -05:00
|
|
|
deleteUser
|
2015-07-01 19:17:56 +01:00
|
|
|
];
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
// Pipeline calls each task passing the result of one to be the arguments for the next
|
|
|
|
return pipeline(tasks, options);
|
2014-07-24 10:46:05 +01:00
|
|
|
},
|
|
|
|
|
2014-06-20 11:15:01 +02:00
|
|
|
/**
|
2015-06-22 21:11:35 +01:00
|
|
|
* ## Change Password
|
2014-07-08 23:28:31 +01:00
|
|
|
* @param {password} object
|
2014-06-20 11:15:01 +02:00
|
|
|
* @param {{context}} options
|
2015-06-22 21:11:35 +01:00
|
|
|
* @returns {Promise<password>} success message
|
2014-06-20 11:15:01 +02:00
|
|
|
*/
|
|
|
|
changePassword: function changePassword(object, options) {
|
2015-06-22 21:11:35 +01:00
|
|
|
var tasks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Handle Permissions
|
|
|
|
* We need to be an authorised user to perform this action
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function handlePermissions(options) {
|
2015-07-07 15:32:50 +02:00
|
|
|
return canThis(options.context).edit.user(options.data.password[0].user_id).then(function permissionGranted() {
|
2015-06-22 21:11:35 +01:00
|
|
|
return options;
|
|
|
|
}).catch(function (error) {
|
2015-11-12 13:29:45 +01:00
|
|
|
return errors.formatAndRejectAPIError(error, i18n.t('errors.api.users.noPermissionToChangeUsersPwd'));
|
2015-06-22 21:11:35 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Model Query
|
|
|
|
* Make the call to the Model layer
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function doQuery(options) {
|
|
|
|
return dataProvider.User.changePassword(
|
2015-07-07 15:32:50 +02:00
|
|
|
options.data.password[0],
|
2015-06-22 21:11:35 +01:00
|
|
|
_.omit(options, ['data'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push all of our tasks into a `tasks` array in the correct order
|
2015-07-01 19:17:56 +01:00
|
|
|
tasks = [
|
|
|
|
utils.validate('password'),
|
|
|
|
handlePermissions,
|
|
|
|
utils.convertOptions(allowedIncludes),
|
|
|
|
doQuery
|
|
|
|
];
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
// Pipeline calls each task passing the result of one to be the arguments for the next
|
|
|
|
return pipeline(tasks, object, options).then(function formatResponse() {
|
2015-11-12 13:29:45 +01:00
|
|
|
return Promise.resolve({password: [{message: i18n.t('notices.api.users.pwdChangedSuccessfully')}]});
|
2014-06-20 11:15:01 +02:00
|
|
|
});
|
2014-07-30 17:40:30 +02:00
|
|
|
},
|
2013-12-06 09:51:35 +01:00
|
|
|
|
2014-07-30 17:40:30 +02:00
|
|
|
/**
|
2015-06-22 21:11:35 +01:00
|
|
|
* ## Transfer Ownership
|
|
|
|
* @param {owner} object
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Promise<User>}
|
2014-07-30 17:40:30 +02:00
|
|
|
*/
|
|
|
|
transferOwnership: function transferOwnership(object, options) {
|
2015-06-22 21:11:35 +01:00
|
|
|
var tasks;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Handle Permissions
|
|
|
|
* We need to be an authorised user to perform this action
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function handlePermissions(options) {
|
|
|
|
return dataProvider.Role.findOne({name: 'Owner'}).then(function (ownerRole) {
|
|
|
|
return canThis(options.context).assign.role(ownerRole);
|
|
|
|
}).then(function () {
|
|
|
|
return options;
|
|
|
|
}).catch(function (error) {
|
2015-10-22 15:28:47 +02:00
|
|
|
return errors.formatAndRejectAPIError(error);
|
2014-07-30 17:40:30 +02:00
|
|
|
});
|
2015-06-22 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ### Model Query
|
|
|
|
* Make the call to the Model layer
|
|
|
|
* @param {Object} options
|
|
|
|
* @returns {Object} options
|
|
|
|
*/
|
|
|
|
function doQuery(options) {
|
|
|
|
return dataProvider.User.transferOwnership(options.data.owner[0], _.omit(options, ['data']));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push all of our tasks into a `tasks` array in the correct order
|
2015-07-01 19:17:56 +01:00
|
|
|
tasks = [
|
|
|
|
utils.validate('owner'),
|
|
|
|
handlePermissions,
|
|
|
|
utils.convertOptions(allowedIncludes),
|
|
|
|
doQuery
|
|
|
|
];
|
2015-06-22 21:11:35 +01:00
|
|
|
|
|
|
|
// Pipeline calls each task passing the result of one to be the arguments for the next
|
|
|
|
return pipeline(tasks, object, options).then(function formatResult(result) {
|
|
|
|
return Promise.resolve({users: result});
|
2014-07-30 17:40:30 +02:00
|
|
|
}).catch(function (error) {
|
2015-10-22 15:28:47 +02:00
|
|
|
return errors.formatAndRejectAPIError(error);
|
2014-07-30 17:40:30 +02:00
|
|
|
});
|
|
|
|
}
|
2013-12-06 09:51:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = users;
|