2019-01-23 12:11:44 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('acl', {
|
|
|
|
description: 'Get the user information and permissions',
|
|
|
|
accepts: [
|
|
|
|
{
|
|
|
|
arg: 'ctx',
|
|
|
|
type: 'Object',
|
|
|
|
http: {source: 'context'}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
returns: {
|
|
|
|
type: 'Object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/acl`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.acl = async function(ctx) {
|
|
|
|
let userId = ctx.req.accessToken.userId;
|
|
|
|
let models = Self.app.models;
|
|
|
|
|
2023-01-31 13:57:24 +00:00
|
|
|
let user = await Self.findById(userId, {
|
2022-04-20 08:25:01 +00:00
|
|
|
fields: ['id', 'name', 'nickname', 'email', 'lang'],
|
|
|
|
include: {
|
|
|
|
relation: 'userConfig',
|
|
|
|
scope: {
|
|
|
|
fields: ['darkMode']
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 12:11:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let roles = await models.RoleMapping.find({
|
|
|
|
fields: ['roleId'],
|
|
|
|
where: {
|
|
|
|
principalId: userId,
|
|
|
|
principalType: 'USER'
|
|
|
|
},
|
|
|
|
include: [{
|
|
|
|
relation: 'role',
|
|
|
|
scope: {
|
|
|
|
fields: ['name']
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
return {roles, user};
|
|
|
|
};
|
|
|
|
};
|