MCPcopy Index your code
hub / github.com/coder/coder / notifyUsersOfTemplateDeprecation

Method notifyUsersOfTemplateDeprecation

coderd/templates.go:860–894  ·  view source on GitHub ↗
(ctx context.Context, template database.Template)

Source from the content-addressed store, hash-verified

858}
859
860func (api *API) notifyUsersOfTemplateDeprecation(ctx context.Context, template database.Template) error {
861 workspaces, err := api.Database.GetWorkspaces(ctx, database.GetWorkspacesParams{
862 TemplateIDs: []uuid.UUID{template.ID},
863 })
864 if err != nil {
865 return xerrors.Errorf("get workspaces by template id: %w", err)
866 }
867
868 users := make(map[uuid.UUID]struct{})
869 for _, workspace := range workspaces {
870 users[workspace.OwnerID] = struct{}{}
871 }
872
873 errs := []error{}
874
875 for userID := range users {
876 _, err = api.NotificationsEnqueuer.Enqueue(
877 //nolint:gocritic // We need the notifier auth context to be able to send the deprecation notification.
878 dbauthz.AsNotifier(ctx),
879 userID,
880 notifications.TemplateTemplateDeprecated,
881 map[string]string{
882 "template": template.Name,
883 "message": template.Deprecated,
884 "organization": template.OrganizationName,
885 },
886 "notify-users-of-template-deprecation",
887 )
888 if err != nil {
889 errs = append(errs, xerrors.Errorf("enqueue notification: %w", err))
890 }
891 }
892
893 return errors.Join(errs...)
894}
895
896// @Summary Get template DAUs by ID
897// @ID get-template-daus-by-id

Callers 1

patchTemplateMetaMethod · 0.95

Calls 4

AsNotifierFunction · 0.92
GetWorkspacesMethod · 0.65
EnqueueMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected