1
0

implemented delete team <-> namespace relation

This commit is contained in:
konrad
2018-07-18 08:16:15 +02:00
committed by kolaente
parent 249128a46e
commit ebb5b332b6
3 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,24 @@
package models
// Delete deletes a team <-> namespace relation based on the namespace & team id
func (tn *TeamNamespace) Delete() (err error) {
// Check if the namespace exists
_, err = GetNamespaceByID(tn.NamespaceID)
if err != nil {
return
}
// Check if the team exists
_, err = GetTeamByID(tn.TeamID)
if err != nil {
return
}
// Delete the relation
_, err = x.Where("team_id = ?", tn.TeamID).
And("namespace_id = ?", tn.NamespaceID).
Delete(tn)
return
}

View File

@ -5,3 +5,9 @@ func (tn *TeamNamespace) CanCreate(user *User, _ int64) bool {
n, _ := GetNamespaceByID(tn.NamespaceID)
return n.IsAdmin(user)
}
// CanDelete checks if a user can remove a team from a namespace. Only namespace admins can do that.
func (tn *TeamNamespace) CanDelete(user *User) bool {
n, _ := GetNamespaceByID(tn.NamespaceID)
return n.IsAdmin(user)
}