Deprecate secret key in webhooks (#2119)

* Add deprecated message

* Extract messages

* Add deprecated pill to webhook secret key

* Update snapshots

* Move extra info to pill toolbar

* Extract messages

* Update snapshots

* Remove preventDefault

* Open link in a new tab

* Update snapshots

* Fix linter issue

* Make webhooks active by default when creating new ones

* Update snapshots
This commit is contained in:
Michał Droń 2022-07-07 10:29:33 +02:00 committed by GitHub
parent dc327f1f76
commit a54fc0396b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 201 additions and 39 deletions

View file

@ -324,6 +324,10 @@
"context": "field is optional", "context": "field is optional",
"string": "(Optional)" "string": "(Optional)"
}, },
"0kPdlb": {
"context": "deprecated secret key toolbar label",
"string": "Use RS256 signature instead."
},
"0krqBj": { "0krqBj": {
"context": "page header", "context": "page header",
"string": "Order no. {orderNumber} - Refund" "string": "Order no. {orderNumber} - Refund"
@ -5710,6 +5714,10 @@
"context": "copied to clipboard alert title", "context": "copied to clipboard alert title",
"string": "Copied to clipboard" "string": "Copied to clipboard"
}, },
"hnRRUe": {
"context": "docs link label",
"string": "Learn more..."
},
"ho75Lr": { "ho75Lr": {
"context": "status label deactivated", "context": "status label deactivated",
"string": "Deactivated" "string": "Deactivated"
@ -7832,6 +7840,9 @@
"context": "button", "context": "button",
"string": "View products" "string": "View products"
}, },
"z9c6/C": {
"string": "Deprecated"
},
"z9wQ/U": { "z9wQ/U": {
"context": "no variant stock in warehouse", "context": "no variant stock in warehouse",
"string": "No Stock" "string": "No Stock"

View file

@ -178,6 +178,10 @@ export const commonMessages = defineMessages({
defaultMessage: "Cant fulfill until payment is captured", defaultMessage: "Cant fulfill until payment is captured",
description: "disabled option description", description: "disabled option description",
}, },
deprecated: {
id: "z9c6/C",
defaultMessage: "Deprecated",
},
}); });
export const errorMessages = defineMessages({ export const errorMessages = defineMessages({

View file

@ -26396,15 +26396,26 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details default 1`] = `
Secret Key Secret Key
</label> </label>
<div <div
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id" class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id MuiInputBase-adornedEnd-id MuiOutlinedInput-adornedEnd-id"
> >
<input <input
aria-invalid="false" aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
name="secretKey" name="secretKey"
type="text" type="text"
value="zxczx_asdas" value="zxczx_asdas"
/> />
<div>
<div
class="MuiChip-root-id Pill-root-id Pill-error-id Pill-outlined-id Pill-small-id MuiChip-sizeSmall-id"
>
<span
class="MuiChip-label-id Pill-label-id MuiChip-labelSmall-id Pill-labelSmall-id"
>
Deprecated
</span>
</div>
</div>
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id" class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id"
@ -26890,15 +26901,26 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details form errors 1`] =
Secret Key Secret Key
</label> </label>
<div <div
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-error-id MuiOutlinedInput-error-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id" class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-error-id MuiOutlinedInput-error-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id MuiInputBase-adornedEnd-id MuiOutlinedInput-adornedEnd-id"
> >
<input <input
aria-invalid="true" aria-invalid="true"
class="MuiInputBase-input-id MuiOutlinedInput-input-id" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
name="secretKey" name="secretKey"
type="text" type="text"
value="zxczx_asdas" value="zxczx_asdas"
/> />
<div>
<div
class="MuiChip-root-id Pill-root-id Pill-error-id Pill-outlined-id Pill-small-id MuiChip-sizeSmall-id"
>
<span
class="MuiChip-label-id Pill-label-id MuiChip-labelSmall-id Pill-labelSmall-id"
>
Deprecated
</span>
</div>
</div>
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id" class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id"
@ -27381,16 +27403,27 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details loading 1`] = `
Secret Key Secret Key
</label> </label>
<div <div
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id" class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id MuiInputBase-adornedEnd-id MuiOutlinedInput-adornedEnd-id"
> >
<input <input
aria-invalid="false" aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-disabled-id MuiOutlinedInput-disabled-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
disabled="" disabled=""
name="secretKey" name="secretKey"
type="text" type="text"
value="" value=""
/> />
<div>
<div
class="MuiChip-root-id Pill-root-id Pill-error-id Pill-outlined-id Pill-small-id MuiChip-sizeSmall-id"
>
<span
class="MuiChip-label-id Pill-label-id MuiChip-labelSmall-id Pill-labelSmall-id"
>
Deprecated
</span>
</div>
</div>
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id" class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id"
@ -27443,13 +27476,14 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details loading 1`] = `
> >
<span <span
aria-disabled="true" aria-disabled="true"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id PrivateSwitchBase-disabled-id MuiCheckbox-disabled-id MuiIconButton-colorPrimary-id MuiIconButton-disabled-id MuiButtonBase-disabled-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id PrivateSwitchBase-checked-id MuiCheckbox-checked-id PrivateSwitchBase-disabled-id MuiCheckbox-disabled-id MuiIconButton-colorPrimary-id MuiIconButton-disabled-id MuiButtonBase-disabled-id"
tabindex="-1" tabindex="-1"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
> >
<input <input
checked=""
class="PrivateSwitchBase-input-id" class="PrivateSwitchBase-input-id"
data-indeterminate="false" data-indeterminate="false"
disabled="" disabled=""
@ -27462,18 +27496,28 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details loading 1`] = `
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
> >
<rect <svg
fill="transparent" fill="none"
height="22" height="24"
rx="2" viewBox="0 0 24 24"
ry="2" width="24"
stroke="currentColor" xmlns="http://www.w3.org/2000/svg"
stroke-linejoin="round" >
stroke-width="2" <rect
width="22" fill="currentColor"
x="1" height="23"
y="1" rx="1.5"
/> width="23"
x="0.5"
y="0.5"
/>
<path
clip-rule="evenodd"
d="M17.5711 4.7629C17.9653 4.34801 18.6267 4.34801 19.0209 4.7629L20.3455 6.1568C20.7122 6.54279 20.7122 7.14848 20.3455 7.53447L9.45066 19L3.65454 12.9002C3.28777 12.5143 3.28777 11.9086 3.65454 11.5226L4.97906 10.1287C5.3733 9.71378 6.03466 9.71378 6.4289 10.1287L9.45066 13.3087L17.5711 4.7629Z"
fill="var(--background-paper)"
fill-rule="evenodd"
/>
</svg>
</svg> </svg>
</span> </span>
</span> </span>
@ -27862,15 +27906,26 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details undefined 1`] = `
Secret Key Secret Key
</label> </label>
<div <div
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id" class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id MuiInputBase-adornedEnd-id MuiOutlinedInput-adornedEnd-id"
> >
<input <input
aria-invalid="false" aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
name="secretKey" name="secretKey"
type="text" type="text"
value="" value=""
/> />
<div>
<div
class="MuiChip-root-id Pill-root-id Pill-error-id Pill-outlined-id Pill-small-id MuiChip-sizeSmall-id"
>
<span
class="MuiChip-label-id Pill-label-id MuiChip-labelSmall-id Pill-labelSmall-id"
>
Deprecated
</span>
</div>
</div>
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id" class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id"
@ -27923,12 +27978,13 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details undefined 1`] = `
> >
<span <span
aria-disabled="false" aria-disabled="false"
class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id MuiIconButton-colorPrimary-id" class="MuiButtonBase-root-id MuiIconButton-root-id PrivateSwitchBase-root-id MuiCheckbox-root-id MuiCheckbox-colorPrimary-id PrivateSwitchBase-checked-id MuiCheckbox-checked-id MuiIconButton-colorPrimary-id"
> >
<span <span
class="MuiIconButton-label-id" class="MuiIconButton-label-id"
> >
<input <input
checked=""
class="PrivateSwitchBase-input-id" class="PrivateSwitchBase-input-id"
data-indeterminate="false" data-indeterminate="false"
name="isActive" name="isActive"
@ -27940,18 +27996,28 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details undefined 1`] = `
focusable="false" focusable="false"
viewBox="0 0 24 24" viewBox="0 0 24 24"
> >
<rect <svg
fill="transparent" fill="none"
height="22" height="24"
rx="2" viewBox="0 0 24 24"
ry="2" width="24"
stroke="currentColor" xmlns="http://www.w3.org/2000/svg"
stroke-linejoin="round" >
stroke-width="2" <rect
width="22" fill="currentColor"
x="1" height="23"
y="1" rx="1.5"
/> width="23"
x="0.5"
y="0.5"
/>
<path
clip-rule="evenodd"
d="M17.5711 4.7629C17.9653 4.34801 18.6267 4.34801 19.0209 4.7629L20.3455 6.1568C20.7122 6.54279 20.7122 7.14848 20.3455 7.53447L9.45066 19L3.65454 12.9002C3.28777 12.5143 3.28777 11.9086 3.65454 11.5226L4.97906 10.1287C5.3733 9.71378 6.03466 9.71378 6.4289 10.1287L9.45066 13.3087L17.5711 4.7629Z"
fill="var(--background-paper)"
fill-rule="evenodd"
/>
</svg>
</svg> </svg>
</span> </span>
</span> </span>
@ -28340,15 +28406,26 @@ exports[`Storyshots Views / Apps / Webhooks / Webhook details unnamed 1`] = `
Secret Key Secret Key
</label> </label>
<div <div
class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id" class="MuiInputBase-root-id MuiOutlinedInput-root-id MuiInputBase-fullWidth-id MuiInputBase-formControl-id MuiInputBase-adornedEnd-id MuiOutlinedInput-adornedEnd-id"
> >
<input <input
aria-invalid="false" aria-invalid="false"
class="MuiInputBase-input-id MuiOutlinedInput-input-id" class="MuiInputBase-input-id MuiOutlinedInput-input-id MuiInputBase-inputAdornedEnd-id MuiOutlinedInput-inputAdornedEnd-id"
name="secretKey" name="secretKey"
type="text" type="text"
value="zxczx_asdas" value="zxczx_asdas"
/> />
<div>
<div
class="MuiChip-root-id Pill-root-id Pill-error-id Pill-outlined-id Pill-small-id MuiChip-sizeSmall-id"
>
<span
class="MuiChip-label-id Pill-label-id MuiChip-labelSmall-id Pill-labelSmall-id"
>
Deprecated
</span>
</div>
</div>
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id" class="PrivateNotchedOutline-root-id MuiOutlinedInput-notchedOutline-id"

