New project structure
Beta of extract.js for extracting english locale
This commit is contained in:
parent
e18d2b2f84
commit
2edbd67205
247 changed files with 6405 additions and 4237 deletions
78
server/routes/rest/shares.js
Normal file
78
server/routes/rest/shares.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
'use strict';
|
||||
|
||||
const passport = require('../../lib/passport');
|
||||
const _ = require('../../lib/translate')._;
|
||||
const shares = require('../../models/shares');
|
||||
|
||||
const router = require('../../lib/router-async').create();
|
||||
const {castToInteger} = require('../../lib/helpers');
|
||||
|
||||
router.postAsync('/shares-table-by-entity/:entityTypeId/:entityId', passport.loggedIn, async (req, res) => {
|
||||
return res.json(await shares.listByEntityDTAjax(req.context, req.params.entityTypeId, castToInteger(req.params.entityId), req.body));
|
||||
});
|
||||
|
||||
router.postAsync('/shares-table-by-user/:entityTypeId/:userId', passport.loggedIn, async (req, res) => {
|
||||
return res.json(await shares.listByUserDTAjax(req.context, req.params.entityTypeId, castToInteger(req.params.userId), req.body));
|
||||
});
|
||||
|
||||
router.postAsync('/shares-unassigned-users-table/:entityTypeId/:entityId', passport.loggedIn, async (req, res) => {
|
||||
return res.json(await shares.listUnassignedUsersDTAjax(req.context, req.params.entityTypeId, castToInteger(req.params.entityId), req.body));
|
||||
});
|
||||
|
||||
router.postAsync('/shares-roles-table/:entityTypeId', passport.loggedIn, async (req, res) => {
|
||||
return res.json(await shares.listRolesDTAjax(req.params.entityTypeId, req.body));
|
||||
});
|
||||
|
||||
router.putAsync('/shares', passport.loggedIn, async (req, res) => {
|
||||
const body = req.body;
|
||||
await shares.assign(req.context, body.entityTypeId, body.entityId, body.userId, body.role);
|
||||
|
||||
return res.json();
|
||||
});
|
||||
|
||||
/*
|
||||
Checks if entities with a given permission exist.
|
||||
|
||||
Accepts format:
|
||||
{
|
||||
XXX1: {
|
||||
entityTypeId: ...
|
||||
requiredOperations: [ ... ]
|
||||
},
|
||||
|
||||
XXX2: {
|
||||
entityTypeId: ...
|
||||
requiredOperations: [ ... ]
|
||||
}
|
||||
}
|
||||
|
||||
Returns:
|
||||
{
|
||||
XXX1: true
|
||||
XXX2: false
|
||||
}
|
||||
*/
|
||||
router.postAsync('/permissions-check', passport.loggedIn, async (req, res) => {
|
||||
const body = req.body;
|
||||
const result = {};
|
||||
|
||||
for (const reqKey in body) {
|
||||
if (body[reqKey].entityId) {
|
||||
result[reqKey] = await shares.checkEntityPermission(req.context, body[reqKey].entityTypeId, body[reqKey].entityId, body[reqKey].requiredOperations);
|
||||
} else {
|
||||
result[reqKey] = await shares.checkTypePermission(req.context, body[reqKey].entityTypeId, body[reqKey].requiredOperations);
|
||||
}
|
||||
}
|
||||
|
||||
return res.json(result);
|
||||
});
|
||||
|
||||
router.postAsync('/permissions-rebuild', passport.loggedIn, async (req, res) => {
|
||||
shares.enforceGlobalPermission(req.context, 'rebuildPermissions');
|
||||
await shares.rebuildPermissions();
|
||||
return res.json(result);
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue