Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/lib/server/functions/setUserActiveStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ export function setUserActiveStatus(userId, active, confirmRelinquish = false) {
return false;
}


// Users without username can't do anything, so there is no need to check for owned rooms
if (user.username != null && !active) {
const userAdmin = Users.findOneAdmin(userId.count);
const adminsCount = Users.findActiveUsersInRoles(['admin']).count();
if (userAdmin && adminsCount === 1) {
throw new Meteor.Error('error-action-not-allowed', 'Leaving the app without an active admin is not allowed', {
method: 'removeUserFromRole',
action: 'Remove_last_admin',
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add this check to removing role if role is admin. Some people seem to keep removing the last admin. 🙈


const subscribedRooms = getSubscribedRoomsForUserWithDetails(userId);
// give omnichannel rooms a special treatment :)
const chatSubscribedRooms = subscribedRooms.filter(({ t }) => t !== 'l');
Expand Down
11 changes: 11 additions & 0 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,17 @@ export class Users extends Base {
return this.find(query, options);
}

findActiveUsersInRoles(roles, scope, options) {
roles = [].concat(roles);

const query = {
roles: { $in: roles },
active: true,
};

return this.find(query, options);
}

findOneByAppId(appId, options) {
const query = { appId };

Expand Down