View file

@ -64,7 +64,7 @@ const WebhookDetailsPage: React.FC<WebhookDetailsPageProps> = ({
const initialForm: FormData = { const initialForm: FormData = {
syncEvents: webhook?.syncEvents?.map(event => event.eventType) || [], syncEvents: webhook?.syncEvents?.map(event => event.eventType) || [],
asyncEvents: webhook?.asyncEvents?.map(event => event.eventType) || [], asyncEvents: webhook?.asyncEvents?.map(event => event.eventType) || [],
isActive: !!webhook?.isActive, isActive: webhook?.isActive ?? true,
name: webhook?.name || "", name: webhook?.name || "",
secretKey: webhook?.secretKey || "", secretKey: webhook?.secretKey || "",
targetUrl: webhook?.targetUrl || "", targetUrl: webhook?.targetUrl || "",

View file

@ -1,16 +1,25 @@
import { Card, CardContent, TextField, Typography } from "@material-ui/core"; import {
Card,
CardContent,
Popper,
TextField,
Typography,
} from "@material-ui/core";
import CardTitle from "@saleor/components/CardTitle"; import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer"; import FormSpacer from "@saleor/components/FormSpacer";
import Hr from "@saleor/components/Hr"; import Hr from "@saleor/components/Hr";
import Link from "@saleor/components/Link";
import { WebhookErrorFragment } from "@saleor/graphql"; import { WebhookErrorFragment } from "@saleor/graphql";
import { commonMessages } from "@saleor/intl"; import { commonMessages } from "@saleor/intl";
import { Pill } from "@saleor/macaw-ui";
import { getFormErrors } from "@saleor/utils/errors"; import { getFormErrors } from "@saleor/utils/errors";
import getWebhookErrorMessage from "@saleor/utils/errors/webhooks"; import getWebhookErrorMessage from "@saleor/utils/errors/webhooks";
import React from "react"; import React from "react";
import { useIntl } from "react-intl"; import { FormattedMessage, useIntl } from "react-intl";
import { WebhookFormData } from "../WebhooksDetailsPage/WebhooksDetailsPage"; import { WebhookFormData } from "../WebhooksDetailsPage/WebhooksDetailsPage";
import { messages } from "./messages"; import { messages } from "./messages";
import { useStyles } from "./styles";
interface WebhookInfoProps { interface WebhookInfoProps {
data: WebhookFormData; data: WebhookFormData;
@ -26,9 +35,13 @@ const WebhookInfo: React.FC<WebhookInfoProps> = ({
onChange, onChange,
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
const classes = useStyles();
const formErrors = getFormErrors(["name", "targetUrl", "secretKey"], errors); const formErrors = getFormErrors(["name", "targetUrl", "secretKey"], errors);
const [isPopupOpen, setPopupOpen] = React.useState(false);
const anchor = React.useRef<HTMLDivElement>(null);
return ( return (
<Card> <Card>
<CardTitle title={intl.formatMessage(messages.webhookInformation)} /> <CardTitle title={intl.formatMessage(messages.webhookInformation)} />
@ -76,6 +89,40 @@ const WebhookInfo: React.FC<WebhookInfoProps> = ({
name="secretKey" name="secretKey"
value={data.secretKey} value={data.secretKey}
onChange={onChange} onChange={onChange}
InputProps={{
endAdornment: (
<div
ref={anchor}
onMouseOver={() => setPopupOpen(true)}
onMouseLeave={() => setPopupOpen(false)}
>
<Pill
label={intl.formatMessage(commonMessages.deprecated)}
color={"error"}
outlined
size="small"
/>
<Popper
anchorEl={anchor.current}
open={isPopupOpen}
placement={"top"}
>
<Card elevation={8} className={classes.toolbar}>
<Typography>
<FormattedMessage {...messages.useSignature} />
</Typography>
<Link
target="_blank"
rel="noopener noreferrer"
href="https://docs.saleor.io/docs/3.x/developer/extending/apps/synchronous-webhooks#payload-signature"
>
<FormattedMessage {...messages.learnMore} />
</Link>
</Card>
</Popper>
</div>
),
}}
/> />
</CardContent> </CardContent>
</Card> </Card>

View file

@ -32,4 +32,14 @@ export const messages = defineMessages({
"secret key is used to create a hash signature with each payload. *optional field", "secret key is used to create a hash signature with each payload. *optional field",
description: "webhook input help text", description: "webhook input help text",
}, },
useSignature: {
id: "0kPdlb",
defaultMessage: "Use RS256 signature instead.",
description: "deprecated secret key toolbar label",
},
learnMore: {
id: "hnRRUe",
defaultMessage: "Learn more...",
description: "docs link label",
},
}); });

View file

@ -0,0 +1,13 @@
import { makeStyles } from "@saleor/macaw-ui";
export const useStyles = makeStyles(
theme => ({
toolbar: {
padding: theme.spacing(2),
backgroundColor: theme.palette.saleor.fail.mid,
color: theme.palette.common.black,
marginBottom: theme.spacing(2),
},
}),
{ name: "WebhookInfo" },
);