mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 00:03:40 +00:00
Init permissions routes
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
9cfc34e19f
commit
ff0b5a13a4
@ -146,6 +146,22 @@
|
|||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/roles/:id/permissions",
|
||||||
|
"handler": "role.getPermissions",
|
||||||
|
"config": {
|
||||||
|
"policies": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "PUT",
|
||||||
|
"path": "/roles/:id/permissions",
|
||||||
|
"handler": "role.updatePermissions",
|
||||||
|
"config": {
|
||||||
|
"policies": []
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/roles/:id",
|
"path": "/roles/:id",
|
||||||
|
|||||||
@ -3,6 +3,10 @@
|
|||||||
const { validateRoleUpdateInput } = require('../validation/role');
|
const { validateRoleUpdateInput } = require('../validation/role');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
/**
|
||||||
|
* Returns on role by id
|
||||||
|
* @param {KoaContext} ctx - koa context
|
||||||
|
*/
|
||||||
async findOne(ctx) {
|
async findOne(ctx) {
|
||||||
const { id } = ctx.params;
|
const { id } = ctx.params;
|
||||||
const role = await strapi.admin.services.role.findOneWithUsersCount({ id });
|
const role = await strapi.admin.services.role.findOneWithUsersCount({ id });
|
||||||
@ -15,6 +19,11 @@ module.exports = {
|
|||||||
data: role,
|
data: role,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns every roles
|
||||||
|
* @param {KoaContext} ctx - koa context
|
||||||
|
*/
|
||||||
async findAll(ctx) {
|
async findAll(ctx) {
|
||||||
const roles = await strapi.admin.services.role.findAllWithUsersCount();
|
const roles = await strapi.admin.services.role.findAllWithUsersCount();
|
||||||
|
|
||||||
@ -22,6 +31,11 @@ module.exports = {
|
|||||||
data: roles,
|
data: roles,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a role by id
|
||||||
|
* @param {KoaContext} ctx - koa context
|
||||||
|
*/
|
||||||
async update(ctx) {
|
async update(ctx) {
|
||||||
const { id } = ctx.params;
|
const { id } = ctx.params;
|
||||||
|
|
||||||
@ -43,4 +57,42 @@ module.exports = {
|
|||||||
data: sanitizedRole,
|
data: sanitizedRole,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the permissions assigned to a role
|
||||||
|
* @param {KoaContext} ctx - koa context
|
||||||
|
*/
|
||||||
|
async getPermissions(ctx) {
|
||||||
|
const { id } = ctx.params;
|
||||||
|
|
||||||
|
const role = await strapi.admin.services.role.findOne({ id });
|
||||||
|
|
||||||
|
if (!role) {
|
||||||
|
return ctx.notFound('role.notFound');
|
||||||
|
}
|
||||||
|
|
||||||
|
const permissions = await strapi.admin.services.permissions.find({ role: role.id });
|
||||||
|
|
||||||
|
ctx.body = {
|
||||||
|
data: permissions,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the permissions assigned to a role
|
||||||
|
* @param {KoaContext} ctx - koa context
|
||||||
|
*/
|
||||||
|
async updatePermissions(ctx) {
|
||||||
|
const { id } = ctx.params;
|
||||||
|
|
||||||
|
const role = await strapi.admin.services.role.findOne({ id });
|
||||||
|
|
||||||
|
if (!role) {
|
||||||
|
return ctx.notFound('role.notFound');
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.body = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
14
packages/strapi-admin/services/permissions.js
Normal file
14
packages/strapi-admin/services/permissions.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find assigned permissions in the database
|
||||||
|
* @param params query params to find the permissions
|
||||||
|
* @returns {Promise<array<Object>>}
|
||||||
|
*/
|
||||||
|
const find = (params = {}) => {
|
||||||
|
return strapi.query('permission', 'admin').find(params, []);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
find,
|
||||||
|
};
|
||||||
@ -30,6 +30,12 @@ module.exports = strapi =>
|
|||||||
controller = strapi.controllers[controllerKey] || strapi.admin.controllers[controllerKey];
|
controller = strapi.controllers[controllerKey] || strapi.admin.controllers[controllerKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_.isFunction(controller[actionName])) {
|
||||||
|
strapi.stopWithError(
|
||||||
|
`Error creating endpoint ${method} ${endpoint}: handler not found "${controllerKey}.${actionName}"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const action = controller[actionName].bind(controller);
|
const action = controller[actionName].bind(controller);
|
||||||
|
|
||||||
// Retrieve the API's name where the controller is located
|
// Retrieve the API's name where the controller is located
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user