API: Add createdAt and updatedAt to api/users/lookup (#19496)

* API: Add `createdAt` and `updatedAt` to api/users/lookup

In the past, we have added both `updatedAt` (#19004) and `createdAt` (#19475) to /api/users/:id

Turns out, api/users/lookup uses the same DTO for both. This fixes the serialization of both `createdAt` and `updatedAt`for this endpoint.

Also, adds a test to ensure no further regressions.

* Updated API documentation
This commit is contained in:
gotjosh
2019-09-30 20:54:09 +01:00
committed by GitHub
parent 47432e9349
commit 4181b30b75
3 changed files with 61 additions and 3 deletions

View File

@@ -116,12 +116,18 @@ HTTP/1.1 200
## User Update
`PUT /api/users/:id`
**Example Request**:
```http
PUT /api/users/2 HTTP/1.1
Accept: application/json
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```
Requires basic authentication and that the authenticated user is a Grafana Admin.
**Example Response**:
@@ -162,7 +168,12 @@ Content-Type: application/json
```http
GET /api/users/1/teams HTTP/1.1
`GET /api/users/:id/teams`
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```
Requires basic authentication and that the authenticated user is a Grafana Admin.
**Example Response**:

View File

@@ -57,6 +57,8 @@ func GetUserByLoginOrEmail(c *m.ReqContext) Response {
Theme: user.Theme,
IsGrafanaAdmin: user.IsAdmin,
OrgId: user.OrgId,
UpdatedAt: user.Updated,
CreatedAt: user.Created,
}
return JSON(200, &result)
}

View File

@@ -73,6 +73,51 @@ func TestUserApiEndpoint(t *testing.T) {
require.JSONEq(t, expected, sc.resp.Body.String())
})
loggedInUserScenario("When calling GET on", "/api/users/lookup", func(sc *scenarioContext) {
fakeNow := time.Date(2019, 2, 11, 17, 30, 40, 0, time.UTC)
bus.AddHandler("test", func(query *models.GetUserByLoginQuery) error {
require.Equal(t, "danlee", query.LoginOrEmail)
query.Result = &models.User{
Id: int64(1),
Email: "daniel@grafana.com",
Name: "Daniel",
Login: "danlee",
Theme: "light",
IsAdmin: true,
OrgId: int64(2),
IsDisabled: false,
Updated: fakeNow,
Created: fakeNow,
}
return nil
})
sc.handlerFunc = GetUserByLoginOrEmail
sc.fakeReqWithParams("GET", sc.url, map[string]string{"loginOrEmail": "danlee"}).exec()
expected := `
{
"id": 1,
"email": "daniel@grafana.com",
"name": "Daniel",
"login": "danlee",
"theme": "light",
"orgId": 2,
"isGrafanaAdmin": true,
"isDisabled": false,
"authLabels": null,
"isExternal": false,
"updatedAt": "2019-02-11T17:30:40Z",
"createdAt": "2019-02-11T17:30:40Z"
}
`
require.Equal(t, http.StatusOK, sc.resp.Code)
require.JSONEq(t, expected, sc.resp.Body.String())
})
loggedInUserScenario("When calling GET on", "/api/users", func(sc *scenarioContext) {
var sentLimit int
var sendPage int