2018-07-18 08:16:15 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// Delete deletes a team <-> namespace relation based on the namespace & team id
|
|
|
|
func (tn *TeamNamespace) Delete() (err error) {
|
|
|
|
|
2018-08-30 19:00:27 +02:00
|
|
|
// Check if the team exists
|
|
|
|
_, err = GetTeamByID(tn.TeamID)
|
2018-07-18 08:16:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-30 19:00:27 +02:00
|
|
|
// Check if the team has access to the namespace
|
|
|
|
has, err := x.Where("team_id = ? AND namespace_id = ?", tn.TeamID, tn.NamespaceID).
|
|
|
|
Get(&TeamNamespace{})
|
2018-07-18 08:16:15 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-08-30 19:00:27 +02:00
|
|
|
if !has {
|
|
|
|
return ErrTeamDoesNotHaveAccessToNamespace{TeamID: tn.TeamID, NamespaceID: tn.NamespaceID}
|
|
|
|
}
|
2018-07-18 08:16:15 +02:00
|
|
|
|
|
|
|
// Delete the relation
|
|
|
|
_, err = x.Where("team_id = ?", tn.TeamID).
|
|
|
|
And("namespace_id = ?", tn.NamespaceID).
|
2018-07-18 08:56:19 +02:00
|
|
|
Delete(TeamNamespace{})
|
2018-07-18 08:16:15 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|