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
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
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) n, _ := GetNamespaceByID(tn.NamespaceID)
return n.IsAdmin(user) 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)
}

View file

@ -118,7 +118,7 @@ func RegisterRoutes(e *echo.Echo) {
} }
a.GET("/namespaces/:id/teams", namespaceTeamHandler.ReadAllWeb) a.GET("/namespaces/:id/teams", namespaceTeamHandler.ReadAllWeb)
a.PUT("/namespaces/:id/teams", namespaceTeamHandler.CreateWeb) a.PUT("/namespaces/:id/teams", namespaceTeamHandler.CreateWeb)
a.DELETE("/namespaces/:nid/teams/:id", namespaceTeamHandler.DeleteWeb) a.DELETE("/namespaces/:nid/teams/:teamid", namespaceTeamHandler.DeleteWeb)
teamHandler := &crud.WebHandler{ teamHandler := &crud.WebHandler{
CObject: &models.Team{}, CObject: &models.Team{},