Browse Source

Merge branch 'develop' of git.digitaltelepresence.com:digital-telepresence/dtp-base into develop

develop
Rob Colbert 2 years ago
parent
commit
f731e478ec
  1. 12
      app/controllers/admin/user.js

12
app/controllers/admin/user.js

@ -100,10 +100,14 @@ class UserAdminController extends SiteController {
user: userService, user: userService,
} = this.dtp.services; } = this.dtp.services;
try { try {
const user = await userService.getLocalUserAccount(req.body.userId); const user = await userService.getLocalUserAccount(req.body.userId);
if (!user) { if (!user) {
throw new SiteError(404, 'User not found'); throw new SiteError(404, 'User not found');
} }
if (req.user && req.user._id.equals(user._id)) {
throw new SiteError(400, "You can't archive yourself");
}
res.locals.job = await userService.archiveLocalUser(user); res.locals.job = await userService.archiveLocalUser(user);
loganService.sendRequestEvent(module.exports, req, { loganService.sendRequestEvent(module.exports, req, {
level: 'info', level: 'info',
@ -138,6 +142,11 @@ class UserAdminController extends SiteController {
this.log.debug('local user update', { action: req.body.action }); this.log.debug('local user update', { action: req.body.action });
switch (req.body.action) { switch (req.body.action) {
case 'update': case 'update':
if (req.user._id.equals(res.locals.userAccount._id)) {
if (req.user.flags.isAdmin && !(userDefinition.isAdmin === 'on')) {
throw new SiteError(400, "You can't remove your own admin privileges");
}
}
await userService.updateLocalForAdmin(res.locals.userAccount, req.body); await userService.updateLocalForAdmin(res.locals.userAccount, req.body);
loganService.sendRequestEvent(module.exports, req, { loganService.sendRequestEvent(module.exports, req, {
level: 'info', level: 'info',
@ -153,6 +162,9 @@ class UserAdminController extends SiteController {
break; break;
case 'ban': case 'ban':
if (req.user._id.equals(res.locals.userAccount._id)) {
throw new SiteError(400, "You can't ban yourself");
}
await userService.ban(res.locals.userAccount); await userService.ban(res.locals.userAccount);
loganService.sendRequestEvent(module.exports, req, { loganService.sendRequestEvent(module.exports, req, {
level: 'info', level: 'info',

Loading…
Cancel
Save