refactor: create tasks in coderd instead of frontend (#19280)

Instead of creating tasks with a specialized call to `CreateWorkspace`
on the frontend, we instead lift this to the backend and allow the
frontend to simply call `CreateAITask`.
This commit is contained in:
Danielle Maywood
2025-08-12 11:23:55 +01:00
committed by GitHub
parent cda1a3a593
commit f349edcc3c
14 changed files with 362 additions and 4 deletions
+11
View File
@@ -2863,6 +2863,17 @@ func (q *querier) GetTemplateVersionByTemplateIDAndName(ctx context.Context, arg
return tv, nil
}
func (q *querier) GetTemplateVersionHasAITask(ctx context.Context, id uuid.UUID) (bool, error) {
// If we can successfully call `GetTemplateVersionByID`, then
// we know the actor has sufficient permissions to know if the
// template has an AI task.
if _, err := q.GetTemplateVersionByID(ctx, id); err != nil {
return false, err
}
return q.db.GetTemplateVersionHasAITask(ctx, id)
}
func (q *querier) GetTemplateVersionParameters(ctx context.Context, templateVersionID uuid.UUID) ([]database.TemplateVersionParameter, error) {
// An actor can read template version parameters if they can read the related template.
tv, err := q.db.GetTemplateVersionByID(ctx, templateVersionID)
+14
View File
@@ -1443,6 +1443,20 @@ func (s *MethodTestSuite) TestTemplate() {
})
check.Args(now.Add(-time.Hour)).Asserts(rbac.ResourceTemplate.All(), policy.ActionRead)
}))
s.Run("GetTemplateVersionHasAITask", s.Subtest(func(db database.Store, check *expects) {
o := dbgen.Organization(s.T(), db, database.Organization{})
u := dbgen.User(s.T(), db, database.User{})
t := dbgen.Template(s.T(), db, database.Template{
OrganizationID: o.ID,
CreatedBy: u.ID,
})
tv := dbgen.TemplateVersion(s.T(), db, database.TemplateVersion{
OrganizationID: o.ID,
TemplateID: uuid.NullUUID{UUID: t.ID, Valid: true},
CreatedBy: u.ID,
})
check.Args(tv.ID).Asserts(t, policy.ActionRead)
}))
s.Run("GetTemplatesWithFilter", s.Subtest(func(db database.Store, check *expects) {
o := dbgen.Organization(s.T(), db, database.Organization{})
u := dbgen.User(s.T(), db, database.User{})