Skip to content

Commit 2e53fb5

Browse files
authored
feat: Enable custom support links (#6313)
* backend: support links * frontend: Support links * fmt * test: CODER_SUPPORT_LINKS_0_NAME * Go tests * Use UpdateAppearanceConfig * ui: UpdateAppearanceConfig * fix: fmt * Fix: site * Fix: site tests * fix: fmt * fix * test: check default support links
1 parent 16364db commit 2e53fb5

File tree

20 files changed

+642
-91
lines changed

20 files changed

+642
-91
lines changed

cli/deployment/config.go

+15
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ func newConfig() *codersdk.DeploymentConfig {
570570
Flag: "disable-password-auth",
571571
Default: false,
572572
},
573+
Support: &codersdk.SupportConfig{
574+
Links: &codersdk.DeploymentConfigField[[]codersdk.LinkConfig]{
575+
Name: "Support links",
576+
Usage: "Use custom support links",
577+
Flag: "support-links",
578+
Default: []codersdk.LinkConfig{},
579+
Enterprise: true,
580+
},
581+
},
573582
}
574583
}
575584

@@ -649,6 +658,10 @@ func setConfig(prefix string, vip *viper.Viper, target interface{}) {
649658
// Do not bind to CODER_GITAUTH, instead bind to CODER_GITAUTH_0_*, etc.
650659
values := readSliceFromViper[codersdk.GitAuthConfig](vip, prefix, value)
651660
val.FieldByName("Value").Set(reflect.ValueOf(values))
661+
case []codersdk.LinkConfig:
662+
// Do not bind to CODER_SUPPORT_LINKS, instead bind to CODER_SUPPORT_LINKS_0_*, etc.
663+
values := readSliceFromViper[codersdk.LinkConfig](vip, prefix, value)
664+
val.FieldByName("Value").Set(reflect.ValueOf(values))
652665
default:
653666
panic(fmt.Sprintf("unsupported type %T", value))
654667
}
@@ -824,6 +837,8 @@ func setFlags(prefix string, flagset *pflag.FlagSet, vip *viper.Viper, target in
824837
_ = flagset.DurationP(flg, shorthand, vip.GetDuration(prefix), usage)
825838
case []string:
826839
_ = flagset.StringSliceP(flg, shorthand, vip.GetStringSlice(prefix), usage)
840+
case []codersdk.LinkConfig:
841+
// Ignore this one!
827842
case []codersdk.GitAuthConfig:
828843
// Ignore this one!
829844
default:

cli/deployment/config_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,29 @@ func TestConfig(t *testing.T) {
222222
Regex: "gitlab.com",
223223
}}, config.GitAuth.Value)
224224
},
225+
}, {
226+
Name: "Support links",
227+
Env: map[string]string{
228+
"CODER_SUPPORT_LINKS_0_NAME": "First link",
229+
"CODER_SUPPORT_LINKS_0_TARGET": "http://target-link-1",
230+
"CODER_SUPPORT_LINKS_0_ICON": "bug",
231+
232+
"CODER_SUPPORT_LINKS_1_NAME": "Second link",
233+
"CODER_SUPPORT_LINKS_1_TARGET": "http://target-link-2",
234+
"CODER_SUPPORT_LINKS_1_ICON": "chat",
235+
},
236+
Valid: func(config *codersdk.DeploymentConfig) {
237+
require.Len(t, config.Support.Links.Value, 2)
238+
require.Equal(t, []codersdk.LinkConfig{{
239+
Name: "First link",
240+
Target: "http://target-link-1",
241+
Icon: "bug",
242+
}, {
243+
Name: "Second link",
244+
Target: "http://target-link-2",
245+
Icon: "chat",
246+
}}, config.Support.Links.Value)
247+
},
225248
}, {
226249
Name: "Wrong env must not break default values",
227250
Env: map[string]string{

coderd/apidoc/docs.go

+82-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+82-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/deployment.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ type DeploymentConfig struct {
153153
Address *DeploymentConfigField[string] `json:"address" typescript:",notnull"`
154154
// DEPRECATED: Use Experiments instead.
155155
Experimental *DeploymentConfigField[bool] `json:"experimental" typescript:",notnull"`
156+
157+
Support *SupportConfig `json:"support" typescript:",notnull"`
156158
}
157159

158160
type DERP struct {
@@ -276,8 +278,18 @@ type DangerousConfig struct {
276278
AllowPathAppSiteOwnerAccess *DeploymentConfigField[bool] `json:"allow_path_app_site_owner_access" typescript:",notnull"`
277279
}
278280

281+
type SupportConfig struct {
282+
Links *DeploymentConfigField[[]LinkConfig] `json:"links" typescript:",notnull"`
283+
}
284+
285+
type LinkConfig struct {
286+
Name string `json:"name"`
287+
Target string `json:"target"`
288+
Icon string `json:"icon"`
289+
}
290+
279291
type Flaggable interface {
280-
string | time.Duration | bool | int | []string | []GitAuthConfig
292+
string | time.Duration | bool | int | []string | []GitAuthConfig | []LinkConfig
281293
}
282294

283295
type DeploymentConfigField[T Flaggable] struct {
@@ -348,6 +360,12 @@ func (c *Client) DeploymentConfig(ctx context.Context) (DeploymentConfig, error)
348360
type AppearanceConfig struct {
349361
LogoURL string `json:"logo_url"`
350362
ServiceBanner ServiceBannerConfig `json:"service_banner"`
363+
SupportLinks []LinkConfig `json:"support_links,omitempty"`
364+
}
365+
366+
type UpdateAppearanceConfig struct {
367+
LogoURL string `json:"logo_url"`
368+
ServiceBanner ServiceBannerConfig `json:"service_banner"`
351369
}
352370

353371
type ServiceBannerConfig struct {
@@ -371,7 +389,7 @@ func (c *Client) Appearance(ctx context.Context) (AppearanceConfig, error) {
371389
return cfg, json.NewDecoder(res.Body).Decode(&cfg)
372390
}
373391

374-
func (c *Client) UpdateAppearance(ctx context.Context, appearance AppearanceConfig) error {
392+
func (c *Client) UpdateAppearance(ctx context.Context, appearance UpdateAppearanceConfig) error {
375393
res, err := c.Request(ctx, http.MethodPut, "/api/v2/appearance", appearance)
376394
if err != nil {
377395
return err

0 commit comments

Comments
 (0)