mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
Don't expose user permissions when extendedPermissions is disabled, cleanup controller.js
This commit is contained in:
parent
abe4f8cf16
commit
b38da68d28
@ -25,7 +25,7 @@ class AdminApi extends Controller {
|
|||||||
);
|
);
|
||||||
this.app.use('/events', new EventController(stores).router);
|
this.app.use('/events', new EventController(stores).router);
|
||||||
this.app.use('/metrics', new MetricsController(perms, stores).router);
|
this.app.use('/metrics', new MetricsController(perms, stores).router);
|
||||||
this.app.use('/user', new UserController().router);
|
this.app.use('/user', new UserController(perms).router);
|
||||||
}
|
}
|
||||||
|
|
||||||
index(req, res) {
|
index(req, res) {
|
||||||
|
@ -3,17 +3,21 @@
|
|||||||
const Controller = require('../controller');
|
const Controller = require('../controller');
|
||||||
|
|
||||||
class UserController extends Controller {
|
class UserController extends Controller {
|
||||||
constructor() {
|
constructor(perms) {
|
||||||
super();
|
super(perms);
|
||||||
this.get('/', this.getUser);
|
this.get('/', this.getUser);
|
||||||
this.get('/logout', this.logout);
|
this.get('/logout', this.logout);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser(req, res) {
|
getUser(req, res) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
|
const user = Object.assign({}, req.user);
|
||||||
|
if (!this.extendedPermissions) {
|
||||||
|
delete user.permissions;
|
||||||
|
}
|
||||||
return res
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
.json(req.user)
|
.json(user)
|
||||||
.end();
|
.end();
|
||||||
} else {
|
} else {
|
||||||
return res.status(404).end();
|
return res.status(404).end();
|
||||||
|
@ -6,54 +6,49 @@ const { requirePermission } = require('./../permissions');
|
|||||||
* Base class for Controllers to standardize binding to express Router.
|
* Base class for Controllers to standardize binding to express Router.
|
||||||
*/
|
*/
|
||||||
class Controller {
|
class Controller {
|
||||||
constructor(extendedPerms) {
|
constructor(extendedPermissions) {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
this.app = router;
|
this.app = router;
|
||||||
this.extendedPerms = extendedPerms;
|
this.extendedPermissions = extendedPermissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkPermission(permission) {
|
||||||
|
if (this.extendedPermissions && permission) {
|
||||||
|
return requirePermission(permission);
|
||||||
|
}
|
||||||
|
return (res, req, next) => next();
|
||||||
}
|
}
|
||||||
|
|
||||||
get(path, handler, permission) {
|
get(path, handler, permission) {
|
||||||
if (this.extendedPerms && permission) {
|
this.app.get(
|
||||||
this.app.get(
|
path,
|
||||||
path,
|
this.checkPermission(permission),
|
||||||
requirePermission(permission),
|
handler.bind(this)
|
||||||
handler.bind(this)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
this.app.get(path, handler.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
post(path, handler, permission) {
|
post(path, handler, permission) {
|
||||||
if (this.extendedPerms && permission) {
|
this.app.post(
|
||||||
this.app.post(
|
path,
|
||||||
path,
|
this.checkPermission(permission),
|
||||||
requirePermission(permission),
|
handler.bind(this)
|
||||||
handler.bind(this)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
this.app.post(path, handler.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
put(path, handler, permission) {
|
put(path, handler, permission) {
|
||||||
if (this.extendedPerms && permission) {
|
this.app.put(
|
||||||
this.app.put(
|
path,
|
||||||
path,
|
this.checkPermission(permission),
|
||||||
requirePermission(permission),
|
handler.bind(this)
|
||||||
handler.bind(this)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
this.app.put(path, handler.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(path, handler, permission) {
|
delete(path, handler, permission) {
|
||||||
if (this.extendedPerms && permission) {
|
this.app.delete(
|
||||||
this.app.delete(
|
path,
|
||||||
path,
|
this.checkPermission(permission),
|
||||||
requirePermission(permission),
|
handler.bind(this)
|
||||||
handler.bind(this)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
this.app.delete(path, handler.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use(path, router) {
|
use(path, router) {
|
||||||
|
Loading…
Reference in New Issue
Block a user