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 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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
* Allow accents in user's first and last names


Expand Down
17 changes: 17 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,23 @@ router.delete('/user/:id', async function(req, res) {
res.status(403).send({ message: 'User owns some web sites, please change owner first!' });
return;
}
let projects = await dbsrv.mongo_projects().find({ owner: uid }).toArray();
if (projects && projects.length > 0) {
res.status(403).send({ message: 'User owns some projects, please change owner first!' });
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 }).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