From 61a1a97ca801b38f89805e209d412404b7320ef8 Mon Sep 17 00:00:00 2001 From: jnfrati Date: Fri, 23 Jul 2021 18:58:11 -0300 Subject: [PATCH] Fixed visual bugs and added RBAC to create webhook token button --- .../expanded-chart/SettingsSection.tsx | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/dashboard/src/main/home/cluster-dashboard/expanded-chart/SettingsSection.tsx b/dashboard/src/main/home/cluster-dashboard/expanded-chart/SettingsSection.tsx index ed1761e627..5d51e2692c 100644 --- a/dashboard/src/main/home/cluster-dashboard/expanded-chart/SettingsSection.tsx +++ b/dashboard/src/main/home/cluster-dashboard/expanded-chart/SettingsSection.tsx @@ -17,6 +17,8 @@ import Heading from "components/values-form/Heading"; import Helper from "components/values-form/Helper"; import _ from "lodash"; import CopyToClipboard from "components/CopyToClipboard"; +import useAuth from "shared/auth/useAuth"; +import Loading from "components/Loading"; type PropsType = { currentChart: ChartType; @@ -44,6 +46,7 @@ const SettingsSection: React.FC = ({ createWebhookButtonStatus, setCreateWebhookButtonStatus, ] = useState(""); + const [loadingWebhookToken, setLoadingWebhookToken] = useState(true); const [action, setAction] = useState({ git_repo: "", @@ -55,9 +58,11 @@ const SettingsSection: React.FC = ({ const { currentCluster, currentProject, setCurrentError } = useContext( Context ); + const [isAuthorized] = useAuth(); useEffect(() => { let isSubscribed = true; + setLoadingWebhookToken(true); const image = currentChart?.config?.image; setSelectedImageUrl(image?.repository); setSelectedTag(image?.tag); @@ -80,7 +85,8 @@ const SettingsSection: React.FC = ({ setAction(res.data.git_action_config); setWebhookToken(res.data.webhook_token); }) - .catch(console.log); + .catch(console.log) + .finally(() => setLoadingWebhookToken(false)); return () => (isSubscribed = false); }, [currentChart, currentCluster, currentProject]); @@ -181,6 +187,18 @@ const SettingsSection: React.FC = ({ const curlWebhook = `curl -X POST 'https://dashboard.getporter.dev/api/webhooks/deploy/${webhookToken}?commit=YOUR_COMMIT_HASH'`; + const isAuthorizedToCreateWebhook = isAuthorized("application", "", [ + "get", + "create", + "update", + ]); + + let buttonStatus = createWebhookButtonStatus; + + if (!isAuthorizedToCreateWebhook) { + buttonStatus = "Unauthorized to create webhook token"; + } + return ( <> {showSource && ( @@ -204,13 +222,15 @@ const SettingsSection: React.FC = ({ Programmatically deploy by calling this secret webhook. - {!webhookToken.length && ( + + {!loadingWebhookToken && !webhookToken.length && ( )} {webhookToken.length > 0 && ( @@ -236,14 +256,18 @@ const SettingsSection: React.FC = ({ return ( - - {renderWebhookSection()} - Additional Settings - - - {showSource && ( + {!loadingWebhookToken ? ( + + {renderWebhookSection()} + Additional Settings + + + ) : ( + + )} + {!loadingWebhookToken && showSource && (