Adds a `codernauts_enabled` runtime setting (default: enabled) that controls whether the Codernauts game link appears in the user dropdown menu. A toggle at the bottom of the Deployment > Appearance page controls it, and the value persists in `site_configs`, so it survives restarts and upgrades without any CLI flags or environment variables. The setting works on all licenses: `GET /api/v2/appearance` reports it from both the enterprise and the default (AGPL) appearance fetchers, and `PUT /api/v2/appearance` persists it gated only by the deployment-config RBAC permission, not by an entitlement. On the Appearance page the toggle renders outside the Premium paywall introduced in #27948; the other appearance fields keep their existing licensing behavior. Note: a pure AGPL-only build of coderd does not register the `/api/v2/appearance` routes at all, so the toggle cannot be saved there. The standard `coder server` binary is unaffected regardless of license state. <details> <summary>Implementation notes</summary> - `coderd/database/queries/siteconfig.sql`: new `GetCodernautsEnabled` / `UpsertCodernautsEnabled` queries backed by a `codernauts_enabled` key in `site_configs`; defaults to `true` when unset (no migration needed). - `coderd/database/dbauthz`: read has no authz checks (matching other appearance reads); write requires `ResourceDeploymentConfig` update. Coverage added to `dbauthz_test.go`. - `codersdk`: `codernauts_enabled` added to `AppearanceConfig` and `UpdateAppearanceConfig`. - `coderd/appearance`: the default fetcher takes a `database.Store` and reads the setting from the database so unlicensed deployments serve it too. - `enterprise/coderd/appearance.go`: fetches the value in `Fetch` and persists it in `putAppearance`. - Frontend: "Codernauts game" toggle section on Deployment > Appearance saving immediately via the existing appearance mutation; `codernauts_enabled` threaded from `useDashboard().appearance` through Navbar to `UserDropdownContent`, which renders the menu item only when enabled. Storybook stories with `play` functions cover toggling (entitled and not) and the dropdown hiding the link when disabled. </details> --- 🤖 This PR was generated by Coder Agents on behalf of @bartekgatzcoder.
43 lines
1000 B
Go
43 lines
1000 B
Go
package appearance
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
type Fetcher interface {
|
|
Fetch(ctx context.Context) (codersdk.AppearanceConfig, error)
|
|
}
|
|
|
|
type AGPLFetcher struct {
|
|
database database.Store
|
|
docsURL string
|
|
}
|
|
|
|
func (f AGPLFetcher) Fetch(ctx context.Context) (codersdk.AppearanceConfig, error) {
|
|
codernautsEnabled, err := f.database.GetCodernautsEnabled(ctx)
|
|
if err != nil {
|
|
return codersdk.AppearanceConfig{}, xerrors.Errorf("get codernauts enabled: %w", err)
|
|
}
|
|
return codersdk.AppearanceConfig{
|
|
AnnouncementBanners: []codersdk.BannerConfig{},
|
|
SupportLinks: codersdk.DefaultSupportLinks(f.docsURL),
|
|
DocsURL: f.docsURL,
|
|
CodernautsEnabled: codernautsEnabled,
|
|
}, nil
|
|
}
|
|
|
|
func NewDefaultFetcher(db database.Store, docsURL string) Fetcher {
|
|
if docsURL == "" {
|
|
docsURL = codersdk.DefaultDocsURL()
|
|
}
|
|
return &AGPLFetcher{
|
|
database: db,
|
|
docsURL: docsURL,
|
|
}
|
|
}
|