Merge branch 'master' into 2.0
This commit is contained in:
commit
b44dac3c62
|
@ -191,11 +191,9 @@ function tokenIdForRequest(req, options) {
|
||||||
var length;
|
var length;
|
||||||
var id;
|
var id;
|
||||||
|
|
||||||
params.push('access_token');
|
params = params.concat(['access_token']);
|
||||||
headers.push('X-Access-Token');
|
headers = headers.concat(['X-Access-Token', 'authorization']);
|
||||||
headers.push('authorization');
|
cookies = cookies.concat(['access_token', 'authorization']);
|
||||||
cookies.push('access_token');
|
|
||||||
cookies.push('authorization');
|
|
||||||
|
|
||||||
for(length = params.length; i < length; i++) {
|
for(length = params.length; i < length; i++) {
|
||||||
id = req.param(params[i]);
|
id = req.param(params[i]);
|
||||||
|
|
|
@ -189,6 +189,26 @@ PersistedModel.destroyAll = function destroyAll(where, cb) {
|
||||||
throwNotAttached(this.modelName, 'destroyAll');
|
throwNotAttached(this.modelName, 'destroyAll');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update multiple instances that match the where clause
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
*```js
|
||||||
|
* Employee.update({managerId: 'x001'}, {managerId: 'x002'}, function(err) {
|
||||||
|
* ...
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param {Object} [where] Search conditions (optional)
|
||||||
|
* @param {Object} data Changes to be made
|
||||||
|
* @param {Function} cb Callback, called with (err, count)
|
||||||
|
*/
|
||||||
|
PersistedModel.update =
|
||||||
|
PersistedModel.updateAll = function updateAll(where, data, cb) {
|
||||||
|
throwNotAttached(this.modelName, 'updateAll');
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a record by id
|
* Destroy a record by id
|
||||||
* @param {*} id The id value
|
* @param {*} id The id value
|
||||||
|
@ -461,6 +481,17 @@ PersistedModel.setupRemoting = function() {
|
||||||
shared: false
|
shared: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setRemoting(PersistedModel, 'updateAll', {
|
||||||
|
description: 'Update instances of the model matched by where from the data source',
|
||||||
|
accepts: [
|
||||||
|
{arg: 'where', type: 'object', http: {source: 'query'},
|
||||||
|
description: 'Criteria to match model instances'},
|
||||||
|
{arg: 'data', type: 'object', http: {source: 'body'},
|
||||||
|
description: 'An object of model property name/value pairs'},
|
||||||
|
],
|
||||||
|
http: {verb: 'post', path: '/update'}
|
||||||
|
});
|
||||||
|
|
||||||
setRemoting(PersistedModel, 'removeById', {
|
setRemoting(PersistedModel, 'removeById', {
|
||||||
description: 'Delete a model instance by id from the data source',
|
description: 'Delete a model instance by id from the data source',
|
||||||
accepts: {arg: 'id', type: 'any', description: 'Model id', required: true,
|
accepts: {arg: 'id', type: 'any', description: 'Model id', required: true,
|
||||||
|
|
|
@ -7,7 +7,7 @@ var AccessContext = require('./access-context').AccessContext;
|
||||||
|
|
||||||
// Role model
|
// Role model
|
||||||
var RoleSchema = {
|
var RoleSchema = {
|
||||||
id: {type: String, id: true}, // Id
|
id: {type: String, id: true, generated: true}, // Id
|
||||||
name: {type: String, required: true}, // The name of a role
|
name: {type: String, required: true}, // The name of a role
|
||||||
description: String, // Description
|
description: String, // Description
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ var RoleSchema = {
|
||||||
* Map principals to roles
|
* Map principals to roles
|
||||||
*/
|
*/
|
||||||
var RoleMappingSchema = {
|
var RoleMappingSchema = {
|
||||||
id: {type: String, id: true}, // Id
|
id: {type: String, id: true, generated: true}, // Id
|
||||||
roleId: String, // The role id
|
// roleId: String, // The role id, to be injected by the belongsTo relation
|
||||||
principalType: String, // The principal type, such as user, application, or role
|
principalType: String, // The principal type, such as user, application, or role
|
||||||
principalId: String // The principal id
|
principalId: String // The principal id
|
||||||
};
|
};
|
||||||
|
|
|
@ -77,6 +77,40 @@ describe('role model', function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("should automatically generate role id", function () {
|
||||||
|
|
||||||
|
User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) {
|
||||||
|
// console.log('User: ', user.id);
|
||||||
|
Role.create({name: 'userRole'}, function (err, role) {
|
||||||
|
assert(role.id);
|
||||||
|
role.principals.create({principalType: RoleMapping.USER, principalId: user.id}, function (err, p) {
|
||||||
|
assert(p.id);
|
||||||
|
assert.equal(p.roleId, role.id);
|
||||||
|
Role.find(function (err, roles) {
|
||||||
|
assert(!err);
|
||||||
|
assert.equal(roles.length, 1);
|
||||||
|
assert.equal(roles[0].name, 'userRole');
|
||||||
|
});
|
||||||
|
role.principals(function (err, principals) {
|
||||||
|
assert(!err);
|
||||||
|
// console.log(principals);
|
||||||
|
assert.equal(principals.length, 1);
|
||||||
|
assert.equal(principals[0].principalType, RoleMapping.USER);
|
||||||
|
assert.equal(principals[0].principalId, user.id);
|
||||||
|
});
|
||||||
|
role.users(function (err, users) {
|
||||||
|
assert(!err);
|
||||||
|
assert.equal(users.length, 1);
|
||||||
|
assert.equal(users[0].principalType, RoleMapping.USER);
|
||||||
|
assert.equal(users[0].principalId, user.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
it("should support getRoles() and isInRole()", function () {
|
it("should support getRoles() and isInRole()", function () {
|
||||||
User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) {
|
User.create({name: 'Raymond', email: 'x@y.com', password: 'foobar'}, function (err, user) {
|
||||||
// console.log('User: ', user.id);
|
// console.log('User: ', user.id);
|
||||||
|
|
Loading…
Reference in New Issue