Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes from5 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
61 changes: 38 additions & 23 deletionscoderd/appearance/appearance.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,36 +10,51 @@ type Fetcher interface {
Fetch(ctx context.Context) (codersdk.AppearanceConfig, error)
}

var DefaultSupportLinks = []codersdk.LinkConfig{
{
func DefaultSupportLinks(docsURL string) []codersdk.LinkConfig {
if docsURL == "" {
docsURL = "https://coder.com/docs/{CODER_VERSION}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You could usebuildinfo.Version() instead so the frontend doesn't have to replace this.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yeah I was taking a "do as the Romans do" approach and doing it the way the build info was done, but I agree with your comment below that we have this info on the backend so we might as well do it here.
Let me ping someone for context on why it's set up this way before falling into the classic "refactor and then realize why they did it the original way" trap and get back to you haha.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks like we can just have the backend do this :)
https://codercom.slack.com/archives/CJURPL8DN/p1723126779529959

}

docsLink := codersdk.LinkConfig{
Name: "Documentation",
Target:"https://coder.com/docs/coder-oss",
Target:docsURL,
Icon: "docs",
},
{
Name: "Report a bug",
Target: "https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
Icon: "bug",
},
{
Name: "Join the Coder Discord",
Target: "https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer",
Icon: "chat",
},
{
Name: "Star the Repo",
Target: "https://github.com/coder/coder",
Icon: "star",
},
}

defaultSupportLinks := []codersdk.LinkConfig{
{
Name: "Report a bug",
Target: "https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know you didn't introduce this, but I think we should be doing this replacement on the backend, not the frontend. We already should have this info anyways.

Icon: "bug",
},
{
Name: "Join the Coder Discord",
Target: "https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer",
Icon: "chat",
},
{
Name: "Star the Repo",
Target: "https://github.com/coder/coder",
Icon: "star",
},
}

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

type AGPLFetcher struct{}
type AGPLFetcher struct {
docsURL string
}

func (AGPLFetcher) Fetch(context.Context) (codersdk.AppearanceConfig, error) {
func (fAGPLFetcher) 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 deletioncoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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
8 changes: 6 additions & 2 deletionsenterprise/coderd/appearance.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
}
}

Expand DownExpand Up@@ -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 != "" {
Expand Down
23 changes: 22 additions & 1 deletionenterprise/coderd/appearance_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import (
"context"
"errors"
"net/http"
"net/url"
"testing"

"github.com/stretchr/testify/require"
Expand DownExpand Up@@ -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()

Expand All@@ -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)
}
6 changes: 5 additions & 1 deletionenterprise/coderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"
Expand DownExpand Up@@ -790,10 +791,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)
}
}

Expand Down
3 changes: 2 additions & 1 deletionsite/site.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -181,12 +181,20 @@ const includeBuildInfo = (
href: string,
buildInfo?: TypesGen.BuildInfoResponse,
): string => {
return href.replace(
"{CODER_BUILD_INFO}",
`${encodeURIComponent(
`Version: [\`${buildInfo?.version}\`](${buildInfo?.external_url})`,
)}`,
);
let version = encodeURIComponent((buildInfo?.version ?? "").split("-")[0]);
if (version) {
// Not encoding the @ because it makes the link look a bit weird.
version = `@${version}`;
}

return href
.replace(
"{CODER_BUILD_INFO}",
`${encodeURIComponent(
`Version: [\`${buildInfo?.version}\`](${buildInfo?.external_url})`,
)}`,
)
.replace("{CODER_VERSION}", version);
};

const styles = {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp