Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
6 changes: 6 additions & 0 deletions coderd/apidoc/docs.go

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

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

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

18 changes: 14 additions & 4 deletions coderd/appearance/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package appearance
import (
"context"

"golang.org/x/xerrors"

"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/codersdk"
)

Expand All @@ -11,22 +14,29 @@ type Fetcher interface {
}

type AGPLFetcher struct {
docsURL string
database database.Store
docsURL string
}

func (f AGPLFetcher) Fetch(context.Context) (codersdk.AppearanceConfig, error) {
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(docsURL string) Fetcher {
func NewDefaultFetcher(db database.Store, docsURL string) Fetcher {
if docsURL == "" {
docsURL = codersdk.DefaultDocsURL()
}
return &AGPLFetcher{
docsURL: docsURL,
database: db,
docsURL: docsURL,
}
}
2 changes: 1 addition & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ func New(options *Options) *API {
options.AppSigningKeyCache,
)

f := appearance.NewDefaultFetcher(api.DeploymentValues.DocsURL.String())
f := appearance.NewDefaultFetcher(options.Database, api.DeploymentValues.DocsURL.String())
api.AppearanceFetcher.Store(&f)
api.PortSharer.Store(&portsharing.DefaultPortSharer)
api.PrebuildsClaimer.Store(&prebuilds.DefaultClaimer)
Expand Down
11 changes: 11 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -3788,6 +3788,10 @@ func (q *querier) GetChildChatsByParentIDs(ctx context.Context, arg database.Get
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetChildChatsByParentIDs)(ctx, arg)
}

func (q *querier) GetCodernautsEnabled(ctx context.Context) (bool, error) {
return q.db.GetCodernautsEnabled(ctx)
}

func (q *querier) GetConnectionLogsOffset(ctx context.Context, arg database.GetConnectionLogsOffsetParams) ([]database.GetConnectionLogsOffsetRow, error) {
// Just like with the audit logs query, shortcut if the user is an owner.
err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceConnectionLog)
Expand Down Expand Up @@ -9179,6 +9183,13 @@ func (q *querier) UpsertChatWorkspaceTTL(ctx context.Context, workspaceTtl strin
return q.db.UpsertChatWorkspaceTTL(ctx, workspaceTtl)
}

func (q *querier) UpsertCodernautsEnabled(ctx context.Context, enabled bool) error {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceDeploymentConfig); err != nil {
return err
}
return q.db.UpsertCodernautsEnabled(ctx, enabled)
}

func (q *querier) UpsertDefaultProxy(ctx context.Context, arg database.UpsertDefaultProxyParams) error {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceSystem); err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5490,6 +5490,14 @@ func (s *MethodTestSuite) TestSystemFunctions() {
dbm.EXPECT().UpsertApplicationName(gomock.Any(), "").Return(nil).AnyTimes()
check.Args("").Asserts(rbac.ResourceDeploymentConfig, policy.ActionUpdate)
}))
s.Run("GetCodernautsEnabled", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
dbm.EXPECT().GetCodernautsEnabled(gomock.Any()).Return(true, nil).AnyTimes()
check.Args().Asserts()
}))
s.Run("UpsertCodernautsEnabled", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
dbm.EXPECT().UpsertCodernautsEnabled(gomock.Any(), false).Return(nil).AnyTimes()
check.Args(false).Asserts(rbac.ResourceDeploymentConfig, policy.ActionUpdate)
}))
s.Run("UpsertBoundaryUsageStats", s.Mocked(func(dbm *dbmock.MockStore, _ *gofakeit.Faker, check *expects) {
arg := database.UpsertBoundaryUsageStatsParams{ReplicaID: uuid.New()}
dbm.EXPECT().UpsertBoundaryUsageStats(gomock.Any(), arg).Return(false, nil).AnyTimes()
Expand Down
16 changes: 16 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.

29 changes: 29 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.

34 changes: 34 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.

20 changes: 20 additions & 0 deletions coderd/database/queries/siteconfig.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ ON CONFLICT (key) DO UPDATE SET value = $1 WHERE site_configs.key = 'application
-- name: GetApplicationName :one
SELECT value FROM site_configs WHERE key = 'application_name';

-- name: GetCodernautsEnabled :one
SELECT
COALESCE((SELECT value = 'true' FROM site_configs WHERE key = 'codernauts_enabled'), true) :: boolean AS codernauts_enabled;

-- name: UpsertCodernautsEnabled :exec
INSERT INTO site_configs (key, value)
VALUES (
'codernauts_enabled',
CASE
WHEN @enabled::bool THEN 'true'
ELSE 'false'
END
)
ON CONFLICT (key) DO UPDATE
SET value = CASE
WHEN @enabled::bool THEN 'true'
ELSE 'false'
END
WHERE site_configs.key = 'codernauts_enabled';

-- name: GetHealthSettings :one
SELECT
COALESCE((SELECT value FROM site_configs WHERE key = 'health_settings'), '{}') :: text AS health_settings
Expand Down
2 changes: 2 additions & 0 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,7 @@ type AppearanceConfig struct {
ServiceBanner BannerConfig `json:"service_banner"`
AnnouncementBanners []BannerConfig `json:"announcement_banners"`
SupportLinks []LinkConfig `json:"support_links,omitempty"`
CodernautsEnabled bool `json:"codernauts_enabled"`
}

type UpdateAppearanceConfig struct {
Expand All @@ -5288,6 +5289,7 @@ type UpdateAppearanceConfig struct {
// Deprecated: ServiceBanner has been replaced by AnnouncementBanners.
ServiceBanner BannerConfig `json:"service_banner"`
AnnouncementBanners []BannerConfig `json:"announcement_banners"`
CodernautsEnabled bool `json:"codernauts_enabled"`
}

// Deprecated: ServiceBannerConfig has been renamed to BannerConfig.
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/api/enterprise.md

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

4 changes: 4 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.

Loading
Loading