Skip to content

Commit

Permalink
feat: expose global/admin privileges to all routes
Browse files Browse the repository at this point in the history
@barisusakli revert if necessary 😬
  • Loading branch information
julianlam committed Aug 20, 2020
1 parent b2271eb commit 4737f93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/middleware/render.js
Expand Up @@ -7,6 +7,7 @@ const winston = require('winston');

const plugins = require('../plugins');
const meta = require('../meta');
const privileges = require('../privileges');
const translator = require('../translator');
const widgets = require('../widgets');
const utils = require('../utils');
Expand All @@ -31,6 +32,9 @@ module.exports = function (middleware) {
options.url = (req.baseUrl + req.path.replace(/^\/api/, ''));
options.bodyClass = buildBodyClass(req, res, options);

const privilegeSet = await Promise.all(['global', 'admin'].map(async type => privileges[type].get(req.uid)));
options.privileges = { ...privilegeSet[0], ...privilegeSet[1] };

const buildResult = await plugins.fireHook('filter:' + template + '.build', { req: req, res: res, templateData: options });
const templateToRender = buildResult.templateData.templateToRender || template;

Expand Down
2 changes: 1 addition & 1 deletion test/api.js
Expand Up @@ -66,7 +66,7 @@ describe('Read API', async () => {
await socketUser.exportPosts({ uid: adminUid }, { uid: adminUid });
await socketUser.exportUploads({ uid: adminUid }, { uid: adminUid });
// wait for export child process to complete
await wait(20000);
// await wait(20000);

This comment has been minimized.

Copy link
@julianlam

julianlam Aug 20, 2020

Author Member

every time, lol


// Attach a search hook so /api/search is enabled
plugins.registerHook('core', {
Expand Down

0 comments on commit 4737f93

Please sign in to comment.