Files
old-naida/endpoints/listuserpermissions.js
2019-11-07 01:10:25 +01:00

29 lines
932 B
JavaScript

//Call for listing all users with their permissions - needed for control panel
//Users without permissions also included
//
const handleListPerm = (req, res, db) => {
db.transaction ( trx => {
trx.select('users.username', 'permissions.objname', 'permissions.type')
.from('groups')
.fullOuterJoin('permissions', function () {
this.on('groups.groupname', '=', 'permissions.owner')
})
.rightJoin('users', function () {
this.on('groups.username', 'ilike','users.username')
.orOn('permissions.owner', 'ilike', 'users.username')
})
.orderBy('username', 'asc')
.orderBy('objname', 'asc')
.then ( data => {
res.json(data);
})
.then(trx.commit)
.catch(trx.rollback)
.catch (err => res.status(400).json('Error accesing database.'))
})
}
module.exports = {
handleListPerm
}