Skip to content

Commit b36838f

Browse files
committed
Use UpdateAppearanceConfig
1 parent 132324c commit b36838f

File tree

8 files changed

+77
-43
lines changed

8 files changed

+77
-43
lines changed

coderd/apidoc/docs.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/deployment.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ type AppearanceConfig struct {
363363
SupportLinks []LinkConfig `json:"support_links,omitempty"`
364364
}
365365

366+
type UpdateAppearanceConfig struct {
367+
LogoURL string `json:"logo_url"`
368+
ServiceBanner ServiceBannerConfig `json:"service_banner"`
369+
}
370+
366371
type ServiceBannerConfig struct {
367372
Enabled bool `json:"enabled"`
368373
Message string `json:"message,omitempty"`
@@ -384,7 +389,7 @@ func (c *Client) Appearance(ctx context.Context) (AppearanceConfig, error) {
384389
return cfg, json.NewDecoder(res.Body).Decode(&cfg)
385390
}
386391

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

docs/api/enterprise.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,15 @@ curl -X PUT http://coder-server:8080/api/v2/appearance \
6666
"background_color": "string",
6767
"enabled": true,
6868
"message": "string"
69-
},
70-
"support_links": [
71-
{
72-
"icon": "string",
73-
"name": "string",
74-
"target": "string"
75-
}
76-
]
69+
}
7770
}
7871
```
7972

8073
### Parameters
8174

82-
| Name | In | Type | Required | Description |
83-
| ------ | ---- | ---------------------------------------------------------------- | -------- | ------------------------- |
84-
| `body` | body | [codersdk.AppearanceConfig](schemas.md#codersdkappearanceconfig) | true | Update appearance request |
75+
| Name | In | Type | Required | Description |
76+
| ------ | ---- | ---------------------------------------------------------------------------- | -------- | ------------------------- |
77+
| `body` | body | [codersdk.UpdateAppearanceConfig](schemas.md#codersdkupdateappearanceconfig) | true | Update appearance request |
8578

8679
### Example responses
8780

@@ -94,22 +87,15 @@ curl -X PUT http://coder-server:8080/api/v2/appearance \
9487
"background_color": "string",
9588
"enabled": true,
9689
"message": "string"
97-
},
98-
"support_links": [
99-
{
100-
"icon": "string",
101-
"name": "string",
102-
"target": "string"
103-
}
104-
]
90+
}
10591
}
10692
```
10793

10894
### Responses
10995

110-
| Status | Meaning | Description | Schema |
111-
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------------------------------- |
112-
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.AppearanceConfig](schemas.md#codersdkappearanceconfig) |
96+
| Status | Meaning | Description | Schema |
97+
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------- |
98+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.UpdateAppearanceConfig](schemas.md#codersdkupdateappearanceconfig) |
11399

114100
To perform this operation, you must be authenticated. [Learn more](authentication.md).
115101

docs/api/schemas.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4887,6 +4887,26 @@ Parameter represents a set value for the scope.
48874887
| ---- | ------ | -------- | ------------ | ----------- |
48884888
| `id` | string | true | | |
48894889

4890+
## codersdk.UpdateAppearanceConfig
4891+
4892+
```json
4893+
{
4894+
"logo_url": "string",
4895+
"service_banner": {
4896+
"background_color": "string",
4897+
"enabled": true,
4898+
"message": "string"
4899+
}
4900+
}
4901+
```
4902+
4903+
### Properties
4904+
4905+
| Name | Type | Required | Restrictions | Description |
4906+
| ---------------- | ------------------------------------------------------------ | -------- | ------------ | ----------- |
4907+
| `logo_url` | string | false | | |
4908+
| `service_banner` | [codersdk.ServiceBannerConfig](#codersdkservicebannerconfig) | false | | |
4909+
48904910
## codersdk.UpdateCheckResponse
48914911

48924912
```json

enterprise/coderd/appearance.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ func validateHexColor(color string) error {
113113
// @Accept json
114114
// @Produce json
115115
// @Tags Enterprise
116-
// @Param request body codersdk.AppearanceConfig true "Update appearance request"
117-
// @Success 200 {object} codersdk.AppearanceConfig
116+
// @Param request body codersdk.UpdateAppearanceConfig true "Update appearance request"
117+
// @Success 200 {object} codersdk.UpdateAppearanceConfig
118118
// @Router /appearance [put]
119119
func (api *API) putAppearance(rw http.ResponseWriter, r *http.Request) {
120120
ctx := r.Context()
@@ -126,18 +126,11 @@ func (api *API) putAppearance(rw http.ResponseWriter, r *http.Request) {
126126
return
127127
}
128128

129-
var appearance codersdk.AppearanceConfig
129+
var appearance codersdk.UpdateAppearanceConfig
130130
if !httpapi.Read(ctx, rw, r, &appearance) {
131131
return
132132
}
133133

134-
if len(appearance.SupportLinks) > 0 {
135-
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
136-
Message: "Support links cannot be dynamically updated, use the config file instead.",
137-
})
138-
return
139-
}
140-
141134
if appearance.ServiceBanner.Enabled {
142135
if err := validateHexColor(appearance.ServiceBanner.BackgroundColor); err != nil {
143136
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{

enterprise/coderd/appearance_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ func TestServiceBanners(t *testing.T) {
4343

4444
basicUserClient, _ := coderdtest.CreateAnotherUser(t, adminClient, adminUser.OrganizationID)
4545

46-
sb.SupportLinks = nil // clean "support links" as they can't be modified using API
47-
46+
uac := codersdk.UpdateAppearanceConfig{
47+
ServiceBanner: sb.ServiceBanner,
48+
}
4849
// Regular user should be unable to set the banner
49-
sb.ServiceBanner.Enabled = true
50-
err = basicUserClient.UpdateAppearance(ctx, sb)
50+
uac.ServiceBanner.Enabled = true
51+
52+
err = basicUserClient.UpdateAppearance(ctx, uac)
5153
require.Error(t, err)
5254
var sdkError *codersdk.Error
5355
require.True(t, errors.As(err, &sdkError))
5456
require.Equal(t, http.StatusForbidden, sdkError.StatusCode())
5557

5658
// But an admin can
57-
wantBanner := sb
59+
wantBanner := uac
5860
wantBanner.ServiceBanner.Enabled = true
5961
wantBanner.ServiceBanner.Message = "Hey"
6062
wantBanner.ServiceBanner.BackgroundColor = "#00FF00"
@@ -63,7 +65,7 @@ func TestServiceBanners(t *testing.T) {
6365
gotBanner, err := adminClient.Appearance(ctx)
6466
require.NoError(t, err)
6567
gotBanner.SupportLinks = nil // clean "support links" before comparison
66-
require.Equal(t, wantBanner, gotBanner)
68+
require.Equal(t, wantBanner.ServiceBanner, gotBanner.ServiceBanner)
6769

6870
// But even an admin can't give a bad color
6971
wantBanner.ServiceBanner.BackgroundColor = "#bad color"

site/src/api/typesGenerated.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,12 @@ export interface UpdateActiveTemplateVersion {
827827
readonly id: string
828828
}
829829

830+
// From codersdk/deployment.go
831+
export interface UpdateAppearanceConfig {
832+
readonly logo_url: string
833+
readonly service_banner: ServiceBannerConfig
834+
}
835+
830836
// From codersdk/updatecheck.go
831837
export interface UpdateCheckResponse {
832838
readonly current: boolean

0 commit comments

Comments
 (0)