Skip to content

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

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
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
Next Next commit
it works now yay
  • Loading branch information
bcpeinhardt committed Aug 5, 2024
commit c1758fa2d72f5ede9f756d0aeb26da7dc0038ba4
36 changes: 26 additions & 10 deletions coderd/appearance/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ type Fetcher interface {
Fetch(ctx context.Context) (codersdk.AppearanceConfig, error)
}

var DefaultSupportLinks = []codersdk.LinkConfig{
{
Name: "Documentation",
Target: "https://coder.com/docs/coder-oss",
Icon: "docs",
},
var defaultSupportLinks = []codersdk.LinkConfig{
{
Name: "Report a bug",
Target: "https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
Expand All @@ -33,13 +28,34 @@ var DefaultSupportLinks = []codersdk.LinkConfig{
},
}

type AGPLFetcher struct{}
func DefaultSupportLinks(docsUrl string) []codersdk.LinkConfig {
if docsUrl == "" {
docsUrl = "https://coder.com/docs/coder-oss"
}

docsLink := codersdk.LinkConfig{
Name: "Documentation",
Target: docsUrl,
Icon: "docs",
}

return append([]codersdk.LinkConfig{docsLink}, defaultSupportLinks...)
}

type AGPLFetcher struct {
docsUrl string
}

func (f AGPLFetcher) Fetch(context.Context) (codersdk.AppearanceConfig, error) {

func (AGPLFetcher) Fetch(context.Context) (codersdk.AppearanceConfig, error) {
return codersdk.AppearanceConfig{
AnnouncementBanners: []codersdk.BannerConfig{},
SupportLinks: DefaultSupportLinks,
SupportLinks: DefaultSupportLinks(f.docsUrl),
}, nil
}

var DefaultFetcher Fetcher = AGPLFetcher{}
func NewDefaultFetcher(docsUrl string) Fetcher {
return &AGPLFetcher{
docsUrl: docsUrl,
}
}
3 changes: 2 additions & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ func New(options *Options) *API {
dbRolluper: options.DatabaseRolluper,
}

api.AppearanceFetcher.Store(&appearance.DefaultFetcher)
f := appearance.NewDefaultFetcher(api.DeploymentValues.DocsURL.String())
api.AppearanceFetcher.Store(&f)
api.PortSharer.Store(&portsharing.DefaultPortSharer)
buildInfo := codersdk.BuildInfoResponse{
ExternalURL: buildinfo.ExternalURL(),
Expand Down
6 changes: 4 additions & 2 deletions enterprise/coderd/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ func (api *API) appearance(rw http.ResponseWriter, r *http.Request) {
type appearanceFetcher struct {
database database.Store
supportLinks []codersdk.LinkConfig
docsUrl string
}

func newAppearanceFetcher(store database.Store, links []codersdk.LinkConfig) agpl.Fetcher {
func newAppearanceFetcher(store database.Store, links []codersdk.LinkConfig, docsUrl string) agpl.Fetcher {
return &appearanceFetcher{
database: store,
supportLinks: links,
docsUrl: docsUrl,
}
}

Expand Down Expand Up @@ -90,7 +92,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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/coderd/appearance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,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)
}
4 changes: 3 additions & 1 deletion enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,12 @@ func (api *API) updateEntitlements(ctx context.Context) error {
f := newAppearanceFetcher(
api.Database,
api.DeploymentValues.Support.Links.Value,
api.DeploymentValues.DocsURL.String(),
)
api.AGPL.AppearanceFetcher.Store(&f)
} else {
api.AGPL.AppearanceFetcher.Store(&appearance.DefaultFetcher)
f := appearance.NewDefaultFetcher(api.DeploymentValues.DocsURL.String())
api.AGPL.AppearanceFetcher.Store(&f)
}
}

Expand Down
3 changes: 2 additions & 1 deletion site/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ type Options struct {
func New(opts *Options) *Handler {
if opts.AppearanceFetcher == nil {
daf := atomic.Pointer[appearance.Fetcher]{}
daf.Store(&appearance.DefaultFetcher)
f := appearance.NewDefaultFetcher(opts.DocsURL)
daf.Store(&f)
opts.AppearanceFetcher = &daf
}
handler := &Handler{
Expand Down