Skip to content

feat: expose application name via Appearance API #9886

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 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Unit tests
  • Loading branch information
mtojek committed Sep 27, 2023
commit 84d0eeb182418a45c39cd157c22e9431b5ed61d2
2 changes: 1 addition & 1 deletion coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ func (q *querier) GetAppSecurityKey(ctx context.Context) (string, error) {

func (q *querier) GetApplicationName(ctx context.Context) (string, error) {
// No authz checks
return q.db.GetLogoURL(ctx)
return q.db.GetApplicationName(ctx)
}

func (q *querier) GetAuditLogsOffset(ctx context.Context, arg database.GetAuditLogsOffsetParams) ([]database.GetAuditLogsOffsetRow, error) {
Expand Down
11 changes: 10 additions & 1 deletion enterprise/coderd/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,16 @@ func (api *API) fetchAppearanceConfig(ctx context.Context) (codersdk.AppearanceC
}

var eg errgroup.Group
var applicationName string
var logoURL string
var serviceBannerJSON string
eg.Go(func() (err error) {
applicationName, err = api.Database.GetApplicationName(ctx)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return xerrors.Errorf("get application name: %w", err)
}
return nil
})
eg.Go(func() (err error) {
logoURL, err = api.Database.GetLogoURL(ctx)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
Expand All @@ -89,7 +97,8 @@ func (api *API) fetchAppearanceConfig(ctx context.Context) (codersdk.AppearanceC
}

cfg := codersdk.AppearanceConfig{
LogoURL: logoURL,
ApplicationName: applicationName,
LogoURL: logoURL,
}
if serviceBannerJSON != "" {
err = json.Unmarshal([]byte(serviceBannerJSON), &cfg.ServiceBanner)
Expand Down
31 changes: 31 additions & 0 deletions enterprise/coderd/appearance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@ import (
"github.com/coder/coder/v2/testutil"
)

func TestCustomLogoAndCompanyName(t *testing.T) {
t.Parallel()

// Prepare enterprise deployment
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

adminClient, _ := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true})
coderdenttest.AddLicense(t, adminClient, coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAppearance: 1,
},
})

// Update logo and application name
uac := codersdk.UpdateAppearanceConfig{
ApplicationName: "ACME Ltd",
LogoURL: "http://logo-url/file.png",
}

err := adminClient.UpdateAppearance(ctx, uac)
require.NoError(t, err)

// Verify update
got, err := adminClient.Appearance(ctx)
require.NoError(t, err)

require.Equal(t, uac.ApplicationName, got.ApplicationName)
require.Equal(t, uac.LogoURL, got.LogoURL)
}

func TestServiceBanners(t *testing.T) {
t.Parallel()

Expand Down