fix: make default support links respect --docs-url (#14176)

make default support links respect --docs-url
This commit is contained in:
Benjamin Peinhardt
2024-08-12 17:01:22 -04:00
committed by GitHub
parent 4c7132f08b
commit 76722a7db5
7 changed files with 80 additions and 44 deletions
+6 -2
View File
@@ -44,12 +44,16 @@ func (api *API) appearance(rw http.ResponseWriter, r *http.Request) {
type appearanceFetcher struct {
database database.Store
supportLinks []codersdk.LinkConfig
docsURL string
coderVersion string
}
func newAppearanceFetcher(store database.Store, links []codersdk.LinkConfig) agpl.Fetcher {
func newAppearanceFetcher(store database.Store, links []codersdk.LinkConfig, docsURL, coderVersion string) agpl.Fetcher {
return &appearanceFetcher{
database: store,
supportLinks: links,
docsURL: docsURL,
coderVersion: coderVersion,
}
}
@@ -90,7 +94,7 @@ func (f *appearanceFetcher) Fetch(ctx context.Context) (codersdk.AppearanceConfi
ApplicationName: applicationName,
LogoURL: logoURL,
AnnouncementBanners: []codersdk.BannerConfig{},
SupportLinks: agpl.DefaultSupportLinks,
SupportLinks: agpl.DefaultSupportLinks(f.docsURL),
}
if announcementBannersJSON != "" {
+22 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/require"
@@ -229,6 +230,26 @@ func TestCustomSupportLinks(t *testing.T) {
require.Equal(t, supportLinks, appr.SupportLinks)
}
func TestDefaultSupportLinksWithCustomDocsUrl(t *testing.T) {
t.Parallel()
// Don't need to set the license, as default links are passed without it.
testURLRawString := "http://google.com"
testURL, err := url.Parse(testURLRawString)
require.NoError(t, err)
cfg := coderdtest.DeploymentValues(t)
cfg.DocsURL = *serpent.URLOf(testURL)
adminClient, adminUser := coderdenttest.New(t, &coderdenttest.Options{DontAddLicense: true, Options: &coderdtest.Options{DeploymentValues: cfg}})
anotherClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
defer cancel()
appr, err := anotherClient.Appearance(ctx)
require.NoError(t, err)
require.Equal(t, appearance.DefaultSupportLinks(testURLRawString), appr.SupportLinks)
}
func TestDefaultSupportLinks(t *testing.T) {
t.Parallel()
@@ -241,5 +262,5 @@ func TestDefaultSupportLinks(t *testing.T) {
appr, err := anotherClient.Appearance(ctx)
require.NoError(t, err)
require.Equal(t, appearance.DefaultSupportLinks, appr.SupportLinks)
require.Equal(t, appearance.DefaultSupportLinks(""), appr.SupportLinks)
}
+5 -1
View File
@@ -12,6 +12,7 @@ import (
"sync"
"time"
"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/coderd/appearance"
"github.com/coder/coder/v2/coderd/database"
agplportsharing "github.com/coder/coder/v2/coderd/portsharing"
@@ -791,10 +792,13 @@ func (api *API) updateEntitlements(ctx context.Context) error {
f := newAppearanceFetcher(
api.Database,
api.DeploymentValues.Support.Links.Value,
api.DeploymentValues.DocsURL.String(),
buildinfo.Version(),
)
api.AGPL.AppearanceFetcher.Store(&f)
} else {
api.AGPL.AppearanceFetcher.Store(&appearance.DefaultFetcher)
f := appearance.NewDefaultFetcher(api.DeploymentValues.DocsURL.String())
api.AGPL.AppearanceFetcher.Store(&f)
}
}