Skip to content
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

add checks #540

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
## 1.4.32 (Unreleased)

* Clearer error message when adding a website
* Add User, Project and Group static classes to front end (refactor)
* Add checks for website owner update
* Fix error in 'projects' tab from user page


## 1.4.31 (2024-09-27)

* Fix 'Admin' button in 'My projects' page for administrators
Expand Down
30 changes: 27 additions & 3 deletions routes/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ router.put('/web/:id/owner/:old/:new', async function(req, res) {
} catch(e) {
logger.error(e);
res.status(404).send({message: 'User session not found'});
res.end();
return;
}

Expand All @@ -40,15 +39,40 @@ router.put('/web/:id/owner/:old/:new', async function(req, res) {
return;
}
session_user.is_admin = isadmin;

if(!session_user.is_admin) {
res.status(401).send({message: 'Not authorized'});
return;
}

if (req.params.old == req.params.new) {
res.status(300).send({message: 'Old owner and new owner are the same person'});
mboudet marked this conversation as resolved.
Show resolved Hide resolved
return;
}
try {
await dbsrv.mongo_web().findOne({name: req.params.id});
} catch(e) {
logger.error(e);
res.status(404).send({message: 'Website not found'});
return;
}
try {
await dbsrv.mongo_users().findOne({uid: req.params.old});
} catch(e) {
logger.error(e);
res.status(404).send({message: 'Old website owner not found'});
return;
}
try {
await dbsrv.mongo_users().findOne({uid: req.params.new});
} catch(e) {
logger.error(e);
res.status(404).send({message: 'New website owner not found'});
return;
}

await dbsrv.mongo_web().updateOne({name: req.params.id},{'$set': {owner: req.params.new}});
await dbsrv.mongo_events().insertOne({'owner': session_user.uid, 'date': new Date().getTime(), 'action': 'change website ' + req.params.id + ' owner to ' + req.params.new , 'logs': []});
res.send({message: 'Owner changed from ' + req.params.old + ' to ' + req.params.new});
res.end();
});

router.get('/web', async function(req, res) {
Expand Down