MCPcopy Index your code
hub / github.com/coder/coder / GetAuthorizedWorkspaces

Method GetAuthorizedWorkspaces

coderd/database/modelqueries.go:244–349  ·  view source on GitHub ↗

GetAuthorizedWorkspaces returns all workspaces that the user is authorized to access. This code is copied from `GetWorkspaces` and adds the authorized filter WHERE clause.

(ctx context.Context, arg GetWorkspacesParams, prepared rbac.PreparedAuthorized)

Source from the content-addressed store, hash-verified

242// This code is copied from `GetWorkspaces` and adds the authorized filter WHERE
243// clause.
244func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspacesParams, prepared rbac.PreparedAuthorized) ([]GetWorkspacesRow, error) {
245 authorizedFilter, err := prepared.CompileToSQL(ctx, rbac.ConfigWorkspaces())
246 if err != nil {
247 return nil, xerrors.Errorf("compile authorized filter: %w", err)
248 }
249
250 // In order to properly use ORDER BY, OFFSET, and LIMIT, we need to inject the
251 // authorizedFilter between the end of the where clause and those statements.
252 filtered, err := insertAuthorizedFilter(getWorkspaces, fmt.Sprintf(" AND %s", authorizedFilter))
253 if err != nil {
254 return nil, xerrors.Errorf("insert authorized filter: %w", err)
255 }
256
257 // The name comment is for metric tracking
258 query := fmt.Sprintf("-- name: GetAuthorizedWorkspaces :many\n%s", filtered)
259 rows, err := q.db.QueryContext(ctx, query,
260 pq.Array(arg.ParamNames),
261 pq.Array(arg.ParamValues),
262 arg.Deleted,
263 arg.Status,
264 arg.OwnerID,
265 arg.OrganizationID,
266 pq.Array(arg.HasParam),
267 arg.OwnerUsername,
268 arg.TemplateName,
269 pq.Array(arg.TemplateIDs),
270 pq.Array(arg.WorkspaceIds),
271 arg.Name,
272 pq.Array(arg.HasAgentStatuses),
273 arg.AgentInactiveDisconnectTimeoutSeconds,
274 arg.Dormant,
275 arg.LastUsedBefore,
276 arg.LastUsedAfter,
277 arg.UsingActive,
278 arg.HasAITask,
279 arg.HasExternalAgent,
280 arg.Shared,
281 arg.SharedWithUserID,
282 arg.SharedWithGroupID,
283 arg.RequesterID,
284 arg.Offset,
285 arg.Limit,
286 arg.WithSummary,
287 )
288 if err != nil {
289 return nil, err
290 }
291 defer rows.Close()
292 var items []GetWorkspacesRow
293 for rows.Next() {
294 var i GetWorkspacesRow
295 if err := rows.Scan(
296 &i.ID,
297 &i.CreatedAt,
298 &i.UpdatedAt,
299 &i.OwnerID,
300 &i.OrganizationID,
301 &i.TemplateID,

Callers

nothing calls this directly

Calls 9

ConfigWorkspacesFunction · 0.92
insertAuthorizedFilterFunction · 0.85
QueryContextMethod · 0.80
ErrMethod · 0.80
CompileToSQLMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.65
ErrorfMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected