implemented delete team <-> namespace relation
This commit is contained in:
parent
249128a46e
commit
ebb5b332b6
3 changed files with 31 additions and 1 deletions
24
models/team_namespace_delete.go
Normal file
24
models/team_namespace_delete.go
Normal 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
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -118,7 +118,7 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
}
|
||||
a.GET("/namespaces/:id/teams", namespaceTeamHandler.ReadAllWeb)
|
||||
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{
|
||||
CObject: &models.Team{},
|
||||
|
|
Loading…
Reference in a new issue