mirror of
https://github.com/strapi/strapi.git
synced 2025-07-08 17:45:30 +00:00
78 lines
1.6 KiB
JavaScript
78 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* UsersPermissions.js controller
|
|
*
|
|
* @description: A set of functions called "actions" of the `users-permissions` plugin.
|
|
*/
|
|
|
|
const fakeData = require('../config/fakeData.json');
|
|
const _ = require('lodash');
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
* Default action.
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
createRole: async (ctx) => {
|
|
if (_.isEmpty(ctx.request.body)) {
|
|
return ctx.badRequest(null, [{ messages: [{ id: 'Cannot be empty' }] }]);
|
|
}
|
|
|
|
try {
|
|
ctx.send({ ok: true });
|
|
} catch(err) {
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occured' }] }]);
|
|
}
|
|
},
|
|
|
|
getPermissions: async (ctx) => {
|
|
try {
|
|
const permissions = await strapi.plugins['users-permissions'].services.userspermissions.getActions();
|
|
ctx.send({ permissions });
|
|
} catch(err) {
|
|
ctx.badRequest(null, [{ message: [{ id: 'Not Found' }] }]);
|
|
}
|
|
},
|
|
|
|
getRole: async (ctx) => {
|
|
const { id } = ctx.params;
|
|
const role = fakeData[id];
|
|
|
|
if (_.isEmpty(role)) {
|
|
return ctx.badRequest(null, [{ messages: [{ id: `Role don't exist` }] }]);
|
|
}
|
|
|
|
return ctx.send({ role });
|
|
},
|
|
|
|
index: async (ctx) => {
|
|
// Add your own logic here.
|
|
|
|
// Send 200 `ok`
|
|
ctx.send({
|
|
message: 'ok'
|
|
});
|
|
},
|
|
|
|
init: async (ctx) => {
|
|
const hasAdmin = await strapi.query('user', 'users-permissions').find({
|
|
where: {
|
|
admin: true
|
|
}
|
|
});
|
|
|
|
ctx.send({ hasAdmin: !_.isEmpty(hasAdmin) });
|
|
},
|
|
|
|
updateRole: async (ctx) => {
|
|
try {
|
|
ctx.send({ ok: true });
|
|
} catch(error) {
|
|
ctx.badRequest(null, [{ messages: [{ id: 'An error occurred' }] }]);
|
|
}
|
|
}
|
|
};
|