Skip to content

Commit 7aa0f65

Browse files
committed
Members
1 parent 77815d3 commit 7aa0f65

15 files changed

+1195
-138
lines changed

coderd/apidoc/docs.go

Lines changed: 316 additions & 19 deletions
Large diffs are not rendered by default.

coderd/apidoc/swagger.json

Lines changed: 292 additions & 19 deletions
Large diffs are not rendered by default.

coderd/members.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ import (
1616
"github.com/coder/coder/codersdk"
1717
)
1818

19+
// @Summary Assign role to organization member
20+
// @ID assign-role-to-organization-member
21+
// @Security CoderSessionToken
22+
// @Accept json
23+
// @Produce json
24+
// @Tags Members
25+
// @Param request body codersdk.UpdateRoles true "Update roles request"
26+
// @Param organization path string true "Organization ID"
27+
// @Param user path string true "Username, UUID, or me"
28+
// @Success 200 {object} codersdk.OrganizationMember
29+
// @Router /organizations/{organization}/members/{user}/roles [put]
1930
func (api *API) putMemberRoles(rw http.ResponseWriter, r *http.Request) {
2031
var (
2132
ctx = r.Context()

coderd/organizations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
// @Security CoderSessionToken
2222
// @Produce json
2323
// @Tags Organizations
24-
// @Param id path string true "Organization ID" format(uuid)
24+
// @Param organization path string true "Organization ID" format(uuid)
2525
// @Success 200 {object} codersdk.Organization
26-
// @Router /organizations/{id} [get]
26+
// @Router /organizations/{organization} [get]
2727
func (api *API) organization(rw http.ResponseWriter, r *http.Request) {
2828
ctx := r.Context()
2929
organization := httpmw.OrganizationParam(r)

coderd/roles.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ func (api *API) assignableSiteRoles(rw http.ResponseWriter, r *http.Request) {
2323
httpapi.Write(ctx, rw, http.StatusOK, assignableRoles(actorRoles.Roles, roles))
2424
}
2525

26+
// @Summary Get member roles by organization
27+
// @ID get-member-roles-by-organization
28+
// @Security CoderSessionToken
29+
// @Produce json
30+
// @Tags Members
31+
// @Param organization path string true "Organization ID" format(uuid)
32+
// @Success 200 {array} codersdk.AssignableRoles
33+
// @Router /organizations/{organization}/members/roles [get]
34+
//
2635
// assignableSiteRoles returns all site wide roles that can be assigned.
2736
func (api *API) assignableOrgRoles(rw http.ResponseWriter, r *http.Request) {
2837
ctx := r.Context()

coderd/templates.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ func (api *API) deleteTemplate(rw http.ResponseWriter, r *http.Request) {
149149
// @Produce json
150150
// @Tags Templates
151151
// @Param request body codersdk.CreateTemplateRequest true "Request body"
152-
// @Param organization-id path string true "Organization ID"
152+
// @Param organization path string true "Organization ID"
153153
// @Success 200 {object} codersdk.Template
154-
// @Router /organizations/{organization-id}/templates/ [post]
154+
// @Router /organizations/{organization}/templates [post]
155155
// Returns a single template.
156156
// Create a new template in an organization.
157157
func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Request) {
@@ -347,7 +347,7 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
347347
// @Produce json
348348
// @Tags Templates
349349
// @Param organization path string true "Organization ID" format(uuid)
350-
// @Success 200 {object} []codersdk.Template
350+
// @Success 200 {array} codersdk.Template
351351
// @Router /organizations/{organization}/templates [get]
352352
func (api *API) templatesByOrganization(rw http.ResponseWriter, r *http.Request) {
353353
ctx := r.Context()
@@ -413,9 +413,9 @@ func (api *API) templatesByOrganization(rw http.ResponseWriter, r *http.Request)
413413
// @Produce json
414414
// @Tags Templates
415415
// @Param organization path string true "Organization ID" format(uuid)
416-
// @Param template-name path string true "Template name"
416+
// @Param templatename path string true "Template name"
417417
// @Success 200 {object} codersdk.Template
418-
// @Router /organizations/{organization}/templates/{template-name} [get]
418+
// @Router /organizations/{organization}/templates/{templatename} [get]
419419
func (api *API) templateByOrganizationAndName(rw http.ResponseWriter, r *http.Request) {
420420
ctx := r.Context()
421421
organization := httpmw.OrganizationParam(r)
@@ -625,6 +625,14 @@ func (api *API) templateDAUs(rw http.ResponseWriter, r *http.Request) {
625625
httpapi.Write(ctx, rw, http.StatusOK, resp)
626626
}
627627

628+
// @Summary Get template examples by organization
629+
// @ID get-template-examples-by-organization
630+
// @Security CoderSessionToken
631+
// @Produce json
632+
// @Tags Templates
633+
// @Param organization path string true "Organization ID" format(uuid)
634+
// @Success 200 {array} codersdk.TemplateExample
635+
// @Router /organizations/{organization}/templates/examples [get]
628636
func (api *API) templateExamples(rw http.ResponseWriter, r *http.Request) {
629637
var (
630638
ctx = r.Context()

coderd/templateversions.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,9 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
646646
// @Produce json
647647
// @Tags Templates
648648
// @Param id path string true "Template ID" format(uuid)
649-
// @Param name path string true "Template name"
649+
// @Param templateversionname path string true "Template version name"
650650
// @Success 200 {array} codersdk.TemplateVersion
651-
// @Router /templates/{id}/versions/{name} [get]
651+
// @Router /templates/{id}/versions/{templateversionname} [get]
652652
func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) {
653653
ctx := r.Context()
654654
template := httpmw.TemplateParam(r)
@@ -699,6 +699,15 @@ func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) {
699699
httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user))
700700
}
701701

702+
// @Summary Get template version by organization and name
703+
// @ID get-template-version-by-organization-and-name
704+
// @Security CoderSessionToken
705+
// @Produce json
706+
// @Tags Templates
707+
// @Param organization path string true "Organization ID" format(uuid)
708+
// @Param templateversionname path string true "Template version name"
709+
// @Success 200 {object} codersdk.TemplateVersion
710+
// @Router /organizations/{organization}/templateversions/{templateversionname} [get]
702711
func (api *API) templateVersionByOrganizationAndName(rw http.ResponseWriter, r *http.Request) {
703712
ctx := r.Context()
704713
organization := httpmw.OrganizationParam(r)
@@ -741,6 +750,15 @@ func (api *API) templateVersionByOrganizationAndName(rw http.ResponseWriter, r *
741750
httpapi.Write(ctx, rw, http.StatusOK, convertTemplateVersion(templateVersion, convertProvisionerJob(job), user))
742751
}
743752

753+
// @Summary Get previous template version by organization and name
754+
// @ID get-previous-template-version-by-organization-and-name
755+
// @Security CoderSessionToken
756+
// @Produce json
757+
// @Tags Templates
758+
// @Param organization path string true "Organization ID" format(uuid)
759+
// @Param templateversionname path string true "Template version name"
760+
// @Success 200 {object} codersdk.TemplateVersion
761+
// @Router /organizations/{organization}/templateversions/{templateversionname} [get]
744762
func (api *API) previousTemplateVersionByOrganizationAndName(rw http.ResponseWriter, r *http.Request) {
745763
ctx := r.Context()
746764
organization := httpmw.OrganizationParam(r)
@@ -890,7 +908,18 @@ func (api *API) patchActiveTemplateVersion(rw http.ResponseWriter, r *http.Reque
890908
})
891909
}
892910

893-
// Creates a new version of a template. An import job is queued to parse the storage method provided.
911+
// @Summary Create template version by organization
912+
// @ID create-template-version-by-organization
913+
// @Security CoderSessionToken
914+
// @Accept json
915+
// @Produce json
916+
// @Tags Templates
917+
// @Param organization path string true "Organization ID" format(uuid)
918+
// @Param request body codersdk.CreateTemplateVersionDryRunRequest true "Create template version request"
919+
// @Success 201 {object} codersdk.TemplateVersion
920+
// @Router /organizations/{organization}/templateversions [post]
921+
//
922+
// postTemplateVersionsByOrganization creates a new version of a template. An import job is queued to parse the storage method provided.
894923
func (api *API) postTemplateVersionsByOrganization(rw http.ResponseWriter, r *http.Request) {
895924
var (
896925
ctx = r.Context()

coderd/workspaces.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,16 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
266266
))
267267
}
268268

269-
// @Summary Create workspace by organization
270-
// @ID create-workspace-by-organization
269+
// @Summary Create user workspace by organization
270+
// @ID create-user-workspace-by-organization
271271
// @Security CoderSessionToken
272272
// @Produce json
273273
// @Tags Workspaces
274274
// @Param organization path string true "Organization ID" format(uuid)
275-
// @Param user path string true "Username"
275+
// @Param user path string true "Username, UUID, or me"
276276
// @Success 200 {object} codersdk.Workspace
277277
// @Router /organizations/{organization}/members/{user}/workspaces [post]
278+
//
278279
// Create a new workspace for the currently authenticated user.
279280
func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Request) {
280281
var (

codersdk/organizationmember.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
type OrganizationMember struct {
10-
UserID uuid.UUID `db:"user_id" json:"user_id"`
11-
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id"`
12-
CreatedAt time.Time `db:"created_at" json:"created_at"`
13-
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
10+
UserID uuid.UUID `db:"user_id" json:"user_id" format:"uuid"`
11+
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id" format:"uuid"`
12+
CreatedAt time.Time `db:"created_at" json:"created_at" format:"date-time"`
13+
UpdatedAt time.Time `db:"updated_at" json:"updated_at" format:"date-time"`
1414
Roles []Role `db:"roles" json:"roles"`
1515
}

docs/api/members.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Members
2+
3+
> This page is incomplete, stay tuned.
4+
5+
## Get member roles by organization
6+
7+
### Code samples
8+
9+
```shell
10+
# Example request using curl
11+
curl -X GET http://coder-server:8080/api/v2/organizations/{organization}/members/roles \
12+
-H 'Accept: application/json' \
13+
-H 'Coder-Session-Token: API_KEY'
14+
```
15+
16+
`GET /organizations/{organization}/members/roles`
17+
18+
### Parameters
19+
20+
| Name | In | Type | Required | Description |
21+
| -------------- | ---- | ------------ | -------- | --------------- |
22+
| `organization` | path | string(uuid) | true | Organization ID |
23+
24+
### Example responses
25+
26+
> 200 Response
27+
28+
```json
29+
[
30+
{
31+
"assignable": true,
32+
"display_name": "string",
33+
"name": "string"
34+
}
35+
]
36+
```
37+
38+
### Responses
39+
40+
| Status | Meaning | Description | Schema |
41+
| ------ | ------------------------------------------------------- | ----------- | ----------------------------------------------------------------------- |
42+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of [codersdk.AssignableRoles](schemas.md#codersdkassignableroles) |
43+
44+
<h3 id="get-member-roles-by-organization-responseschema">Response Schema</h3>
45+
46+
Status Code **200**
47+
48+
| Name | Type | Required | Restrictions | Description |
49+
| ---------------- | ------- | -------- | ------------ | ----------- |
50+
| `[array item]` | array | false | | |
51+
| `» assignable` | boolean | false | | |
52+
| `» display_name` | string | false | | |
53+
| `» name` | string | false | | |
54+
55+
To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.
56+
57+
## Assign role to organization member
58+
59+
### Code samples
60+
61+
```shell
62+
# Example request using curl
63+
curl -X PUT http://coder-server:8080/api/v2/organizations/{organization}/members/{user}/roles \
64+
-H 'Content-Type: application/json' \
65+
-H 'Accept: application/json' \
66+
-H 'Coder-Session-Token: API_KEY'
67+
```
68+
69+
`PUT /organizations/{organization}/members/{user}/roles`
70+
71+
> Body parameter
72+
73+
```json
74+
{
75+
"roles": ["string"]
76+
}
77+
```
78+
79+
### Parameters
80+
81+
| Name | In | Type | Required | Description |
82+
| -------------- | ---- | ------------------------------------------------------ | -------- | --------------------- |
83+
| `organization` | path | string | true | Organization ID |
84+
| `user` | path | string | true | Username, UUID, or me |
85+
| `body` | body | [codersdk.UpdateRoles](schemas.md#codersdkupdateroles) | true | Update roles request |
86+
87+
### Example responses
88+
89+
> 200 Response
90+
91+
```json
92+
{
93+
"created_at": "2019-08-24T14:15:22Z",
94+
"organization_id": "7c60d51f-b44e-4682-87d6-449835ea4de6",
95+
"roles": [
96+
{
97+
"display_name": "string",
98+
"name": "string"
99+
}
100+
],
101+
"updated_at": "2019-08-24T14:15:22Z",
102+
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
103+
}
104+
```
105+
106+
### Responses
107+
108+
| Status | Meaning | Description | Schema |
109+
| ------ | ------------------------------------------------------- | ----------- | -------------------------------------------------------------------- |
110+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.OrganizationMember](schemas.md#codersdkorganizationmember) |
111+
112+
To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.

docs/api/organizations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ To perform this operation, you must be authenticated by means of one of the foll
5757

5858
```shell
5959
# Example request using curl
60-
curl -X GET http://coder-server:8080/api/v2/organizations/{id} \
60+
curl -X GET http://coder-server:8080/api/v2/organizations/{organization} \
6161
-H 'Accept: application/json' \
6262
-H 'Coder-Session-Token: API_KEY'
6363
```
6464

65-
`GET /organizations/{id}`
65+
`GET /organizations/{organization}`
6666

6767
### Parameters
6868

69-
| Name | In | Type | Required | Description |
70-
| ---- | ---- | ------------ | -------- | --------------- |
71-
| `id` | path | string(uuid) | true | Organization ID |
69+
| Name | In | Type | Required | Description |
70+
| -------------- | ---- | ------------ | -------- | --------------- |
71+
| `organization` | path | string(uuid) | true | Organization ID |
7272

7373
### Example responses
7474

0 commit comments

Comments
 (0)