1
0

Cleanup/fixing methods

This commit is contained in:
konrad
2018-08-30 19:00:27 +02:00
committed by kolaente
parent efaa277751
commit aeb1521cc4
4 changed files with 55 additions and 12 deletions

View File

@ -3,18 +3,22 @@ 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
}
// Check if the team has access to the namespace
has, err := x.Where("team_id = ? AND namespace_id = ?", tn.TeamID, tn.NamespaceID).
Get(&TeamNamespace{})
if err != nil {
return
}
if !has {
return ErrTeamDoesNotHaveAccessToNamespace{TeamID: tn.TeamID, NamespaceID: tn.NamespaceID}
}
// Delete the relation
_, err = x.Where("team_id = ?", tn.TeamID).
And("namespace_id = ?", tn.NamespaceID).