Skip to content

Commit

Permalink
fix: is user doesnt have view:users privilege
Browse files Browse the repository at this point in the history
dont redirect uid/1 to userslug
  • Loading branch information
barisusakli committed Apr 12, 2024
1 parent 6816e39 commit 14f5774
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/middleware/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,12 @@ module.exports = function (middleware) {
if (uid <= 0) {
return next();
}
const userslug = await user.getUserField(uid, 'userslug');
if (!userslug) {
const [canView, userslug] = await Promise.all([
privileges.global.can('view:users', req.uid),
user.getUserField(uid, 'userslug'),
]);

if (!userslug || (!canView && req.uid !== uid)) {
return next();
}
const path = req.url.replace(/^\/api/, '')
Expand Down
6 changes: 5 additions & 1 deletion src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const helpers = require('./helpers');
const { setupPageRoute } = helpers;

module.exports = function (app, name, middleware, controllers) {
const middlewares = [middleware.exposeUid, middleware.canViewUsers, middleware.buildAccountData];
const middlewares = [
middleware.exposeUid,
middleware.canViewUsers,
middleware.buildAccountData,
];
const accountMiddlewares = [
...middlewares,
middleware.ensureLoggedIn,
Expand Down

0 comments on commit 14f5774

Please sign in to comment.