Added an endpoint to update a team <-> namespace relation
This commit is contained in:
parent
aa40ab8eed
commit
067672dcb4
6 changed files with 58 additions and 1 deletions
|
@ -39,3 +39,33 @@ DELETE http://localhost:8080/api/v1/namespaces/1/users/2
|
|||
Authorization: Bearer {{auth_token}}
|
||||
|
||||
###
|
||||
|
||||
# Get all teams who have access to that namespace
|
||||
GET http://localhost:8080/api/v1/namespaces/1/teams
|
||||
Authorization: Bearer {{auth_token}}
|
||||
|
||||
###
|
||||
|
||||
# Give a team access to that namespace
|
||||
PUT http://localhost:8080/api/v1/namespaces/1/teams
|
||||
Authorization: Bearer {{auth_token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{"team_id":3, "right": 0}
|
||||
|
||||
###
|
||||
|
||||
# Update a teams access to that namespace
|
||||
POST http://localhost:8080/api/v1/namespaces/1/teams/1
|
||||
Authorization: Bearer {{auth_token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{"right": 0}
|
||||
|
||||
###
|
||||
|
||||
# Delete a team from a namespace
|
||||
DELETE http://localhost:8080/api/v1/namespaces/1/teams/2
|
||||
Authorization: Bearer {{auth_token}}
|
||||
|
||||
###
|
|
@ -1,6 +1,6 @@
|
|||
package models
|
||||
|
||||
// Update updates a user <-> namespace relation
|
||||
// Update updates a team <-> list relation
|
||||
func (tl *TeamList) Update() (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
|
|
|
@ -11,3 +11,9 @@ func (tn *TeamNamespace) CanDelete(user *User) bool {
|
|||
n, _ := GetNamespaceByID(tn.NamespaceID)
|
||||
return n.IsAdmin(user)
|
||||
}
|
||||
|
||||
// CanUpdate checks if a user can update a team from a namespace. Only namespace admins can do that.
|
||||
func (tn *TeamNamespace) CanUpdate(user *User) bool {
|
||||
n, _ := GetNamespaceByID(tn.NamespaceID)
|
||||
return n.IsAdmin(user)
|
||||
}
|
||||
|
|
16
models/team_namespace_update.go
Normal file
16
models/team_namespace_update.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package models
|
||||
|
||||
// Update updates a team <-> namespace relation
|
||||
func (tl *TeamNamespace) Update() (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
if err := tl.Right.isValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = x.
|
||||
Where("namespace_id = ? AND team_id = ?", tl.TeamID, tl.TeamID).
|
||||
Cols("right").
|
||||
Update(tl)
|
||||
return
|
||||
}
|
|
@ -24,6 +24,10 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||
return echo.NewHTTPError(http.StatusForbidden, "You need to have read access to this list.")
|
||||
}
|
||||
|
||||
if models.IsErrNamespaceDoesNotExist(err) {
|
||||
return echo.NewHTTPError(http.StatusNotFound, "This namespace does not exist.")
|
||||
}
|
||||
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "An error occured.")
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
a.GET("/namespaces/:namespace/teams", namespaceTeamHandler.ReadAllWeb)
|
||||
a.PUT("/namespaces/:namespace/teams", namespaceTeamHandler.CreateWeb)
|
||||
a.DELETE("/namespaces/:namespace/teams/:team", namespaceTeamHandler.DeleteWeb)
|
||||
a.POST("/namespaces/:namespace/teams/:team", namespaceTeamHandler.UpdateWeb)
|
||||
|
||||
namespaceUserHandler := &crud.WebHandler{
|
||||
CObject: &models.NamespaceUser{},
|
||||
|
|
Loading…
Reference in a new issue