1
0

Added endpoint to update a user <-> namespace relation

This commit is contained in:
kolaente
2018-09-19 08:03:39 +02:00
parent 1e993f1e5c
commit 5e8597699d
4 changed files with 34 additions and 1 deletions

View File

@ -13,3 +13,10 @@ func (nu *NamespaceUser) CanDelete(doer *User) bool {
n, _ := GetNamespaceByID(nu.NamespaceID)
return n.CanWrite(doer)
}
// CanUpdate checks if the user can update a user <-> namespace relation
func (nu *NamespaceUser) CanUpdate(doer *User) bool {
// Get the namespace and check if the user has write access on it
n, _ := GetNamespaceByID(nu.NamespaceID)
return n.CanWrite(doer)
}

View File

@ -0,0 +1,16 @@
package models
// Update updates a user <-> namespace relation
func (nu *NamespaceUser) Update() (err error) {
// Check if the right is valid
if err := nu.Right.isValid(); err != nil {
return err
}
_, err = x.
Where("namespace_id = ? AND user_id = ?", nu.NamespaceID, nu.UserID).
Cols("right").
Update(nu)
return
}