Skip to content

Commit 863f932

Browse files
authored
Merge pull request #1201 from mathematicalthinking/adminActionButtons
Admin action buttons -- another force logout try
2 parents d325883 + 719953b commit 863f932

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

client/src/Containers/Dashboard.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,22 @@ class Dashboard extends Component {
239239
isSuspended: false,
240240
});
241241

242-
removeAsAdmin = (userId) => {
243-
const { user } = this.props;
244-
console.log('about to force logout', userId, user._id);
245-
socket.emit('FORCE_LOGOUT', userId, user._id);
242+
removeAsAdmin = (userId, details) => {
243+
if (this._isOkToForceLogout(details)) {
244+
const { user } = this.props;
245+
socket.emit('FORCE_LOGOUT', userId, user._id);
246+
}
246247
this._buttonAction(() => API.removeAsAdmin(userId), userId, {
247248
isAdmin: false,
248249
socketId: null,
249250
});
250251
};
251252

252253
makeAdmin = (userId) => {
253-
const { user } = this.props;
254-
console.log('about to force logout', userId, user._id);
255-
socket.emit('FORCE_LOGOUT', userId, user._id);
254+
if (this._isOkToForceLogout(details)) {
255+
const { user } = this.props;
256+
socket.emit('FORCE_LOGOUT', userId, user._id);
257+
}
256258
this._buttonAction(() => API.makeAdmin(userId), userId, {
257259
isAdmin: true,
258260
socketId: null,
@@ -336,12 +338,13 @@ class Dashboard extends Component {
336338
};
337339

338340
const iconActions = [];
339-
if (details.socketId && !details.doForceLogout)
340-
iconActions.push(forceLogoutAction);
341+
if (this._isOkToForceLogout(details)) iconActions.push(forceLogoutAction);
341342
if (!isSelf) iconActions.push(suspendReinstateAction, makeRemoveAdmin);
342343
return iconActions;
343344
};
344345

346+
_isOkToForceLogout = (user) => user.socketId && !user.doForceLogout;
347+
345348
render() {
346349
const { match, user } = this.props;
347350
const {
@@ -410,7 +413,7 @@ class Dashboard extends Component {
410413
<Button
411414
data-testid={manageUserAction}
412415
click={() => {
413-
this[manageUserAction](userToManage._id);
416+
this[manageUserAction](userToManage._id, userToManage);
414417
}}
415418
m={5}
416419
>

server/sockets.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ module.exports = function() {
241241
try {
242242
const allSockets = await getAllSocketsForUser(userId);
243243
io.in(allSockets).emit('FORCED_LOGOUT');
244-
// forceUserLogout(userId, userId);
245244
} catch (error) {
246245
console.error(
247246
`Error forcing logout by user ${userId}: ${error.message}`

0 commit comments

Comments
 (0)