Skip to content

Commit 6761671

Browse files
committed
some recursion fixes, fix GetTemplateVersionByJobID when template does not exist
1 parent 6eda48b commit 6761671

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

coderd/authzquery/parameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (q *AuthzQuerier) GetParameterSchemasByJobID(ctx context.Context, jobID uui
124124
if err != nil {
125125
return nil, err
126126
}
127-
return q.GetParameterSchemasByJobID(ctx, jobID)
127+
return q.database.GetParameterSchemasByJobID(ctx, jobID)
128128
}
129129

130130
func (q *AuthzQuerier) GetParameterValueByScopeAndName(ctx context.Context, arg database.GetParameterValueByScopeAndNameParams) (database.ParameterValue, error) {

coderd/authzquery/template.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func (q *AuthzQuerier) GetTemplateVersionByID(ctx context.Context, tvid uuid.UUI
5858
// An actor can read the template version if they can read the related template.
5959
fetchRelated := func(tv database.TemplateVersion, _ uuid.UUID) (rbac.Objecter, error) {
6060
if !tv.TemplateID.Valid {
61-
// If no linked template exists, check if the actor can read a template in the organization.
61+
// If no linked template exists, check if the actor can read a template
62+
// in the organization.
6263
return rbac.ResourceTemplate.InOrg(tv.OrganizationID), nil
6364
}
6465
return q.database.GetTemplateByID(ctx, tv.TemplateID.UUID)
@@ -73,7 +74,12 @@ func (q *AuthzQuerier) GetTemplateVersionByID(ctx context.Context, tvid uuid.UUI
7374

7475
func (q *AuthzQuerier) GetTemplateVersionByJobID(ctx context.Context, jobID uuid.UUID) (database.TemplateVersion, error) {
7576
// An actor can read the template version if they can read the related template.
76-
fetchRelated := func(tv database.TemplateVersion, _ uuid.UUID) (database.Template, error) {
77+
fetchRelated := func(tv database.TemplateVersion, _ uuid.UUID) (rbac.Objecter, error) {
78+
if !tv.TemplateID.Valid {
79+
// If no linked template exists, check if the actor can read a
80+
// template in the organization.
81+
return rbac.ResourceTemplate.InOrg(tv.OrganizationID), nil
82+
}
7783
return q.database.GetTemplateByID(ctx, tv.TemplateID.UUID)
7884
}
7985
return authorizedQueryWithRelated(

coderd/authzquery/workspace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func (q *AuthzQuerier) UpdateWorkspaceBuildByID(ctx context.Context, arg databas
402402
return database.WorkspaceBuild{}, err
403403
}
404404

405-
return q.UpdateWorkspaceBuildByID(ctx, arg)
405+
return q.database.UpdateWorkspaceBuildByID(ctx, arg)
406406
}
407407

408408
func (q *AuthzQuerier) SoftDeleteWorkspaceByID(ctx context.Context, id uuid.UUID) error {

0 commit comments

Comments
 (0)