models: move Role LDL def into a json file
This commit is contained in:
parent
e9c86163aa
commit
461ae92c1c
|
@ -41,8 +41,8 @@ var AccessContext = ctx.AccessContext;
|
||||||
var Principal = ctx.Principal;
|
var Principal = ctx.Principal;
|
||||||
var AccessRequest = ctx.AccessRequest;
|
var AccessRequest = ctx.AccessRequest;
|
||||||
|
|
||||||
var role = require('./role');
|
var Role = loopback.Role;
|
||||||
var Role = role.Role;
|
assert(Role, 'Role model must be defined before ACL model');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Model for access control meta data.
|
* A Model for access control meta data.
|
||||||
|
|
|
@ -5,33 +5,26 @@ var async = require('async');
|
||||||
|
|
||||||
var AccessContext = require('../../lib/access-context').AccessContext;
|
var AccessContext = require('../../lib/access-context').AccessContext;
|
||||||
|
|
||||||
// Role model
|
var RoleMapping = loopback.RoleMapping;
|
||||||
var RoleSchema = {
|
assert(RoleMapping, 'RoleMapping model must be defined before Role model');
|
||||||
id: {type: String, id: true, generated: true}, // Id
|
|
||||||
name: {type: String, required: true}, // The name of a role
|
|
||||||
description: String, // Description
|
|
||||||
|
|
||||||
// Timestamps
|
|
||||||
created: {type: Date, default: Date},
|
|
||||||
modified: {type: Date, default: Date}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Role Model
|
* The Role Model
|
||||||
* @class
|
* @class Role
|
||||||
*/
|
*/
|
||||||
var Role = loopback.createModel('Role', RoleSchema, {
|
module.exports = function(Role) {
|
||||||
relations: {
|
|
||||||
principals: {
|
|
||||||
type: 'hasMany',
|
|
||||||
model: 'RoleMapping',
|
|
||||||
foreignKey: 'roleId'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var RoleMapping = loopback.RoleMapping;
|
// Workaround for https://github.com/strongloop/loopback/issues/292
|
||||||
assert(RoleMapping, 'RoleMapping model must be defined before Role model');
|
Role.definition.rawProperties.created.default =
|
||||||
|
Role.definition.properties.created.default = function() {
|
||||||
|
return new Date();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Workaround for https://github.com/strongloop/loopback/issues/292
|
||||||
|
Role.definition.rawProperties.modified.default =
|
||||||
|
Role.definition.properties.modified.default = function() {
|
||||||
|
return new Date();
|
||||||
|
};
|
||||||
|
|
||||||
// Set up the connection to users/applications/roles once the model
|
// Set up the connection to users/applications/roles once the model
|
||||||
Role.once('dataSourceAttached', function() {
|
Role.once('dataSourceAttached', function() {
|
||||||
|
@ -393,11 +386,4 @@ Role.getRoles = function (context, callback) {
|
||||||
callback && callback(err, roles);
|
callback && callback(err, roles);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
Role: Role,
|
|
||||||
RoleMapping: RoleMapping
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"name": "Role",
|
||||||
|
"properties": {
|
||||||
|
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
"id": true,
|
||||||
|
"generated": true
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"description": "string",
|
||||||
|
|
||||||
|
"created": "date",
|
||||||
|
"modified": "date"
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"principals": {
|
||||||
|
"type": "hasMany",
|
||||||
|
"model": "RoleMapping",
|
||||||
|
"foreignKey": "roleId"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,7 +17,9 @@ module.exports = function(loopback) {
|
||||||
require('../common/models/role-mapping.json'),
|
require('../common/models/role-mapping.json'),
|
||||||
require('../common/models/role-mapping.js'));
|
require('../common/models/role-mapping.js'));
|
||||||
|
|
||||||
loopback.Role = require('../common/models/role').Role;
|
loopback.Role = createModel(
|
||||||
|
require('../common/models/role.json'),
|
||||||
|
require('../common/models/role.js'));
|
||||||
|
|
||||||
loopback.ACL = createModel(
|
loopback.ACL = createModel(
|
||||||
require('../common/models/acl.json'),
|
require('../common/models/acl.json'),
|
||||||
|
|
Loading…
Reference in New Issue