Skip to content

chore(coderd): allow creating workspaces without specifying an organization #14048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🧼
  • Loading branch information
aslilac committed Jul 29, 2024
commit a96ae89668ef141a92efce5ddef4dbe18d7e07a6
2 changes: 1 addition & 1 deletion coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/coderdtest/swaggerparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func parseSwaggerComment(commentGroup *ast.CommentGroup) SwaggerComment {
failures: []response{},
}
for _, line := range commentGroup.List {
// @<annotationName> [args...]
// "// @<annotationName> [args...]" -> []string{"//", "@<annotationName>", "args..."}
splitN := strings.SplitN(strings.TrimSpace(line.Text), " ", 3)
if len(splitN) < 2 {
if len(splitN) < 3 {
continue // comment prefix without any content
}

Expand Down
4 changes: 2 additions & 2 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
// @Description specify either the Template ID or the Template Version ID,
// @Description not both. If the Template ID is specified, the active version
// @Description of the template will be used.
// @Deprecated
// @Deprecated Use /users/{user}/workspaces instead.
// @ID create-user-workspace-by-organization
// @Security CoderSessionToken
// @Accept json
Expand Down Expand Up @@ -397,7 +397,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req

// Create a new workspace for the currently authenticated user.
//
// @Summary Create user workspace by organization
// @Summary Create user workspace
// @Description Create a new workspace using a template. The request must
// @Description specify either the Template ID or the Template Version ID,
// @Description not both. If the Template ID is specified, the active version
Expand Down
18 changes: 18 additions & 0 deletions codersdk/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ func (c *Client) TemplateByName(ctx context.Context, organizationID uuid.UUID, n
}

// CreateWorkspace creates a new workspace for the template specified.
//
// Deprecated: Use CreateUserWorkspace instead.
func (c *Client) CreateWorkspace(ctx context.Context, organizationID uuid.UUID, user string, request CreateWorkspaceRequest) (Workspace, error) {
res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/organizations/%s/members/%s/workspaces", organizationID, user), request)
if err != nil {
Expand All @@ -487,3 +489,19 @@ func (c *Client) CreateWorkspace(ctx context.Context, organizationID uuid.UUID,
var workspace Workspace
return workspace, json.NewDecoder(res.Body).Decode(&workspace)
}

// CreateUserWorkspace creates a new workspace for the template specified.
func (c *Client) CreateUserWorkspace(ctx context.Context, user string, request CreateWorkspaceRequest) (Workspace, error) {
res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/users/%s/workspaces", user), request)
if err != nil {
return Workspace{}, err
}
defer res.Body.Close()

if res.StatusCode != http.StatusCreated {
return Workspace{}, ReadBodyAsError(res)
}

var workspace Workspace
return workspace, json.NewDecoder(res.Body).Decode(&workspace)
}
252 changes: 246 additions & 6 deletions docs/api/workspaces.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions enterprise/coderd/coderdenttest/swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@

"github.com/stretchr/testify/require"

"fmt"

"github.com/coder/coder/v2/coderd/coderdtest"
"github.com/coder/coder/v2/enterprise/coderd/coderdenttest"
)

func TestEnterpriseEndpointsDocumented(t *testing.T) {
t.Parallel()

fmt.Println("wtf")

Check failure on line 17 in enterprise/coderd/coderdenttest/swagger_test.go

View workflow job for this annotation

GitHub Actions / lint

unhandled-error: Unhandled error in call to function fmt.Println (revive)
swaggerComments, err := coderdtest.ParseSwaggerComments("..", "../../../coderd")
require.NoError(t, err, "can't parse swagger comments")
require.NotEmpty(t, swaggerComments, "swagger comments must be present")
fmt.Println("wtf2")

Check failure on line 21 in enterprise/coderd/coderdenttest/swagger_test.go

View workflow job for this annotation

GitHub Actions / lint

unhandled-error: Unhandled error in call to function fmt.Println (revive)

//nolint: dogsled
_, _, api, _ := coderdenttest.NewWithAPI(t, nil)
fmt.Println("wtf3")

Check failure on line 25 in enterprise/coderd/coderdenttest/swagger_test.go

View workflow job for this annotation

GitHub Actions / lint

unhandled-error: Unhandled error in call to function fmt.Println (revive)
coderdtest.VerifySwaggerDefinitions(t, api.AGPL.APIHandler, swaggerComments)
fmt.Println("wtf4")

Check failure on line 27 in enterprise/coderd/coderdenttest/swagger_test.go

View workflow job for this annotation

GitHub Actions / lint

unhandled-error: Unhandled error in call to function fmt.Println (revive)
}
2 changes: 1 addition & 1 deletion enterprise/coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestCreateWorkspace(t *testing.T) {
require.Error(t, err)
var apiErr *codersdk.Error
require.ErrorAs(t, err, &apiErr)
require.Equal(t, http.StatusForbidden, apiErr.StatusCode())
require.Equal(t, http.StatusNotAcceptable, apiErr.StatusCode())
})

// Test that a user cannot indirectly access
Expand Down
Loading