Skip to content

Commit 6979a7f

Browse files
committed
User profile
1 parent 9285425 commit 6979a7f

File tree

5 files changed

+316
-0
lines changed

5 files changed

+316
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,6 +2126,83 @@ const docTemplate = `{
21262126
}
21272127
}
21282128
},
2129+
"/users/{user}": {
2130+
"delete": {
2131+
"security": [
2132+
{
2133+
"CoderSessionToken": []
2134+
}
2135+
],
2136+
"produces": [
2137+
"application/json"
2138+
],
2139+
"tags": [
2140+
"Users"
2141+
],
2142+
"summary": "Get user by name",
2143+
"operationId": "get-user-by-name",
2144+
"parameters": [
2145+
{
2146+
"type": "string",
2147+
"description": "User ID, name, or me",
2148+
"name": "user",
2149+
"in": "path",
2150+
"required": true
2151+
}
2152+
],
2153+
"responses": {
2154+
"200": {
2155+
"description": "OK",
2156+
"schema": {
2157+
"$ref": "#/definitions/codersdk.User"
2158+
}
2159+
}
2160+
}
2161+
}
2162+
},
2163+
"/users/{user}/profile": {
2164+
"put": {
2165+
"security": [
2166+
{
2167+
"CoderSessionToken": []
2168+
}
2169+
],
2170+
"produces": [
2171+
"application/json"
2172+
],
2173+
"tags": [
2174+
"Users"
2175+
],
2176+
"summary": "Update user profile",
2177+
"operationId": "update-user-profile",
2178+
"parameters": [
2179+
{
2180+
"type": "string",
2181+
"description": "User ID, name, or me",
2182+
"name": "user",
2183+
"in": "path",
2184+
"required": true
2185+
},
2186+
{
2187+
"description": "Updated profile",
2188+
"name": "request",
2189+
"in": "body",
2190+
"required": true,
2191+
"schema": {
2192+
"$ref": "#/definitions/codersdk.UpdateUserProfileRequest"
2193+
}
2194+
}
2195+
],
2196+
"responses": {
2197+
"200": {
2198+
"description": "OK",
2199+
"schema": {
2200+
"$ref": "#/definitions/codersdk.User"
2201+
}
2202+
}
2203+
}
2204+
}
2205+
},
21292206
"/users/{user}/workspace/{workspacename}": {
21302207
"get": {
21312208
"security": [
@@ -4840,6 +4917,17 @@ const docTemplate = `{
48404917
}
48414918
}
48424919
},
4920+
"codersdk.UpdateUserProfileRequest": {
4921+
"type": "object",
4922+
"required": [
4923+
"username"
4924+
],
4925+
"properties": {
4926+
"username": {
4927+
"type": "string"
4928+
}
4929+
}
4930+
},
48434931
"codersdk.UpdateWorkspaceAutostartRequest": {
48444932
"type": "object",
48454933
"properties": {

coderd/apidoc/swagger.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,75 @@
18661866
}
18671867
}
18681868
},
1869+
"/users/{user}": {
1870+
"delete": {
1871+
"security": [
1872+
{
1873+
"CoderSessionToken": []
1874+
}
1875+
],
1876+
"produces": ["application/json"],
1877+
"tags": ["Users"],
1878+
"summary": "Get user by name",
1879+
"operationId": "get-user-by-name",
1880+
"parameters": [
1881+
{
1882+
"type": "string",
1883+
"description": "User ID, name, or me",
1884+
"name": "user",
1885+
"in": "path",
1886+
"required": true
1887+
}
1888+
],
1889+
"responses": {
1890+
"200": {
1891+
"description": "OK",
1892+
"schema": {
1893+
"$ref": "#/definitions/codersdk.User"
1894+
}
1895+
}
1896+
}
1897+
}
1898+
},
1899+
"/users/{user}/profile": {
1900+
"put": {
1901+
"security": [
1902+
{
1903+
"CoderSessionToken": []
1904+
}
1905+
],
1906+
"produces": ["application/json"],
1907+
"tags": ["Users"],
1908+
"summary": "Update user profile",
1909+
"operationId": "update-user-profile",
1910+
"parameters": [
1911+
{
1912+
"type": "string",
1913+
"description": "User ID, name, or me",
1914+
"name": "user",
1915+
"in": "path",
1916+
"required": true
1917+
},
1918+
{
1919+
"description": "Updated profile",
1920+
"name": "request",
1921+
"in": "body",
1922+
"required": true,
1923+
"schema": {
1924+
"$ref": "#/definitions/codersdk.UpdateUserProfileRequest"
1925+
}
1926+
}
1927+
],
1928+
"responses": {
1929+
"200": {
1930+
"description": "OK",
1931+
"schema": {
1932+
"$ref": "#/definitions/codersdk.User"
1933+
}
1934+
}
1935+
}
1936+
}
1937+
},
18691938
"/users/{user}/workspace/{workspacename}": {
18701939
"get": {
18711940
"security": [
@@ -4376,6 +4445,15 @@
43764445
}
43774446
}
43784447
},
4448+
"codersdk.UpdateUserProfileRequest": {
4449+
"type": "object",
4450+
"required": ["username"],
4451+
"properties": {
4452+
"username": {
4453+
"type": "string"
4454+
}
4455+
}
4456+
},
43794457
"codersdk.UpdateWorkspaceAutostartRequest": {
43804458
"type": "object",
43814459
"properties": {

coderd/users.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ func (api *API) postUser(rw http.ResponseWriter, r *http.Request) {
339339
httpapi.Write(ctx, rw, http.StatusCreated, convertUser(user, []uuid.UUID{req.OrganizationID}))
340340
}
341341

342+
// @Summary Delete user
343+
// @ID delete-user
344+
// @Security CoderSessionToken
345+
// @Produce json
346+
// @Tags Users
347+
// @Param user path string true "User ID, name, or me"
348+
// @Success 200 {object} codersdk.User
349+
// @Router /users/{user} [delete]
342350
func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
343351
ctx := r.Context()
344352
auditor := *api.Auditor.Load()
@@ -394,6 +402,15 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) {
394402

395403
// Returns the parameterized user requested. All validation
396404
// is completed in the middleware for this route.
405+
//
406+
// @Summary Get user by name
407+
// @ID get-user-by-name
408+
// @Security CoderSessionToken
409+
// @Produce json
410+
// @Tags Users
411+
// @Param user path string true "User ID, name, or me"
412+
// @Success 200 {object} codersdk.User
413+
// @Router /users/{user} [delete]
397414
func (api *API) userByName(rw http.ResponseWriter, r *http.Request) {
398415
ctx := r.Context()
399416
user := httpmw.UserParam(r)
@@ -415,6 +432,15 @@ func (api *API) userByName(rw http.ResponseWriter, r *http.Request) {
415432
httpapi.Write(ctx, rw, http.StatusOK, convertUser(user, organizationIDs))
416433
}
417434

435+
// @Summary Update user profile
436+
// @ID update-user-profile
437+
// @Security CoderSessionToken
438+
// @Produce json
439+
// @Tags Users
440+
// @Param user path string true "User ID, name, or me"
441+
// @Param request body codersdk.UpdateUserProfileRequest true "Updated profile"
442+
// @Success 200 {object} codersdk.User
443+
// @Router /users/{user}/profile [put]
418444
func (api *API) putUserProfile(rw http.ResponseWriter, r *http.Request) {
419445
var (
420446
ctx = r.Context()

docs/api/schemas.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,20 @@ Parameter represents a set value for the scope.
33773377
| ------- | --------------- | -------- | ------------ | ----------- |
33783378
| `roles` | array of string | false | | |
33793379

3380+
## codersdk.UpdateUserProfileRequest
3381+
3382+
```json
3383+
{
3384+
"username": "string"
3385+
}
3386+
```
3387+
3388+
### Properties
3389+
3390+
| Name | Type | Required | Restrictions | Description |
3391+
| ---------- | ------ | -------- | ------------ | ----------- |
3392+
| `username` | string | true | | |
3393+
33803394
## codersdk.UpdateWorkspaceAutostartRequest
33813395

33823396
```json

docs/api/users.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,113 @@ curl -X GET http://coder-server:8080/api/v2/users/oidc/callback \
320320
| 307 | [Temporary Redirect](https://tools.ietf.org/html/rfc7231#section-6.4.7) | Temporary Redirect | |
321321

322322
To perform this operation, you must be authenticated. [Learn more](authentication.md).
323+
324+
## Get user by name
325+
326+
### Code samples
327+
328+
```shell
329+
# Example request using curl
330+
curl -X DELETE http://coder-server:8080/api/v2/users/{user} \
331+
-H 'Accept: application/json' \
332+
-H 'Coder-Session-Token: API_KEY'
333+
```
334+
335+
`DELETE /users/{user}`
336+
337+
### Parameters
338+
339+
| Name | In | Type | Required | Description |
340+
| ------ | ---- | ------ | -------- | -------------------- |
341+
| `user` | path | string | true | User ID, name, or me |
342+
343+
### Example responses
344+
345+
> 200 Response
346+
347+
```json
348+
{
349+
"avatar_url": "http://example.com",
350+
"created_at": "2019-08-24T14:15:22Z",
351+
"email": "user@example.com",
352+
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
353+
"last_seen_at": "2019-08-24T14:15:22Z",
354+
"organization_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
355+
"roles": [
356+
{
357+
"display_name": "string",
358+
"name": "string"
359+
}
360+
],
361+
"status": "active",
362+
"username": "string"
363+
}
364+
```
365+
366+
### Responses
367+
368+
| Status | Meaning | Description | Schema |
369+
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------- |
370+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.User](schemas.md#codersdkuser) |
371+
372+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
373+
374+
## Update user profile
375+
376+
### Code samples
377+
378+
```shell
379+
# Example request using curl
380+
curl -X PUT http://coder-server:8080/api/v2/users/{user}/profile \
381+
-H 'Content-Type: application/json' \
382+
-H 'Accept: application/json' \
383+
-H 'Coder-Session-Token: API_KEY'
384+
```
385+
386+
`PUT /users/{user}/profile`
387+
388+
> Body parameter
389+
390+
```json
391+
{
392+
"username": "string"
393+
}
394+
```
395+
396+
### Parameters
397+
398+
| Name | In | Type | Required | Description |
399+
| ------ | ---- | -------------------------------------------------------------------------------- | -------- | -------------------- |
400+
| `user` | path | string | true | User ID, name, or me |
401+
| `body` | body | [codersdk.UpdateUserProfileRequest](schemas.md#codersdkupdateuserprofilerequest) | true | Updated profile |
402+
403+
### Example responses
404+
405+
> 200 Response
406+
407+
```json
408+
{
409+
"avatar_url": "http://example.com",
410+
"created_at": "2019-08-24T14:15:22Z",
411+
"email": "user@example.com",
412+
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
413+
"last_seen_at": "2019-08-24T14:15:22Z",
414+
"organization_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
415+
"roles": [
416+
{
417+
"display_name": "string",
418+
"name": "string"
419+
}
420+
],
421+
"status": "active",
422+
"username": "string"
423+
}
424+
```
425+
426+
### Responses
427+
428+
| Status | Meaning | Description | Schema |
429+
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------- |
430+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.User](schemas.md#codersdkuser) |
431+
432+
To perform this operation, you must be authenticated. [Learn more](authentication.md).

0 commit comments

Comments
 (0)