Skip to content

chore: add template_with_user view to include user contextual data #8568

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 19, 2023
Merged
Prev Previous commit
clarify function name, wrap an error
  • Loading branch information
Emyrk committed Jul 19, 2023
commit 107bb45b016ca0a7769f04d3f2bab69bce42e77e
14 changes: 7 additions & 7 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,21 +446,21 @@ func (q *FakeQuerier) getLatestWorkspaceBuildByWorkspaceIDNoLock(_ context.Conte
func (q *FakeQuerier) getTemplateByIDNoLock(_ context.Context, id uuid.UUID) (database.Template, error) {
for _, template := range q.templates {
if template.ID == id {
return q.templateWithUser(template), nil
return q.templateWithUserNoLock(template), nil
}
}
return database.Template{}, sql.ErrNoRows
}

func (q *FakeQuerier) templatesWithUser(tpl []database.TemplateTable) []database.Template {
func (q *FakeQuerier) templatesWithUserNoLock(tpl []database.TemplateTable) []database.Template {
cpy := make([]database.Template, 0, len(tpl))
for _, t := range tpl {
cpy = append(cpy, q.templateWithUser(t))
cpy = append(cpy, q.templateWithUserNoLock(t))
}
return cpy
}

func (q *FakeQuerier) templateWithUser(tpl database.TemplateTable) database.Template {
func (q *FakeQuerier) templateWithUserNoLock(tpl database.TemplateTable) database.Template {
var user database.User
for _, _user := range q.users {
if _user.ID == tpl.CreatedBy {
Expand Down Expand Up @@ -1894,7 +1894,7 @@ func (q *FakeQuerier) GetTemplateByOrganizationAndName(_ context.Context, arg da
if template.Deleted != arg.Deleted {
continue
}
return q.templateWithUser(template), nil
return q.templateWithUserNoLock(template), nil
}
return database.Template{}, sql.ErrNoRows
}
Expand Down Expand Up @@ -2124,7 +2124,7 @@ func (q *FakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
return i.ID.String() < j.ID.String()
})

return q.templatesWithUser(templates), nil
return q.templatesWithUserNoLock(templates), nil
}

func (q *FakeQuerier) GetTemplatesWithFilter(ctx context.Context, arg database.GetTemplatesWithFilterParams) ([]database.Template, error) {
Expand Down Expand Up @@ -5007,7 +5007,7 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G

var templates []database.Template
for _, templateTable := range q.templates {
template := q.templateWithUser(templateTable)
template := q.templateWithUserNoLock(templateTable)
if prepared != nil && prepared.Authorize(ctx, template.RBACObject()) != nil {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (*agplTemplateScheduleStore) SetTemplateScheduleOptions(ctx context.Context
LockedTTL: tpl.LockedTTL,
})
if err != nil {
return err
return xerrors.Errorf("update template schedule: %w", err)
}

template, err = db.GetTemplateByID(ctx, tpl.ID)
Expand Down