- Notifications
You must be signed in to change notification settings - Fork1.1k
chore: addtemplate_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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
229d7703f2a8ddb3d51991eaa49fca1a3bbcffbb611219f2a5b6d046664a81a457322ac2aa8c472097c552259914715f52d115920fc4a400107bb45File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -58,7 +58,7 @@ func New() database.Store { | ||
| workspaceResourceMetadata: make([]database.WorkspaceResourceMetadatum, 0), | ||
| provisionerJobs: make([]database.ProvisionerJob, 0), | ||
| templateVersions: make([]database.TemplateVersion, 0), | ||
| templates: make([]database.TemplateTable, 0), | ||
| workspaceAgentStats: make([]database.WorkspaceAgentStat, 0), | ||
| workspaceAgentLogs: make([]database.WorkspaceAgentStartupLog, 0), | ||
| workspaceBuilds: make([]database.WorkspaceBuild, 0), | ||
| @@ -130,7 +130,7 @@ type data struct { | ||
| templateVersions []database.TemplateVersion | ||
| templateVersionParameters []database.TemplateVersionParameter | ||
| templateVersionVariables []database.TemplateVersionVariable | ||
| templates []database.TemplateTable | ||
| workspaceAgents []database.WorkspaceAgent | ||
| workspaceAgentMetadata []database.WorkspaceAgentMetadatum | ||
| workspaceAgentLogs []database.WorkspaceAgentStartupLog | ||
| @@ -446,12 +446,37 @@ 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 { | ||
| returnq.templateWithUserNoLock(template), nil | ||
| } | ||
| } | ||
| return database.Template{}, sql.ErrNoRows | ||
| } | ||
| func (q *FakeQuerier) templatesWithUserNoLock(tpl []database.TemplateTable) []database.Template { | ||
| cpy := make([]database.Template, 0, len(tpl)) | ||
| for _, t := range tpl { | ||
| cpy = append(cpy, q.templateWithUserNoLock(t)) | ||
| } | ||
| return cpy | ||
| } | ||
| func (q *FakeQuerier) templateWithUserNoLock(tpl database.TemplateTable) database.Template { | ||
| var user database.User | ||
| for _, _user := range q.users { | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if _user.ID == tpl.CreatedBy { | ||
| user = _user | ||
| break | ||
| } | ||
| } | ||
| var withUser database.Template | ||
| // This is a cheeky way to copy the fields over without explicitly listing them all. | ||
| d, _ := json.Marshal(tpl) | ||
| _ = json.Unmarshal(d, &withUser) | ||
Emyrk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| withUser.CreatedByUsername = user.Username | ||
| withUser.CreatedByAvatarURL = user.AvatarURL.String | ||
| return withUser | ||
| } | ||
| func (q *FakeQuerier) getTemplateVersionByIDNoLock(_ context.Context, templateVersionID uuid.UUID) (database.TemplateVersion, error) { | ||
| for _, templateVersion := range q.templateVersions { | ||
| if templateVersion.ID != templateVersionID { | ||
| @@ -1869,7 +1894,7 @@ func (q *FakeQuerier) GetTemplateByOrganizationAndName(_ context.Context, arg da | ||
| if template.Deleted != arg.Deleted { | ||
| continue | ||
| } | ||
| returnq.templateWithUserNoLock(template), nil | ||
| } | ||
| return database.Template{}, sql.ErrNoRows | ||
| } | ||
| @@ -2092,17 +2117,14 @@ func (q *FakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro | ||
| defer q.mutex.RUnlock() | ||
| templates := slices.Clone(q.templates) | ||
| slices.SortFunc(templates, func(i, j database.TemplateTable) bool { | ||
| if i.Name != j.Name { | ||
| return i.Name < j.Name | ||
| } | ||
| return i.ID.String() < j.ID.String() | ||
| }) | ||
| returnq.templatesWithUserNoLock(templates), nil | ||
| } | ||
| func (q *FakeQuerier) GetTemplatesWithFilter(ctx context.Context, arg database.GetTemplatesWithFilterParams) ([]database.Template, error) { | ||
| @@ -3436,16 +3458,16 @@ func (q *FakeQuerier) InsertReplica(_ context.Context, arg database.InsertReplic | ||
| return replica, nil | ||
| } | ||
| func (q *FakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTemplateParams) error { | ||
| if err := validateDatabaseType(arg); err != nil { | ||
| return err | ||
| } | ||
| q.mutex.Lock() | ||
| defer q.mutex.Unlock() | ||
| //nolint:gosimple | ||
| template := database.TemplateTable{ | ||
| ID: arg.ID, | ||
| CreatedAt: arg.CreatedAt, | ||
| UpdatedAt: arg.UpdatedAt, | ||
| @@ -3464,7 +3486,7 @@ func (q *FakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl | ||
| AllowUserAutostop: true, | ||
| } | ||
| q.templates = append(q.templates, template) | ||
| return nil | ||
| } | ||
| func (q *FakeQuerier) InsertTemplateVersion(_ context.Context, arg database.InsertTemplateVersionParams) (database.TemplateVersion, error) { | ||
| @@ -4172,9 +4194,9 @@ func (q *FakeQuerier) UpdateReplica(_ context.Context, arg database.UpdateReplic | ||
| return database.Replica{}, sql.ErrNoRows | ||
| } | ||
| func (q *FakeQuerier) UpdateTemplateACLByID(_ context.Context, arg database.UpdateTemplateACLByIDParams) error { | ||
| if err := validateDatabaseType(arg); err != nil { | ||
| return err | ||
| } | ||
| q.mutex.Lock() | ||
| @@ -4186,11 +4208,11 @@ func (q *FakeQuerier) UpdateTemplateACLByID(_ context.Context, arg database.Upda | ||
| template.UserACL = arg.UserACL | ||
| q.templates[i] = template | ||
| return nil | ||
| } | ||
| } | ||
| return sql.ErrNoRows | ||
| } | ||
| func (q *FakeQuerier) UpdateTemplateActiveVersionByID(_ context.Context, arg database.UpdateTemplateActiveVersionByIDParams) error { | ||
| @@ -4233,9 +4255,9 @@ func (q *FakeQuerier) UpdateTemplateDeletedByID(_ context.Context, arg database. | ||
| return sql.ErrNoRows | ||
| } | ||
| func (q *FakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.UpdateTemplateMetaByIDParams) error { | ||
| if err := validateDatabaseType(arg); err != nil { | ||
| return err | ||
| } | ||
| q.mutex.Lock() | ||
| @@ -4251,15 +4273,15 @@ func (q *FakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd | ||
| tpl.Description = arg.Description | ||
| tpl.Icon = arg.Icon | ||
| q.templates[idx] = tpl | ||
| return nil | ||
| } | ||
| return sql.ErrNoRows | ||
| } | ||
| func (q *FakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database.UpdateTemplateScheduleByIDParams) error { | ||
| if err := validateDatabaseType(arg); err != nil { | ||
| return err | ||
| } | ||
| q.mutex.Lock() | ||
| @@ -4278,10 +4300,10 @@ func (q *FakeQuerier) UpdateTemplateScheduleByID(_ context.Context, arg database | ||
| tpl.InactivityTTL = arg.InactivityTTL | ||
| tpl.LockedTTL = arg.LockedTTL | ||
| q.templates[idx] = tpl | ||
| return nil | ||
| } | ||
| return sql.ErrNoRows | ||
| } | ||
| func (q *FakeQuerier) UpdateTemplateVersionByID(_ context.Context, arg database.UpdateTemplateVersionByIDParams) (database.TemplateVersion, error) { | ||
| @@ -4984,7 +5006,8 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G | ||
| } | ||
| var templates []database.Template | ||
| for _, templateTable := range q.templates { | ||
| template := q.templateWithUserNoLock(templateTable) | ||
| if prepared != nil && prepared.Authorize(ctx, template.RBACObject()) != nil { | ||
| continue | ||
| } | ||
| @@ -5012,7 +5035,7 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G | ||
| continue | ||
| } | ||
| } | ||
| templates = append(templates, template) | ||
| } | ||
| if len(templates) > 0 { | ||
| slices.SortFunc(templates, func(i, j database.Template) bool { | ||
| @@ -5031,7 +5054,7 @@ func (q *FakeQuerier) GetTemplateGroupRoles(_ context.Context, id uuid.UUID) ([] | ||
| q.mutex.RLock() | ||
| defer q.mutex.RUnlock() | ||
| var template database.TemplateTable | ||
| for _, t := range q.templates { | ||
| if t.ID == id { | ||
| template = t | ||
| @@ -5068,7 +5091,7 @@ func (q *FakeQuerier) GetTemplateUserRoles(_ context.Context, id uuid.UUID) ([]d | ||
| q.mutex.RLock() | ||
| defer q.mutex.RUnlock() | ||
| var template database.TemplateTable | ||
| for _, t := range q.templates { | ||
| if t.ID == id { | ||
| template = t | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.