Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(coderd): alter return signature of convertWorkspace, add check for requesterID#11796

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 1 commit intomainfromcj/convert-workspaces-requester-id
Jan 24, 2024
Merged
Changes fromall commits
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
93 changes: 73 additions & 20 deletionscoderd/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,14 +102,23 @@ func (api *API) workspace(rw http.ResponseWriter, r *http.Request) {
})
return
}
httpapi.Write(ctx, rw, http.StatusOK, convertWorkspace(

w, err := convertWorkspace(
apiKey.UserID,
workspace,
data.builds[0],
data.templates[0],
ownerName,
api.Options.AllowWorkspaceRenames,
))
)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error converting workspace.",
Detail: err.Error(),
})
return
}
httpapi.Write(ctx, rw, http.StatusOK, w)
}

// workspaces returns all workspaces a user can read.
Expand DownExpand Up@@ -280,14 +289,22 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
})
return
}
httpapi.Write(ctx, rw, http.StatusOK, convertWorkspace(
w, err := convertWorkspace(
apiKey.UserID,
workspace,
data.builds[0],
data.templates[0],
ownerName,
api.Options.AllowWorkspaceRenames,
))
)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error converting workspace.",
Detail: err.Error(),
})
return
}
httpapi.Write(ctx, rw, http.StatusOK, w)
}

// Create a new workspace for the currently authenticated user.
Expand DownExpand Up@@ -590,14 +607,22 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
return
}

httpapi.Write(ctx, rw, http.StatusCreated, convertWorkspace(
w, err := convertWorkspace(
apiKey.UserID,
workspace,
apiBuild,
template,
member.Username,
api.Options.AllowWorkspaceRenames,
))
)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error converting workspace.",
Detail: err.Error(),
})
return
}
httpapi.Write(ctx, rw, http.StatusCreated, w)
}

// @Summary Update workspace metadata by ID
Expand DownExpand Up@@ -931,14 +956,23 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
}

aReq.New = workspace
httpapi.Write(ctx, rw, http.StatusOK, convertWorkspace(

w, err := convertWorkspace(
apiKey.UserID,
workspace,
data.builds[0],
data.templates[0],
ownerName,
api.Options.AllowWorkspaceRenames,
))
)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error converting workspace.",
Detail: err.Error(),
})
return
}
httpapi.Write(ctx, rw, http.StatusOK, w)
}

// @Summary Extend workspace deadline by ID
Expand DownExpand Up@@ -1349,16 +1383,27 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
})
return
}

w, err := convertWorkspace(
apiKey.UserID,
workspace,
data.builds[0],
data.templates[0],
ownerName,
api.Options.AllowWorkspaceRenames,
)
if err != nil {
_ = sendEvent(ctx, codersdk.ServerSentEvent{
Type: codersdk.ServerSentEventTypeError,
Data: codersdk.Response{
Message: "Internal error converting workspace.",
Detail: err.Error(),
},
})
}
_ = sendEvent(ctx, codersdk.ServerSentEvent{
Type: codersdk.ServerSentEventTypeData,
Data: convertWorkspace(
apiKey.UserID,
workspace,
data.builds[0],
data.templates[0],
ownerName,
api.Options.AllowWorkspaceRenames,
),
Data: w,
})
}

Expand DownExpand Up@@ -1505,14 +1550,19 @@ func convertWorkspaces(requesterID uuid.UUID, workspaces []database.Workspace, d
continue
}

apiWorkspaces = append(apiWorkspaces, convertWorkspace(
w, err := convertWorkspace(
requesterID,
workspace,
build,
template,
owner.Username,
data.allowRenames,
))
)
if err != nil {
return nil, xerrors.Errorf("convert workspace: %w", err)
}

apiWorkspaces = append(apiWorkspaces, w)
}
return apiWorkspaces, nil
}
Expand All@@ -1524,7 +1574,10 @@ func convertWorkspace(
template database.Template,
ownerName string,
allowRenames bool,
) codersdk.Workspace {
) (codersdk.Workspace, error) {
if requesterID == uuid.Nil {
return codersdk.Workspace{}, xerrors.Errorf("developer error: requesterID cannot be uuid.Nil!")
}
var autostartSchedule *string
if workspace.AutostartSchedule.Valid {
autostartSchedule = &workspace.AutostartSchedule.String
Expand DownExpand Up@@ -1583,7 +1636,7 @@ func convertWorkspace(
AutomaticUpdates: codersdk.AutomaticUpdates(workspace.AutomaticUpdates),
AllowRenames: allowRenames,
Favorite: requesterFavorite,
}
}, nil
}

func convertWorkspaceTTLMillis(i sql.NullInt64) *int64 {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp