ACL corregido error
This commit is contained in:
parent
0cc64bf285
commit
cd750cb86f
|
@ -11,9 +11,9 @@ module.exports = function (app) {
|
|||
|
||||
app.get('/acl', function(req, res){
|
||||
let token = req.cookies.vnToken;
|
||||
validateToken(token, function(isValid) {
|
||||
validateToken(token, function(isValid, token) {
|
||||
if (isValid)
|
||||
sendUserRole(res);
|
||||
sendUserRole(res, token);
|
||||
else
|
||||
sendACL(res, {});
|
||||
});
|
||||
|
@ -44,11 +44,8 @@ module.exports = function (app) {
|
|||
function validateToken(tokenId, cb) {
|
||||
app.models.AccessToken.findById(tokenId, function(err, token) {
|
||||
if (token) {
|
||||
if(token.userId){
|
||||
app.currentUser = {id: token.userId};
|
||||
}
|
||||
token.validate (function (err, isValid) {
|
||||
cb(isValid === true);
|
||||
cb(isValid === true, token);
|
||||
});
|
||||
}
|
||||
else
|
||||
|
@ -56,11 +53,11 @@ module.exports = function (app) {
|
|||
});
|
||||
}
|
||||
|
||||
function sendUserRole(res){
|
||||
if(app.currentUser && app.currentUser.id){
|
||||
function sendUserRole(res, token){
|
||||
if(token.userId){
|
||||
let query = {
|
||||
"where": {
|
||||
"principalId": `${app.currentUser.id}`,
|
||||
"principalId": token.userId,
|
||||
"principalType": "USER"
|
||||
},
|
||||
"include": [{
|
||||
|
@ -68,29 +65,26 @@ module.exports = function (app) {
|
|||
"scope": {
|
||||
"fields": ["name"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"relation": "user",
|
||||
"scope": {
|
||||
"fields": ["id", "username"]
|
||||
}
|
||||
}]
|
||||
};
|
||||
app.models.RoleMapping.belongsTo(app.models.User, {foreignKey: 'principalId', as: 'user'});
|
||||
};
|
||||
app.models.RoleMapping.find(query, function(err, roles){
|
||||
if(roles){
|
||||
let acl = {
|
||||
var acl = {
|
||||
userProfile: {},
|
||||
roles: {}
|
||||
};
|
||||
acl.userProfile = roles[0].user();
|
||||
Object.keys(roles).forEach(function(_, i){
|
||||
if(roles[i].roleId){
|
||||
let rol = roles[i].role();
|
||||
acl.roles[rol.name] = true;
|
||||
}
|
||||
});
|
||||
sendACL(res, acl);
|
||||
app.models.User.findById(token.userId, function(_, userProfile){
|
||||
//acl.userProfile = userProfile;
|
||||
acl.userProfile.id = userProfile.id;
|
||||
acl.userProfile.username = userProfile.username;
|
||||
sendACL(res, acl);
|
||||
});
|
||||
}
|
||||
else
|
||||
sendACL(res, {});
|
||||
|
|
Loading…
Reference in New Issue