Skip to content

check project owner is not removed #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* increase size of input field in users page
* add a readonly input field under email for showing the email domain*
* Add "custom_users" key to config file, to be used with various scripts
* Check that user being removed is not owner or last member of a project


## 1.4.31 (2024-09-27)
Expand Down
12 changes: 8 additions & 4 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,17 @@ router.delete('/user/:id', async function(req, res) {
return;
}
const allprojects = user.projects ? user.projects : [];
let empty_projects = '';
for (let project_name of allprojects) {
const users_in_project = await dbsrv.mongo_users().find({ 'projects': project_name }).toArray();
if (users_in_project.length <= 1) {
res.status(403).send({ message: 'User is the last member of project ${project_name}' });
return;
const users_in_project = await dbsrv.mongo_users().find({ 'projects': project_name }).count();
if (users_in_project <= 1) {
empty_projects += ', ' + project_name;
}
}
if(empty_projects != '') {
res.status(403).send({ message: 'User is the last member of project(s)${empty_projects}' });
return;
}
usrsrv.delete_user(user, session_user.uid, mail_message, mail_send).then(function() {
res.send({ message: 'User deleted' });
return;
Expand Down