Added an endpoint to update a team <-> namespace relation

This commit is contained in:
kolaente 2018-09-19 08:16:04 +02:00
parent aa40ab8eed
commit 067672dcb4
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
6 changed files with 58 additions and 1 deletions

View File

@ -38,4 +38,34 @@ Content-Type: application/json
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}}
###

View File

@ -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

View File

@ -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)
}

View 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
}

View File

@ -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.")
}

View File

@ -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{},