8000 feat: Enable custom support links by mtojek · Pull Request #6313 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Enable custom support links #6313

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use UpdateAppearanceConfig
  • Loading branch information
mtojek committed Feb 23, 2023
commit b36838f7f7958fe9a4afa68c1fc3a8bd4bcbacc4
15 changes: 13 additions & 2 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ type AppearanceConfig struct {
SupportLinks []LinkConfig `json:"support_links,omitempty"`
}

type UpdateAppearanceConfig struct {
LogoURL string `json:"logo_url"`
ServiceBanner ServiceBannerConfig `json:"service_banner"`
}

type ServiceBannerConfig struct {
Enabled bool `json:"enabled"`
Message string `json:"message,omitempty"`
Expand All @@ -384,7 +389,7 @@ func (c *Client) Appearance(ctx context.Context) (AppearanceConfig, error) {
return cfg, json.NewDecoder(res.Body).Decode(&cfg)
}

func (c *Client) UpdateAppearance(ctx context.Context, appearance AppearanceConfig) error {
func (c *Client) UpdateAppearance(ctx context.Context, appearance UpdateAppearanceConfig) error {
res, err := c.Request(ctx, http.MethodPut, "/api/v2/appearance", appearance)
if err != nil {
return err
Expand Down
30 changes: 8 additions & 22 deletions docs/api/enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,15 @@ curl -X PUT http://coder-server:8080/api/v2/appearance \
"background_color": "string",
"enabled": true,
"message": "string"
},
"support_links": [
{
"icon": "string",
"name": "string",
"target": "string"
}
]
}
}
```

### Parameters

| Name | In | Type | Required | Description |
| ------ | ---- | ---------------------------------------------------------------- | -------- | ------------------------- |
| `body` | body | [codersdk.AppearanceConfig](schemas.md#codersdkappearanceconfig) | true | Update appearance request |
| Name | In | Type | Required | Description |
| ------ | ---- | ---------------------------------------------------------------------------- | -------- | ------------------------- |
| `body` | body | [codersdk.UpdateAppearanceConfig](schemas.md#codersdkupdateappearanceconfig) | true | Update appearance request |

### Example responses

Expand All @@ -94,22 +87,15 @@ curl -X PUT http://coder-server:8080/api/v2/appearance \
"background_color": "string",
"enabled": true,
"message": "string"
},
"support_links": [
{
"icon": "string",
"name": "string",
"target": "string"
}
]
}
}
```

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------------------------------- |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.AppearanceConfig](schemas.md#codersdkappearanceconfig) |
| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------- |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.UpdateAppearanceConfig](schemas.md#codersdkupdateappearanceconfig) |

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

Expand Down
20 changes: 20 additions & 0 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -4887,6 +4887,26 @@ Parameter represents a set value for the scope.
| ---- | ------ | -------- | ------------ | ----------- |
| `id` | string | true | | |

## codersdk.UpdateAppearanceConfig

```json
{
"logo_url": "string",
"service_banner": {
"background_color": "string",
"enabled": true,
"message": "string"
}
}
```

### Properties

| Name | Type | Required | Restrictions | Description |
| ---------------- | ------------------------------------------------------------ | -------- | ------------ | ----------- |
| `logo_url` | string | false | | |
| `service_banner` | [codersdk.ServiceBannerConfig](#codersdkservicebannerconfig) | false | | |

## codersdk.UpdateCheckResponse

```json
Expand Down
13 changes: 3 additions & 10 deletions enterprise/coderd/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func validateHexColor(color string) error {
// @Accept json
// @Produce json
// @Tags Enterprise
// @Param request body codersdk.AppearanceConfig true "Update appearance request"
// @Success 200 {object} codersdk.AppearanceConfig
// @Param request body codersdk.UpdateAppearanceConfig true "Update appearance request"
// @Success 200 {object} codersdk.UpdateAppearanceConfig
// @Router /appearance [put]
func (api *API) putAppearance(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand All @@ -126,18 +126,11 @@ func (api *API) putAppearance(rw http.ResponseWriter, r *http.Request) {
return
}

var appearance codersdk.AppearanceConfig
var appearance codersdk.UpdateAppearanceConfig
if !httpapi.Read(ctx, rw, r, &appearance) {
return
}

if len(appearance.SupportLinks) > 0 {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Support links cannot be dynamically updated, use the config file instead.",
})
return
}

if appearance.ServiceBanner.Enabled {
if err := validateHexColor(appearance.ServiceBanner.BackgroundColor); err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Expand Down
14 changes: 8 additions & 6 deletions enterprise/coderd/appearance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ func TestServiceBanners(t *testing.T) {

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

sb.SupportLinks = nil // clean "support links" as they can't be modified using API

uac := codersdk.UpdateAppearanceConfig{
ServiceBanner: sb.ServiceBanner,
}
// Regular user should be unable to set the banner
sb.ServiceBanner.Enabled = true
err = basicUserClient.UpdateAppearance(ctx, sb)
uac.ServiceBanner.Enabled = true

err = basicUserClient.UpdateAppearance(ctx, uac)
require.Error(t, err)
var sdkError *codersdk.Error
require.True(t, errors.As(err, &sdkError))
require.Equal(t, http.StatusForbidden, sdkError.StatusCode())

// But an admin can
wantBanner := sb
wantBanner := uac
wantBanner.ServiceBanner.Enabled = true
wantBanner.ServiceBanner.Message = "Hey"
wantBanner.ServiceBanner.BackgroundColor = "#00FF00"
Expand All @@ -63,7 +65,7 @@ func TestServiceBanners(t *testing.T) {
gotBanner, err := adminClient.Appearance(ctx)
require.NoError(t, err)
gotBanner.SupportLinks = nil // clean "support links" before comparison
require.Equal(t, wantBanner, gotBanner)
require.Equal(t, wantBanner.ServiceBanner, gotBanner.ServiceBanner)

// But even an admin can't give a bad color
wantBanner.ServiceBanner.BackgroundColor = "#bad color"
Expand Down
6 changes: 6 additions & 0 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,12 @@ export interface UpdateActiveTemplateVersion {
readonly id: string
}

// From codersdk/deployment.go
export interface UpdateAppearanceConfig {
readonly logo_url: string
readonly service_banner: ServiceBannerConfig
}

// From codersdk/updatecheck.go
export interface UpdateCheckResponse {
readonly current: boolean
Expand Down
0