summaryrefslogtreecommitdiffstats
path: root/server/api/user.js
diff options
context:
space:
mode:
authorChristian Hofmaier2018-08-05 01:42:49 +0200
committerChristian Hofmaier2018-08-05 01:42:49 +0200
commitd236e4c57a7f71589764efccd0cb36337d551055 (patch)
tree6d47dc6deface87f1985ce7daf26692e25838b16 /server/api/user.js
parent[store/global] simplified settings loading (diff)
downloadbas-d236e4c57a7f71589764efccd0cb36337d551055.tar.gz
bas-d236e4c57a7f71589764efccd0cb36337d551055.tar.xz
bas-d236e4c57a7f71589764efccd0cb36337d551055.zip
[permissions] add permission management
Add Roles Table with Delete Roles and Create Roles possibilities Add Users Table with Grant Roles and Revoke Roles possibilities
Diffstat (limited to 'server/api/user.js')
-rw-r--r--server/api/user.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/server/api/user.js b/server/api/user.js
index 0565d58..9aba1fc 100644
--- a/server/api/user.js
+++ b/server/api/user.js
@@ -26,5 +26,38 @@ module.exports = {
user.name = userDb.name
res.status(200).send(user)
})
+ },
+
+ getUserList: function(req, res) {
+ db.user.findAll({
+ attributes: ['id', 'username', 'name'],
+ include: [{model: db.role, as: 'roles', attributes: ['name'] }]
+ }).then(function (users) {
+ res.status(200).send(users)
+ })
+ },
+
+ grantRoles: function(req, res) {
+ const roleIds = req.body.roleIds
+ const userIds = req.body.userIds
+
+ db.user.findAll({ where: { id: userIds } }).then(users => {
+ users.forEach(user => {
+ user.addRoles(roleIds)
+ })
+ res.status(200).send('success')
+ })
+ },
+
+ revokeRoles: function(req, res) {
+ const roleIds = req.body.roleIds
+ const userIds = req.body.userIds
+
+ db.user.findAll({ where: { id: userIds } }).then(users => {
+ users.forEach(user => {
+ user.removeRoles(roleIds)
+ })
+ res.status(200).send('success')
+ })
}
}