fix error handling and displaying on membership PUT and DELETE; don't allow to change your own role; require at least one admin

This commit is contained in:
mntmn
2020-04-09 14:55:18 +02:00
parent c05afaba8a
commit 16ffecdb16
4 changed files with 57 additions and 21 deletions

View File

@@ -168,12 +168,15 @@ router.post('/', function(req, res, next) {
attrs.edit_slug = slug(attrs.name);
db.Space.create(attrs).then(createdSpace => {
//if (err) res.sendStatus(400);
res.status(201).json(createdSpace);
// create initial admin membership
var membership = {
_id: uuidv4(),
user_id: req.user._id,
space_id: attrs._id,
role: "admin"
role: "admin",
state: "active"
};
db.Membership.create(membership).then(() => {