mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #14120 from supercharlesliu/user-teams
Add API GET /api/users/:id/teams for GrafanaAdmin
This commit is contained in:
@@ -226,6 +226,40 @@ Content-Type: application/json
|
|||||||
**Example Response**:
|
**Example Response**:
|
||||||
|
|
||||||
```http
|
```http
|
||||||
|
HTTP/1.1 200
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Switch user context for a specified user
|
||||||
|
|
||||||
|
`POST /api/users/:userId/using/:organizationId`
|
||||||
|
|
||||||
|
Switch user context to the given organization. Requires basic authentication and that the authenticated user is a Grafana Admin.
|
||||||
|
|
||||||
|
**Example Request**:
|
||||||
|
|
||||||
|
```http
|
||||||
|
POST /api/users/7/using/2 HTTP/1.1
|
||||||
|
Authorization: Basic YWRtaW46YWRtaW4=
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example Response**:
|
||||||
|
|
||||||
|
```http
|
||||||
|
HTTP/1.1 200
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Switch user context for signed in user
|
||||||
|
|
||||||
|
`POST /api/user/using/:organizationId`
|
||||||
|
|
||||||
|
Switch user context to the given organization.
|
||||||
|
|
||||||
|
**Example Request**:
|
||||||
|
|
||||||
```http
|
```http
|
||||||
POST /api/user/using/2 HTTP/1.1
|
POST /api/user/using/2 HTTP/1.1
|
||||||
Accept: application/json
|
Accept: application/json
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
usersRoute.Get("/", Wrap(SearchUsers))
|
usersRoute.Get("/", Wrap(SearchUsers))
|
||||||
usersRoute.Get("/search", Wrap(SearchUsersWithPaging))
|
usersRoute.Get("/search", Wrap(SearchUsersWithPaging))
|
||||||
usersRoute.Get("/:id", Wrap(GetUserByID))
|
usersRoute.Get("/:id", Wrap(GetUserByID))
|
||||||
|
usersRoute.Get("/:id/teams", Wrap(GetUserTeams))
|
||||||
usersRoute.Get("/:id/orgs", Wrap(GetUserOrgList))
|
usersRoute.Get("/:id/orgs", Wrap(GetUserOrgList))
|
||||||
// query parameters /users/lookup?loginOrEmail=admin@example.com
|
// query parameters /users/lookup?loginOrEmail=admin@example.com
|
||||||
usersRoute.Get("/lookup", Wrap(GetUserByLoginOrEmail))
|
usersRoute.Get("/lookup", Wrap(GetUserByLoginOrEmail))
|
||||||
|
|||||||
@@ -113,7 +113,16 @@ func GetSignedInUserOrgList(c *m.ReqContext) Response {
|
|||||||
|
|
||||||
// GET /api/user/teams
|
// GET /api/user/teams
|
||||||
func GetSignedInUserTeamList(c *m.ReqContext) Response {
|
func GetSignedInUserTeamList(c *m.ReqContext) Response {
|
||||||
query := m.GetTeamsByUserQuery{OrgId: c.OrgId, UserId: c.UserId}
|
return getUserTeamList(c.OrgId, c.UserId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET /api/users/:id/teams
|
||||||
|
func GetUserTeams(c *m.ReqContext) Response {
|
||||||
|
return getUserTeamList(c.OrgId, c.ParamsInt64(":id"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUserTeamList(userID int64, orgID int64) Response {
|
||||||
|
query := m.GetTeamsByUserQuery{OrgId: orgID, UserId: userID}
|
||||||
|
|
||||||
if err := bus.Dispatch(&query); err != nil {
|
if err := bus.Dispatch(&query); err != nil {
|
||||||
return Error(500, "Failed to get user teams", err)
|
return Error(500, "Failed to get user teams", err)
|
||||||
@@ -122,11 +131,10 @@ func GetSignedInUserTeamList(c *m.ReqContext) Response {
|
|||||||
for _, team := range query.Result {
|
for _, team := range query.Result {
|
||||||
team.AvatarUrl = dtos.GetGravatarUrlWithDefault(team.Email, team.Name)
|
team.AvatarUrl = dtos.GetGravatarUrlWithDefault(team.Email, team.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON(200, query.Result)
|
return JSON(200, query.Result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/user/:id/orgs
|
// GET /api/users/:id/orgs
|
||||||
func GetUserOrgList(c *m.ReqContext) Response {
|
func GetUserOrgList(c *m.ReqContext) Response {
|
||||||
return getUserOrgList(c.ParamsInt64(":id"))
|
return getUserOrgList(c.ParamsInt64(":id"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user