(ctx context.Context, arg database.InsertWorkspaceBuildParams)
| 6003 | } |
| 6004 | |
| 6005 | func (q *querier) InsertWorkspaceBuild(ctx context.Context, arg database.InsertWorkspaceBuildParams) error { |
| 6006 | w, err := q.db.GetWorkspaceByID(ctx, arg.WorkspaceID) |
| 6007 | if err != nil { |
| 6008 | return xerrors.Errorf("get workspace by id: %w", err) |
| 6009 | } |
| 6010 | |
| 6011 | action, err := workspaceTransitionAction(arg.Transition) |
| 6012 | if err != nil { |
| 6013 | return err |
| 6014 | } |
| 6015 | |
| 6016 | // Special handling for prebuilt workspace deletion |
| 6017 | if err := q.authorizePrebuiltWorkspace(ctx, action, w); err != nil { |
| 6018 | return err |
| 6019 | } |
| 6020 | |
| 6021 | // If we're starting a workspace we need to check the template. |
| 6022 | if arg.Transition == database.WorkspaceTransitionStart { |
| 6023 | t, err := q.db.GetTemplateByID(ctx, w.TemplateID) |
| 6024 | if err != nil { |
| 6025 | return xerrors.Errorf("get template by id: %w", err) |
| 6026 | } |
| 6027 | |
| 6028 | accessControl := (*q.acs.Load()).GetTemplateAccessControl(t) |
| 6029 | |
| 6030 | // If the template requires the active version we need to check if |
| 6031 | // the user is a template admin. If they aren't and are attempting |
| 6032 | // to use a non-active version then we must fail the request. |
| 6033 | if accessControl.RequireActiveVersion { |
| 6034 | if arg.TemplateVersionID != t.ActiveVersionID { |
| 6035 | if err = q.authorizeContext(ctx, policy.ActionUpdate, t); err != nil { |
| 6036 | return xerrors.Errorf("cannot use non-active version: %w", err) |
| 6037 | } |
| 6038 | } |
| 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | return q.db.InsertWorkspaceBuild(ctx, arg) |
| 6043 | } |
| 6044 | |
| 6045 | func (q *querier) InsertWorkspaceBuildParameters(ctx context.Context, arg database.InsertWorkspaceBuildParametersParams) error { |
| 6046 | // TODO: Optimize this. We always have the workspace and build already fetched. |
nothing calls this directly
no test coverage detected