Browse Source

ban user button in Admin

develop
Rob Colbert 2 years ago
parent
commit
814c358233
  1. 41
      app/controllers/admin/user.js
  2. 3
      app/services/chat.js
  3. 4
      app/views/admin/user/form.pug

41
app/controllers/admin/user.js

@ -35,6 +35,9 @@ class UserAdminController extends SiteController {
const { user: userService } = this.dtp.services; const { user: userService } = this.dtp.services;
try { try {
res.locals.userAccount = await userService.getLocalUserAccount(localUserId); res.locals.userAccount = await userService.getLocalUserAccount(localUserId);
if (!res.locals.userAccount) {
throw new SiteError(404, 'User not found');
}
return next(); return next();
} catch (error) { } catch (error) {
return next(error); return next(error);
@ -42,9 +45,43 @@ class UserAdminController extends SiteController {
} }
async postUpdateLocalUser (req, res, next) { async postUpdateLocalUser (req, res, next) {
const { user: userService } = this.dtp.services; const {
logan: loganService,
user: userService,
} = this.dtp.services;
try { try {
await userService.updateLocalForAdmin(res.locals.userAccount, req.body); this.log.debug('local user update', { action: req.body.action });
switch (req.body.action) {
case 'update':
await userService.updateLocalForAdmin(res.locals.userAccount, req.body);
loganService.sendRequestEvent(module.exports, req, {
level: 'info',
event: 'postUpdateLocalUser',
message: 'local user account updated',
data: {
userAccount: {
_id: res.locals.userAccount._id,
username: res.locals.userAccount.username,
},
},
});
break;
case 'ban':
await userService.ban(res.locals.userAccount);
loganService.sendRequestEvent(module.exports, req, {
level: 'info',
event: 'postUpdateLocalUser',
message: 'local user banned from the app',
data: {
userAccount: {
_id: res.locals.userAccount._id,
username: res.locals.userAccount.username,
},
},
});
break;
}
res.redirect('/admin/user'); res.redirect('/admin/user');
} catch (error) { } catch (error) {
return next(error); return next(error);

3
app/services/chat.js

@ -792,7 +792,8 @@ class ChatService extends SiteService {
await ChatRoom await ChatRoom
.find({ owner: user._id }) .find({ owner: user._id })
.populate(this.populateChatRoom) .populate(this.populateChatRoom)
.cursor(async (room) => { .cursor()
.eachAsync(async (room) => {
try { try {
await this.deleteRoom(room); await this.deleteRoom(room);
++roomCount; ++roomCount;

4
app/views/admin/user/form.pug

@ -76,7 +76,9 @@ block content
.uk-width-expand .uk-width-expand
+renderBackButton() +renderBackButton()
.uk-width-auto .uk-width-auto
button(type="submit").uk-button.uk-button-primary Update User button(type="submit", name="action", value="ban").uk-button.uk-button-danger.uk-border-rounded Ban User
.uk-width-auto
button(type="submit", name="action", value="update").uk-button.uk-button-primary.uk-border-rounded Update User
div(class="uk-width-1-1 uk-width-1-3@l") div(class="uk-width-1-1 uk-width-1-3@l")

Loading…
Cancel
Save