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

Commit76722a7

Browse files
authored
fix: make default support links respect --docs-url (#14176)
make default support links respect --docs-url
1 parent4c7132f commit76722a7

File tree

7 files changed

+80
-44
lines changed

7 files changed

+80
-44
lines changed

‎coderd/appearance/appearance.go

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,61 @@ package appearance
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57

8+
"github.com/coder/coder/v2/buildinfo"
69
"github.com/coder/coder/v2/codersdk"
710
)
811

912
typeFetcherinterface {
1013
Fetch(ctx context.Context) (codersdk.AppearanceConfig,error)
1114
}
1215

13-
varDefaultSupportLinks= []codersdk.LinkConfig{
14-
{
15-
Name:"Documentation",
16-
Target:"https://coder.com/docs/coder-oss",
17-
Icon:"docs",
18-
},
19-
{
20-
Name:"Report a bug",
21-
Target:"https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
22-
Icon:"bug",
23-
},
24-
{
25-
Name:"Join the Coder Discord",
26-
Target:"https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer",
27-
Icon:"chat",
28-
},
29-
{
30-
Name:"Star the Repo",
31-
Target:"https://github.com/coder/coder",
32-
Icon:"star",
33-
},
16+
funcDefaultSupportLinks(docsURLstring) []codersdk.LinkConfig {
17+
version:=buildinfo.Version()
18+
ifdocsURL=="" {
19+
docsURL="https://coder.com/docs/@"+strings.Split(version,"-")[0]
20+
}
21+
buildInfo:=fmt.Sprintf("Version: [`%s`](%s)",version,buildinfo.ExternalURL())
22+
23+
return []codersdk.LinkConfig{
24+
{
25+
Name:"Documentation",
26+
Target:docsURL,
27+
Icon:"docs",
28+
},
29+
{
30+
Name:"Report a bug",
31+
Target:"https://github.com/coder/coder/issues/new?labels=needs+grooming&body="+buildInfo,
32+
Icon:"bug",
33+
},
34+
{
35+
Name:"Join the Coder Discord",
36+
Target:"https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer",
37+
Icon:"chat",
38+
},
39+
{
40+
Name:"Star the Repo",
41+
Target:"https://github.com/coder/coder",
42+
Icon:"star",
43+
},
44+
}
3445
}
3546

36-
typeAGPLFetcherstruct{}
47+
typeAGPLFetcherstruct {
48+
docsURLstring
49+
}
3750

38-
func (AGPLFetcher)Fetch(context.Context) (codersdk.AppearanceConfig,error) {
51+
func (fAGPLFetcher)Fetch(context.Context) (codersdk.AppearanceConfig,error) {
3952
return codersdk.AppearanceConfig{
4053
AnnouncementBanners: []codersdk.BannerConfig{},
41-
SupportLinks:DefaultSupportLinks,
54+
SupportLinks:DefaultSupportLinks(f.docsURL),
4255
},nil
4356
}
4457

45-
varDefaultFetcherFetcher=AGPLFetcher{}
58+
funcNewDefaultFetcher(docsURLstring)Fetcher {
59+
return&AGPLFetcher{
60+
docsURL:docsURL,
61+
}
62+
}

‎coderd/coderd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ func New(options *Options) *API {
475475
dbRolluper:options.DatabaseRolluper,
476476
}
477477

478-
api.AppearanceFetcher.Store(&appearance.DefaultFetcher)
478+
f:=appearance.NewDefaultFetcher(api.DeploymentValues.DocsURL.String())
479+
api.AppearanceFetcher.Store(&f)
479480
api.PortSharer.Store(&portsharing.DefaultPortSharer)
480481
buildInfo:= codersdk.BuildInfoResponse{
481482
ExternalURL:buildinfo.ExternalURL(),

‎enterprise/coderd/appearance.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ func (api *API) appearance(rw http.ResponseWriter, r *http.Request) {
4444
typeappearanceFetcherstruct {
4545
database database.Store
4646
supportLinks []codersdk.LinkConfig
47+
docsURLstring
48+
coderVersionstring
4749
}
4850

49-
funcnewAppearanceFetcher(store database.Store,links []codersdk.LinkConfig) agpl.Fetcher {
51+
funcnewAppearanceFetcher(store database.Store,links []codersdk.LinkConfig,docsURL,coderVersionstring) agpl.Fetcher {
5052
return&appearanceFetcher{
5153
database:store,
5254
supportLinks:links,
55+
docsURL:docsURL,
56+
coderVersion:coderVersion,
5357
}
5458
}
5559

@@ -90,7 +94,7 @@ func (f *appearanceFetcher) Fetch(ctx context.Context) (codersdk.AppearanceConfi
9094
ApplicationName:applicationName,
9195
LogoURL:logoURL,
9296
AnnouncementBanners: []codersdk.BannerConfig{},
93-
SupportLinks:agpl.DefaultSupportLinks,
97+
SupportLinks:agpl.DefaultSupportLinks(f.docsURL),
9498
}
9599

96100
ifannouncementBannersJSON!="" {

‎enterprise/coderd/appearance_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"net/http"
7+
"net/url"
78
"testing"
89

910
"github.com/stretchr/testify/require"
@@ -229,6 +230,26 @@ func TestCustomSupportLinks(t *testing.T) {
229230
require.Equal(t,supportLinks,appr.SupportLinks)
230231
}
231232

233+
funcTestDefaultSupportLinksWithCustomDocsUrl(t*testing.T) {
234+
t.Parallel()
235+
236+
// Don't need to set the license, as default links are passed without it.
237+
testURLRawString:="http://google.com"
238+
testURL,err:=url.Parse(testURLRawString)
239+
require.NoError(t,err)
240+
cfg:=coderdtest.DeploymentValues(t)
241+
cfg.DocsURL=*serpent.URLOf(testURL)
242+
adminClient,adminUser:=coderdenttest.New(t,&coderdenttest.Options{DontAddLicense:true,Options:&coderdtest.Options{DeploymentValues:cfg}})
243+
anotherClient,_:=coderdtest.CreateAnotherUser(t,adminClient,adminUser.OrganizationID)
244+
245+
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitMedium)
246+
defercancel()
247+
248+
appr,err:=anotherClient.Appearance(ctx)
249+
require.NoError(t,err)
250+
require.Equal(t,appearance.DefaultSupportLinks(testURLRawString),appr.SupportLinks)
251+
}
252+
232253
funcTestDefaultSupportLinks(t*testing.T) {
233254
t.Parallel()
234255

@@ -241,5 +262,5 @@ func TestDefaultSupportLinks(t *testing.T) {
241262

242263
appr,err:=anotherClient.Appearance(ctx)
243264
require.NoError(t,err)
244-
require.Equal(t,appearance.DefaultSupportLinks,appr.SupportLinks)
265+
require.Equal(t,appearance.DefaultSupportLinks(""),appr.SupportLinks)
245266
}

‎enterprise/coderd/coderd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sync"
1313
"time"
1414

15+
"github.com/coder/coder/v2/buildinfo"
1516
"github.com/coder/coder/v2/coderd/appearance"
1617
"github.com/coder/coder/v2/coderd/database"
1718
agplportsharing"github.com/coder/coder/v2/coderd/portsharing"
@@ -791,10 +792,13 @@ func (api *API) updateEntitlements(ctx context.Context) error {
791792
f:=newAppearanceFetcher(
792793
api.Database,
793794
api.DeploymentValues.Support.Links.Value,
795+
api.DeploymentValues.DocsURL.String(),
796+
buildinfo.Version(),
794797
)
795798
api.AGPL.AppearanceFetcher.Store(&f)
796799
}else {
797-
api.AGPL.AppearanceFetcher.Store(&appearance.DefaultFetcher)
800+
f:=appearance.NewDefaultFetcher(api.DeploymentValues.DocsURL.String())
801+
api.AGPL.AppearanceFetcher.Store(&f)
798802
}
799803
}
800804

‎site/site.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ type Options struct {
8484
funcNew(opts*Options)*Handler {
8585
ifopts.AppearanceFetcher==nil {
8686
daf:= atomic.Pointer[appearance.Fetcher]{}
87-
daf.Store(&appearance.DefaultFetcher)
87+
f:=appearance.NewDefaultFetcher(opts.DocsURL)
88+
daf.Store(&f)
8889
opts.AppearanceFetcher=&daf
8990
}
9091
handler:=&Handler{

‎site/src/modules/dashboard/Navbar/UserDropdown/UserDropdownContent.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const UserDropdownContent: FC<UserDropdownContentProps> = ({
9393
<Divider/>
9494
{supportLinks.map((link)=>(
9595
<a
96-
href={includeBuildInfo(link.target,buildInfo)}
96+
href={link.target}
9797
key={link.name}
9898
target="_blank"
9999
rel="noreferrer"
@@ -177,18 +177,6 @@ export const GithubStar: FC<SvgIconProps> = (props) => (
177177
</svg>
178178
);
179179

180-
constincludeBuildInfo=(
181-
href:string,
182-
buildInfo?:TypesGen.BuildInfoResponse,
183-
):string=>{
184-
returnhref.replace(
185-
"{CODER_BUILD_INFO}",
186-
`${encodeURIComponent(
187-
`Version: [\`${buildInfo?.version}\`](${buildInfo?.external_url})`,
188-
)}`,
189-
);
190-
};
191-
192180
conststyles={
193181
info:(theme)=>[
194182
theme.typography.body2asCSSObject,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp