Skip to content

feat: add backend logic for determining tasks tab visibility #18401

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 5 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/testdata/coder_server_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ Clients include the Coder CLI, Coder Desktop, IDE extensions, and the web UI.
is detected. By default it instructs users to update using 'curl -L
https://coder.com/install.sh | sh'.

--hide-ai-tasks bool, $CODER_HIDE_AI_TASKS (default: false)
Hide AI tasks from the dashboard.

--ssh-config-options string-array, $CODER_SSH_CONFIG_OPTIONS
These SSH config options will override the default SSH config options.
Provide options in "key=value" or "key value" format separated by
Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/server-config.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ client:
# 'webgl', or 'dom'.
# (default: canvas, type: string)
webTerminalRenderer: canvas
# Hide AI tasks from the dashboard.
# (default: false, type: bool)
hideAITasks: false
# Support links to display in the top right drop down menu.
# (default: <unset>, type: struct[[]codersdk.LinkConfig])
supportLinks: []
Expand Down
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ func New(options *Options) *API {
Entitlements: options.Entitlements,
Telemetry: options.Telemetry,
Logger: options.Logger.Named("site"),
HideAITasks: options.DeploymentValues.HideAITasks.Value(),
})
api.SiteHandler.Experiments.Store(&experiments)

Expand Down
5 changes: 5 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,11 @@ func (q *querier) GetWorkspacesEligibleForTransition(ctx context.Context, now ti
return q.db.GetWorkspacesEligibleForTransition(ctx, now)
}

func (q *querier) HasTemplateVersionsWithAITask(ctx context.Context) (bool, error) {
// Anyone can call HasTemplateVersionsWithAITask.
return q.db.HasTemplateVersionsWithAITask(ctx)
}

