diff --git a/back/methods/account/getRoles.js b/back/methods/account/getRoles.js new file mode 100644 index 000000000..2a4e50ef2 --- /dev/null +++ b/back/methods/account/getRoles.js @@ -0,0 +1,31 @@ +module.exports = Self => { + Self.remoteMethodCtx('getUserRoles', { + description: 'Gets the user roles', + accepts: + { + arg: 'ctx', + type: 'Object', + http: {source: 'context'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: `/getUserRoles`, + verb: 'POST' + } + }); + + Self.getUserRoles = async ctx => { + // Get the user from the accesstoken + const userId = ctx.req.accessToken.userId; + + // Get the user roles + const roles = await Self.getRoles(userId, { + ctx: ctx + }); + + return roles; + }; +}; diff --git a/back/models/account.js b/back/models/account.js index f74052b5c..bb46cc2df 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/account/set-password')(Self); require('../methods/account/validate-token')(Self); require('../methods/account/privileges')(Self); + require('../methods/account/getRoles')(Self); // Validations