2017-11-06 11:14:43 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UsersPermissions.js controller
|
|
|
|
*
|
|
|
|
* @description: A set of functions called "actions" of the `users-permissions` plugin.
|
|
|
|
*/
|
|
|
|
|
2017-11-16 14:12:03 +01:00
|
|
|
const fakeData = require('../config/fakeData.json');
|
2017-11-15 15:06:09 +01:00
|
|
|
const _ = require('lodash');
|
|
|
|
|
2017-11-06 11:14:43 +01:00
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default action.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
2017-11-15 15:11:10 +01:00
|
|
|
getPermissions: async(ctx) => {
|
|
|
|
try {
|
2017-11-16 17:59:41 +01:00
|
|
|
const permissions = await strapi.plugins['users-permissions'].services.userspermissions.getActions();
|
|
|
|
ctx.send({ permissions });
|
2017-11-15 15:11:10 +01:00
|
|
|
} catch(err) {
|
2017-11-16 17:59:41 +01:00
|
|
|
console.log(err);
|
2017-11-15 15:11:10 +01:00
|
|
|
ctx.badRequest(null, [{ message: [{ id: 'Not Found' }] }]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-15 14:00:51 +01:00
|
|
|
getRole: async(ctx) => {
|
|
|
|
const { id } = ctx.params;
|
2017-11-15 15:11:10 +01:00
|
|
|
const role = fakeData[id];
|
|
|
|
|
|
|
|
if (_.isEmpty(role)) {
|
|
|
|
return ctx.badRequest(null, [{ messages: [{ id: 'Role don\'t exist' }] }]);
|
|
|
|
}
|
2017-11-15 14:00:51 +01:00
|
|
|
|
2017-11-15 15:11:10 +01:00
|
|
|
return ctx.send({ role });
|
2017-11-15 14:00:51 +01:00
|
|
|
},
|
2017-11-06 11:14:43 +01:00
|
|
|
|
|
|
|
index: async (ctx) => {
|
|
|
|
// Add your own logic here.
|
|
|
|
|
|
|
|
// Send 200 `ok`
|
|
|
|
ctx.send({
|
|
|
|
message: 'ok'
|
|
|
|
});
|
2017-11-14 17:09:13 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
init: async (ctx) => {
|
2017-11-15 17:27:07 +01:00
|
|
|
const hasAdmin = await strapi.query('user', 'users-permissions').find({
|
|
|
|
where: {
|
|
|
|
admin: true
|
|
|
|
}
|
2017-11-15 15:06:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ctx.send({ hasAdmin: !_.isEmpty(hasAdmin) });
|
2017-11-06 11:14:43 +01:00
|
|
|
}
|
|
|
|
};
|