1
0

Added namespace user rights

This commit is contained in:
konrad
2018-09-04 20:15:24 +02:00
committed by kolaente
parent 422662e3e1
commit f2758e239c
12 changed files with 179 additions and 4 deletions

View File

@ -0,0 +1,25 @@
package models
// Delete deletes a namespace <-> user relation
func (nu *NamespaceUser) Delete() (err error) {
// Check if the user exists
_, err = GetUserByID(nu.UserID)
if err != nil {
return
}
// Check if the user has access to the namespace
has, err := x.Where("user_id = ? AND namespace_id = ?", nu.UserID, nu.NamespaceID).
Get(&NamespaceUser{})
if err != nil {
return
}
if !has {
return ErrUserDoesNotHaveAccessToNamespace{NamespaceID: nu.NamespaceID, UserID: nu.UserID}
}
_, err = x.Where("user_id = ? AND namespace_id = ?", nu.UserID, nu.NamespaceID).
Delete(&NamespaceUser{})
return
}