WIP: add update user group command
This commit is contained in:
@@ -134,9 +134,12 @@ func (hs *HttpServer) registerRoutes() {
|
||||
|
||||
// user group (admin permission required)
|
||||
r.Group("/user-groups", func() {
|
||||
r.Get("/:userGroupId", wrap(GetUserGroupById))
|
||||
r.Get("/search", wrap(SearchUserGroups))
|
||||
r.Post("/", quota("user-groups"), bind(m.CreateUserGroupCommand{}), wrap(CreateUserGroup))
|
||||
r.Put("/:userGroupId", bind(m.UpdateUserGroupCommand{}), wrap(UpdateUserGroup))
|
||||
r.Delete("/:userGroupId", wrap(DeleteUserGroupById))
|
||||
r.Get("/:userGroupId/members", wrap(GetUserGroupMembers))
|
||||
}, reqGrafanaAdmin)
|
||||
|
||||
// org information available to all users.
|
||||
|
||||
@@ -26,6 +26,19 @@ func CreateUserGroup(c *middleware.Context, cmd m.CreateUserGroupCommand) Respon
|
||||
})
|
||||
}
|
||||
|
||||
// PUT /api/user-groups/:userGroupId
|
||||
func UpdateUserGroup(c *middleware.Context, cmd m.UpdateUserGroupCommand) Response {
|
||||
cmd.Id = c.ParamsInt64(":userGroupId")
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
if err == m.ErrUserGroupNameTaken {
|
||||
return ApiError(400, "User Group name taken", err)
|
||||
}
|
||||
return ApiError(500, "Failed to update User Group", err)
|
||||
}
|
||||
|
||||
return ApiSuccess("User Group updated")
|
||||
}
|
||||
|
||||
// DELETE /api/user-groups/:userGroupId
|
||||
func DeleteUserGroupById(c *middleware.Context) Response {
|
||||
if err := bus.Dispatch(&m.DeleteUserGroupCommand{Id: c.ParamsInt64(":userGroupId")}); err != nil {
|
||||
@@ -64,3 +77,18 @@ func SearchUserGroups(c *middleware.Context) Response {
|
||||
|
||||
return Json(200, query.Result)
|
||||
}
|
||||
|
||||
// GET /api/user-groups/:userGroupId
|
||||
func GetUserGroupById(c *middleware.Context) Response {
|
||||
query := m.GetUserGroupByIdQuery{Id: c.ParamsInt64(":userGroupId")}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err == m.ErrUserGroupNotFound {
|
||||
return ApiError(404, "User Group not found", err)
|
||||
}
|
||||
|
||||
return ApiError(500, "Failed to get User Group", err)
|
||||
}
|
||||
|
||||
return Json(200, &query.Result)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
// GET /api/user-groups/:userGroupId/members
|
||||
func GetUserGroupMembers(c *middleware.Context) Response {
|
||||
query := m.GetUserGroupMembersQuery{UserGroupId: c.ParamsInt64(":userGroupId")}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
return ApiError(500, "Failed to get User Group Members", err)
|
||||
}
|
||||
|
||||
return Json(200, query.Result)
|
||||
}
|
||||
Reference in New Issue
Block a user