mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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)
|
||||
|
||||
@@ -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{})
|
||||
|
||||
Reference in New Issue
Block a user