@@ -11,29 +11,13 @@ import (
1111 "golang.org/x/sync/errgroup"
1212 "golang.org/x/xerrors"
1313
14+ agpl "github.com/coder/coder/v2/coderd/appearance"
15+ "github.com/coder/coder/v2/coderd/database"
1416 "github.com/coder/coder/v2/coderd/httpapi"
1517 "github.com/coder/coder/v2/coderd/rbac"
1618 "github.com/coder/coder/v2/codersdk"
1719)
1820
19- var DefaultSupportLinks = []codersdk.LinkConfig {
20- {
21- Name : "Documentation" ,
22- Target : "https://coder.com/docs/coder-oss" ,
23- Icon : "docs" ,
24- },
25- {
26- Name : "Report a bug" ,
27- Target : "https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}" ,
28- Icon : "bug" ,
29- },
30- {
31- Name : "Join the Coder Discord" ,
32- Target : "https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer" ,
33- Icon : "chat" ,
34- },
35- }
36-
3721// @Summary Get appearance
3822// @ID get-appearance
3923// @Security CoderSessionToken
@@ -42,7 +26,8 @@ var DefaultSupportLinks = []codersdk.LinkConfig{
4226// @Success 200 {object} codersdk.AppearanceConfig
4327// @Router /appearance [get]
4428func (api * API ) appearance (rw http.ResponseWriter , r * http.Request ) {
45- cfg , err := api .fetchAppearanceConfig (r .Context ())
29+ af := * api .AGPL .AppearanceFetcher .Load ()
30+ cfg , err := af .Fetch (r .Context ())
4631 if err != nil {
4732 httpapi .Write (r .Context (), rw , http .StatusInternalServerError , codersdk.Response {
4833 Message : "Failed to fetch appearance config." ,
@@ -54,37 +39,39 @@ func (api *API) appearance(rw http.ResponseWriter, r *http.Request) {
5439 httpapi .Write (r .Context (), rw , http .StatusOK , cfg )
5540}
5641
57- func ( api * API ) fetchAppearanceConfig ( ctx context. Context ) (codersdk. AppearanceConfig , error ) {
58- api . entitlementsMu . RLock ()
59- isEntitled := api . entitlements . Features [ codersdk . FeatureAppearance ]. Entitlement == codersdk .EntitlementEntitled
60- api . entitlementsMu . RUnlock ()
42+ type appearanceFetcher struct {
43+ database database. Store
44+ supportLinks [] codersdk.LinkConfig
45+ }
6146
62- if ! isEntitled {
63- return codersdk. AppearanceConfig {
64- SupportLinks : DefaultSupportLinks ,
65- }, nil
47+ func newAppearanceFetcher ( store database. Store , links []codersdk. LinkConfig ) agpl. Fetcher {
48+ return & appearanceFetcher {
49+ database : store ,
50+ supportLinks : links ,
6651 }
52+ }
6753
54+ func (f * appearanceFetcher ) Fetch (ctx context.Context ) (codersdk.AppearanceConfig , error ) {
6855 var eg errgroup.Group
6956 var applicationName string
7057 var logoURL string
7158 var serviceBannerJSON string
7259 eg .Go (func () (err error ) {
73- applicationName , err = api . Database .GetApplicationName (ctx )
60+ applicationName , err = f . database .GetApplicationName (ctx )
7461 if err != nil && ! errors .Is (err , sql .ErrNoRows ) {
7562 return xerrors .Errorf ("get application name: %w" , err )
7663 }
7764 return nil
7865 })
7966 eg .Go (func () (err error ) {
80- logoURL , err = api . Database .GetLogoURL (ctx )
67+ logoURL , err = f . database .GetLogoURL (ctx )
8168 if err != nil && ! errors .Is (err , sql .ErrNoRows ) {
8269 return xerrors .Errorf ("get logo url: %w" , err )
8370 }
8471 return nil
8572 })
8673 eg .Go (func () (err error ) {
87- serviceBannerJSON , err = api . Database .GetServiceBanner (ctx )
74+ serviceBannerJSON , err = f . database .GetServiceBanner (ctx )
8875 if err != nil && ! errors .Is (err , sql .ErrNoRows ) {
8976 return xerrors .Errorf ("get service banner: %w" , err )
9077 }
@@ -108,10 +95,10 @@ func (api *API) fetchAppearanceConfig(ctx context.Context) (codersdk.AppearanceC
10895 }
10996 }
11097
111- if len (api . DeploymentValues . Support . Links . Value ) == 0 {
112- cfg .SupportLinks = DefaultSupportLinks
98+ if len (f . supportLinks ) == 0 {
99+ cfg .SupportLinks = agpl . DefaultSupportLinks
113100 } else {
114- cfg .SupportLinks = api . DeploymentValues . Support . Links . Value
101+ cfg .SupportLinks = f . supportLinks
115102 }
116103
117104 return cfg , nil
0 commit comments