Skip to content

Commit 62a26f9

Browse files
committed
Status suspend activate
1 parent 6979a7f commit 62a26f9

File tree

5 files changed

+254
-2
lines changed

5 files changed

+254
-2
lines changed

coderd/apidoc/docs.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,74 @@ const docTemplate = `{
22032203
}
22042204
}
22052205
},
2206+
"/users/{user}/status/activate": {
2207+
"put": {
2208+
"security": [
2209+
{
2210+
"CoderSessionToken": []
2211+
}
2212+
],
2213+
"produces": [
2214+
"application/json"
2215+
],
2216+
"tags": [
2217+
"Users"
2218+
],
2219+
"summary": "Activate user account",
2220+
"operationId": "activate-user-account",
2221+
"parameters": [
2222+
{
2223+
"type": "string",
2224+
"description": "User ID, name, or me",
2225+
"name": "user",
2226+
"in": "path",
2227+
"required": true
2228+
}
2229+
],
2230+
"responses": {
2231+
"200": {
2232+
"description": "OK",
2233+
"schema": {
2234+
"$ref": "#/definitions/codersdk.User"
2235+
}
2236+
}
2237+
}
2238+
}
2239+
},
2240+
"/users/{user}/status/suspend": {
2241+
"put": {
2242+
"security": [
2243+
{
2244+
"CoderSessionToken": []
2245+
}
2246+
],
2247+
"produces": [
2248+
"application/json"
2249+
],
2250+
"tags": [
2251+
"Users"
2252+
],
2253+
"summary": "Suspend user account",
2254+
"operationId": "suspend-user-account",
2255+
"parameters": [
2256+
{
2257+
"type": "string",
2258+
"description": "User ID, name, or me",
2259+
"name": "user",
2260+
"in": "path",
2261+
"required": true
2262+
}
2263+
],
2264+
"responses": {
2265+
"200": {
2266+
"description": "OK",
2267+
"schema": {
2268+
"$ref": "#/definitions/codersdk.User"
2269+
}
2270+
}
2271+
}
2272+
}
2273+
},
22062274
"/users/{user}/workspace/{workspacename}": {
22072275
"get": {
22082276
"security": [

coderd/apidoc/swagger.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,66 @@
19351935
}
19361936
}
19371937
},
1938+
"/users/{user}/status/activate": {
1939+
"put": {
1940+
"security": [
1941+
{
1942+
"CoderSessionToken": []
1943+
}
1944+
],
1945+
"produces": ["application/json"],
1946+
"tags": ["Users"],
1947+
"summary": "Activate user account",
1948+
"operationId": "activate-user-account",
1949+
"parameters": [
1950+
{
1951+
"type": "string",
1952+
"description": "User ID, name, or me",
1953+
"name": "user",
1954+
"in": "path",
1955+
"required": true
1956+
}
1957+
],
1958+
"responses": {
1959+
"200": {
1960+
"description": "OK",
1961+
"schema": {
1962+
"$ref": "#/definitions/codersdk.User"
1963+
}
1964+
}
1965+
}
1966+
}
1967+
},
1968+
"/users/{user}/status/suspend": {
1969+
"put": {
1970+
"security": [
1971+
{
1972+
"CoderSessionToken": []
1973+
}
1974+
],
1975+
"produces": ["application/json"],
1976+
"tags": ["Users"],
1977+
"summary": "Suspend user account",
1978+
"operationId": "suspend-user-account",
1979+
"parameters": [
1980+
{
1981+
"type": "string",
1982+
"description": "User ID, name, or me",
1983+
"name": "user",
1984+
"in": "path",
1985+
"required": true
1986+
}
1987+
],
1988+
"responses": {
1989+
"200": {
1990+
"description": "OK",
1991+
"schema": {
1992+
"$ref": "#/definitions/codersdk.User"
1993+
}
1994+
}
1995+
}
1996+
}
1997+
},
19381998
"/users/{user}/workspace/{workspacename}": {
19391999
"get": {
19402000
"security": [

coderd/coderd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ func New(options *Options) *API {
462462
r.Get("/", api.userByName)
463463
r.Put("/profile", api.putUserProfile)
464464
r.Route("/status", func(r chi.Router) {
465-
r.Put("/suspend", api.putUserStatus(database.UserStatusSuspended))
466-
r.Put("/activate", api.putUserStatus(database.UserStatusActive))
465+
r.Put("/suspend", api.putSuspendUserAccount())
466+
r.Put("/activate", api.putActivateUserAccount())
467467
})
468468
r.Route("/password", func(r chi.Router) {
469469
r.Put("/", api.putUserPassword)

coderd/users.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,30 @@ func (api *API) putUserProfile(rw http.ResponseWriter, r *http.Request) {
521521
httpapi.Write(ctx, rw, http.StatusOK, convertUser(updatedUserProfile, organizationIDs))
522522
}
523523

524+
// @Summary Suspend user account
525+
// @ID suspend-user-account
526+
// @Security CoderSessionToken
527+
// @Produce json
528+
// @Tags Users
529+
// @Param user path string true "User ID, name, or me"
530+
// @Success 200 {object} codersdk.User
531+
// @Router /users/{user}/status/suspend [put]
532+
func (api *API) putSuspendUserAccount() func(rw http.ResponseWriter, r *http.Request) {
533+
return api.putUserStatus(database.UserStatusSuspended)
534+
}
535+
536+
// @Summary Activate user account
537+
// @ID activate-user-account
538+
// @Security CoderSessionToken
539+
// @Produce json
540+
// @Tags Users
541+
// @Param user path string true "User ID, name, or me"
542+
// @Success 200 {object} codersdk.User
543+
// @Router /users/{user}/status/activate [put]
544+
func (api *API) putActivateUserAccount() func(rw http.ResponseWriter, r *http.Request) {
545+
return api.putUserStatus(database.UserStatusSuspended)
546+
}
547+
524548
func (api *API) putUserStatus(status database.UserStatus) func(rw http.ResponseWriter, r *http.Request) {
525549
return func(rw http.ResponseWriter, r *http.Request) {
526550
var (

docs/api/users.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,103 @@ curl -X PUT http://coder-server:8080/api/v2/users/{user}/profile \
430430
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.User](schemas.md#codersdkuser) |
431431

432432
To perform this operation, you must be authenticated. [Learn more](authentication.md).
433+
434+
## Activate user account
435+
436+
### Code samples
437+
438+
```shell
439+
# Example request using curl
440+
curl -X PUT http://coder-server:8080/api/v2/users/{user}/status/activate \
441+
-H 'Accept: application/json' \
442+
-H 'Coder-Session-Token: API_KEY'
443+
```
444+
445+
`PUT /users/{user}/status/activate`
446+
447+
### Parameters
448+
449+
| Name | In | Type | Required | Description |
450+
| ------ | ---- | ------ | -------- | -------------------- |
451+
| `user` | path | string | true | User ID, name, or me |
452+
453+
### Example responses
454+
455+
> 200 Response
456+
457+
```json
458+
{
459+
"avatar_url": "http://example.com",
460+
"created_at": "2019-08-24T14:15:22Z",
461+
"email": "user@example.com",
462+
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
463+
"last_seen_at": "2019-08-24T14:15:22Z",
464+
"organization_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
465+
"roles": [
466+
{
467+
"display_name": "string",
468+
"name": "string"
469+
}
470+
],
471+
"status": "active",
472+
"username": "string"
473+
}
474+
```
475+
476+
### Responses
477+
478+
| Status | Meaning | Description | Schema |
479+
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------- |
480+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.User](schemas.md#codersdkuser) |
481+
482+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
483+
484+
## Suspend user account
485+
486+
### Code samples
487+
488+
```shell
489+
# Example request using curl
490+
curl -X PUT http://coder-server:8080/api/v2/users/{user}/status/suspend \
491+
-H 'Accept: application/json' \
492+
-H 'Coder-Session-Token: API_KEY'
493+
```
494+
495+
`PUT /users/{user}/status/suspend`
496+
497+
### Parameters
498+
499+
| Name | In | Type | Required | Description |
500+
| ------ | ---- | ------ | -------- | -------------------- |
501+
| `user` | path | string | true | User ID, name, or me |
502+
503+
### Example responses
504+
505+
> 200 Response
506+
507+
```json
508+
{
509+
"avatar_url": "http://example.com",
510+
"created_at": "2019-08-24T14:15:22Z",
511+
"email": "user@example.com",
512+
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
513+
"last_seen_at": "2019-08-24T14:15:22Z",
514+
"organization_ids": ["497f6eca-6276-4993-bfeb-53cbbbba6f08"],
515+
"roles": [
516+
{
517+
"display_name": "string",
518+
"name": "string"
519+
}
520+
],
521+
"status": "active",
522+
"username": "string"
523+
}
524+
```
525+
526+
### Responses
527+
528+
| Status | Meaning | Description | Schema |
529+
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------- |
530+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.User](schemas.md#codersdkuser) |
531+
532+
To perform this operation, you must be authenticated. [Learn more](authentication.md).

0 commit comments

Comments
 (0)