func (q *querier) InsertAPIKey(ctx context.Context, arg database.InsertAPIKeyParams) (database.APIKey, error) {
return insert(q.log, q.auth,
rbac.ResourceApiKey.WithOwner(arg.UserID.String()),
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,9 @@ func (s *MethodTestSuite) TestSystemFunctions() {
s.Run("GetProvisionerJobByIDForUpdate", s.Subtest(func(db database.Store, check *expects) {
check.Args(uuid.New()).Asserts(rbac.ResourceProvisionerJobs, policy.ActionRead).Errors(sql.ErrNoRows)
}))
s.Run("HasTemplateVersionsWithAITask", s.Subtest(func(db database.Store, check *expects) {
check.Args().Asserts()
}))
}

func (s *MethodTestSuite) TestNotifications() {
Expand Down
13 changes: 13 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -8491,6 +8491,19 @@ func (q *FakeQuerier) GetWorkspacesEligibleForTransition(ctx context.Context, no
return workspaces, nil
}

func (q *FakeQuerier) HasTemplateVersionsWithAITask(_ context.Context) (bool, error) {
q.mutex.RLock()
defer q.mutex.RUnlock()

for _, templateVersion := range q.templateVersions {
if templateVersion.HasAITask {
return true, nil
}
}

return false, nil
}

func (q *FakeQuerier) InsertAPIKey(_ context.Context, arg database.InsertAPIKeyParams) (database.APIKey, error) {
if err := validateDatabaseType(arg); err != nil {
return database.APIKey{}, err
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions coderd/database/queries/templateversions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,7 @@ FROM
WHERE
template_versions.id IN (archived_versions.id)
RETURNING template_versions.id;

-- name: HasTemplateVersionsWithAITask :one
-- Determines if the template versions table has any rows with has_ai_task = TRUE.
SELECT EXISTS (SELECT 1 FROM template_versions WHERE has_ai_task = TRUE);
11 changes: 11 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ type DeploymentValues struct {
AdditionalCSPPolicy serpent.StringArray `json:"additional_csp_policy,omitempty" typescript:",notnull"`
WorkspaceHostnameSuffix serpent.String `json:"workspace_hostname_suffix,omitempty" typescript:",notnull"`
Prebuilds PrebuildsConfig `json:"workspace_prebuilds,omitempty" typescript:",notnull"`
HideAITasks serpent.Bool `json:"hide_ai_tasks,omitempty" typescript:",notnull"`

Config serpent.YAMLConfigPath `json:"config,omitempty" typescript:",notnull"`
WriteConfig serpent.Bool `json:"write_config,omitempty" typescript:",notnull"`
Expand Down Expand Up @@ -3116,6 +3117,16 @@ Write out the current server config as YAML to stdout.`,
YAML: "failure_hard_limit",
Hidden: true,
},
{
Name: "Hide AI Tasks",
Description: "Hide AI tasks from the dashboard.",
Flag: "hide-ai-tasks",
Env: "CODER_HIDE_AI_TASKS",
Default: "false",
Value: &c.HideAITasks,
Group: &deploymentGroupClient,
YAML: "hideAITasks",
},
}

return opts
Expand Down
1 change: 1 addition & 0 deletions docs/reference/api/general.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/reference/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions docs/reference/cli/server.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions enterprise/cli/testdata/coder_server_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Clients include the Coder CLI, Coder Desktop, IDE extensions, and the web UI.
is detected. By default it instructs users to update using 'curl -L
https://coder.com/install.sh | sh'.

--hide-ai-tasks bool, $CODER_HIDE_AI_TASKS (default: false)
Hide AI tasks from the dashboard.

--ssh-config-options string-array, $CODER_SSH_CONFIG_OPTIONS
These SSH config options will override the default SSH config options.
Provide options in "key=value" or "key value" format separated by
Expand Down
1 change: 1 addition & 0 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<meta property="regions" content="{{ .Regions }}" />
<meta property="docs-url" content="{{ .DocsURL }}" />
<meta property="logo-url" content="{{ .LogoURL }}" />
<meta property="tasks-tab-visible" content="{{ .TasksTabVisible }}" />
<!-- We need to set data-react-helmet to be able to override it in the workspace page -->
<link
rel="alternate icon"
Expand Down
26 changes: 26 additions & 0 deletions site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Options struct {
Entitlements *entitlements.Set
Telemetry telemetry.Reporter
Logger slog.Logger
HideAITasks bool
}

func New(opts *Options) *Handler {
Expand Down Expand Up @@ -316,6 +317,8 @@ type htmlState struct {
Experiments string
Regions string
DocsURL string

TasksTabVisible string
}

type csrfState struct {
Expand Down Expand Up @@ -445,6 +448,7 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
var user database.User
var themePreference string
var terminalFont string
var tasksTabVisible bool
orgIDs := []uuid.UUID{}
eg.Go(func() error {
var err error
Expand Down Expand Up @@ -480,6 +484,20 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
orgIDs = memberIDs[0].OrganizationIDs
return err
})
eg.Go(func() error {
// If HideAITasks is true, force hide the tasks tab
if h.opts.HideAITasks {
tasksTabVisible = false
return nil
}

hasAITask, err := h.opts.Database.HasTemplateVersionsWithAITask(ctx)
if err != nil {
return err
}
tasksTabVisible = hasAITask
return nil
})
err := eg.Wait()
if err == nil {
var wg sync.WaitGroup
Expand Down Expand Up @@ -550,6 +568,14 @@ func (h *Handler) renderHTMLWithState(r *http.Request, filePath string, state ht
}
}()
}
wg.Add(1)
go func() {
defer wg.Done()
tasksTabVisible, err := json.Marshal(tasksTabVisible)
if err == nil {
state.TasksTabVisible = html.EscapeString(string(tasksTabVisible))
}
}()
wg.Wait()
}

Expand Down
1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions site/src/hooks/useEmbeddedMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
MockBuildInfo,
MockEntitlements,
MockExperiments,
MockTasksTabVisible,
MockUserAppearanceSettings,
MockUserOwner,
} from "testHelpers/entities";
Expand Down Expand Up @@ -41,6 +42,7 @@ const mockDataForTags = {
user: MockUserOwner,
userAppearance: MockUserAppearanceSettings,
regions: MockRegions,
tasksTabVisible: MockTasksTabVisible,
} as const satisfies Record<MetadataKey, MetadataValue>;

const emptyMetadata: RuntimeHtmlMetadata = {
Expand Down Expand Up @@ -72,6 +74,10 @@ const emptyMetadata: RuntimeHtmlMetadata = {
available: false,
value: undefined,
},
tasksTabVisible: {
available: false,
value: undefined,
},
};

const populatedMetadata: RuntimeHtmlMetadata = {
Expand Down Expand Up @@ -103,6 +109,10 @@ const populatedMetadata: RuntimeHtmlMetadata = {
available: true,
value: MockUserAppearanceSettings,
},
tasksTabVisible: {
available: true,
value: MockTasksTabVisible,
},
};

function seedInitialMetadata(metadataKey: string): () => void {
Expand Down
2 changes: 2 additions & 0 deletions site/src/hooks/useEmbeddedMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type AvailableMetadata = Readonly<{
entitlements: Entitlements;
regions: readonly Region[];
"build-info": BuildInfoResponse;
tasksTabVisible: boolean;
}>;

export type MetadataKey = keyof AvailableMetadata;
Expand Down Expand Up @@ -91,6 +92,7 @@ export class MetadataManager implements MetadataManagerApi {
experiments: this.registerValue<Experiments>("experiments"),
"build-info": this.registerValue<BuildInfoResponse>("build-info"),
regions: this.registerRegionValue(),
tasksTabVisible: this.registerValue<boolean>("tasksTabVisible"),
};
}

Expand Down
2 changes: 2 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ export const MockUserAppearanceSettings: TypesGen.UserAppearanceSettings = {
terminal_font: "",
};

export const MockTasksTabVisible: boolean = false;

export const MockOrganizationMember: TypesGen.OrganizationMemberWithUserData = {
organization_id: MockOrganization.id,
user_id: MockUserOwner.id,
Expand Down
Loading