@@ -176,13 +176,35 @@ func (q *sqlQuerier) GetTemplateGroupRoles(ctx context.Context, id uuid.UUID) ([
176
176
}
177
177
178
178
type workspaceQuerier interface {
179
- GetAuthorizedWorkspaces (ctx context.Context , arg GetWorkspacesParams , prepared rbac.PreparedAuthorized ) ([]GetWorkspacesRow , error )
179
+ GetAuthorizedWorkspaces (ctx context.Context , arg GetWorkspacesParams , prepared rbac.PreparedAuthorized ) ([]WorkspaceWithData , error )
180
+ }
181
+
182
+ // WorkspaceWithData includes information returned by the api for a workspace.
183
+ type WorkspaceWithData struct {
184
+ Workspace
185
+
186
+ // These template fields are included in the response for a workspace.
187
+ // This means if you can read a workspace, you can also read these limited
188
+ // template fields as they are metadata of the workspace.
189
+ TemplateName string
190
+ TemplateIcon string
191
+ TemplateDisplayName string
192
+ TemplateAllowUserCancelWorkspaceJobs bool
193
+ TemplateActiveVersionID uuid.UUID
194
+
195
+ LatestBuild WorkspaceBuild
196
+ LatestBuildJob ProvisionerJob
197
+
198
+ // Count is the total number of workspaces applicable to the query.
199
+ // This is used for pagination as the total number of returned workspaces
200
+ // could be less than this number.
201
+ Count int64 `db:"count" json:"count"`
180
202
}
181
203
182
204
// GetAuthorizedWorkspaces returns all workspaces that the user is authorized to access.
183
205
// This code is copied from `GetWorkspaces` and adds the authorized filter WHERE
184
206
// clause.
185
- func (q * sqlQuerier ) GetAuthorizedWorkspaces (ctx context.Context , arg GetWorkspacesParams , prepared rbac.PreparedAuthorized ) ([]GetWorkspacesRow , error ) {
207
+ func (q * sqlQuerier ) GetAuthorizedWorkspaces (ctx context.Context , arg GetWorkspacesParams , prepared rbac.PreparedAuthorized ) ([]WorkspaceWithData , error ) {
186
208
authorizedFilter , err := prepared .CompileToSQL (ctx , rbac .ConfigWithoutACL ())
187
209
if err != nil {
188
210
return nil , xerrors .Errorf ("compile authorized filter: %w" , err )
@@ -204,6 +226,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
204
226
arg .OwnerUsername ,
205
227
arg .TemplateName ,
206
228
pq .Array (arg .TemplateIds ),
229
+ pq .Array (arg .WorkspaceIds ),
207
230
arg .Name ,
208
231
arg .HasAgent ,
209
232
arg .AgentInactiveDisconnectTimeoutSeconds ,
@@ -214,9 +237,9 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
214
237
return nil , xerrors .Errorf ("get authorized workspaces: %w" , err )
215
238
}
216
239
defer rows .Close ()
217
- var items []GetWorkspacesRow
240
+ var items []WorkspaceWithData
218
241
for rows .Next () {
219
- var i GetWorkspacesRow
242
+ var i WorkspaceWithData
220
243
if err := rows .Scan (
221
244
& i .ID ,
222
245
& i .CreatedAt ,
@@ -229,6 +252,35 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
229
252
& i .AutostartSchedule ,
230
253
& i .Ttl ,
231
254
& i .LastUsedAt ,
255
+ & i .TemplateName ,
256
+ & i .TemplateIcon ,
257
+ & i .TemplateDisplayName ,
258
+ & i .TemplateAllowUserCancelWorkspaceJobs ,
259
+ & i .TemplateActiveVersionID ,
260
+ & i .LatestBuild .ID ,
261
+ & i .LatestBuild .CreatedAt ,
262
+ & i .LatestBuild .UpdatedAt ,
263
+ & i .LatestBuild .TemplateVersionID ,
264
+ & i .LatestBuild .BuildNumber ,
265
+ & i .LatestBuild .Transition ,
266
+ & i .LatestBuild .JobID ,
267
+ & i .LatestBuild .InitiatorID ,
268
+ & i .LatestBuild .Reason ,
269
+ & i .LatestBuild .DailyCost ,
270
+ & i .LatestBuildJob .ID ,
271
+ & i .LatestBuildJob .CreatedAt ,
272
+ & i .LatestBuildJob .UpdatedAt ,
273
+ & i .LatestBuildJob .StartedAt ,
274
+ & i .LatestBuildJob .CompletedAt ,
275
+ & i .LatestBuildJob .CanceledAt ,
276
+ & i .LatestBuildJob .Error ,
277
+ & i .LatestBuildJob .OrganizationID ,
278
+ & i .LatestBuildJob .Provisioner ,
279
+ & i .LatestBuildJob .StorageMethod ,
280
+ & i .LatestBuildJob .Type ,
281
+ & i .LatestBuildJob .WorkerID ,
282
+ & i .LatestBuildJob .FileID ,
283
+ & i .LatestBuildJob .Tags ,
232
284
& i .Count ,
233
285
); err != nil {
234
286
return nil , err
0 commit comments