From 1cc727e107335eb25f0a5e240ccdf59c0a46f62c Mon Sep 17 00:00:00 2001 From: Alexandre Monjol Date: Wed, 22 May 2024 19:08:20 +0200 Subject: [PATCH] feat: add rbac guards for integrations page --- .../settings/AdyenIntegrationDetails.tsx | 256 +++++++++------- src/pages/settings/AdyenIntegrations.tsx | 136 +++++---- .../settings/GocardlessIntegrationDetails.tsx | 287 ++++++++++-------- src/pages/settings/GocardlessIntegrations.tsx | 136 +++++---- .../settings/LagoTaxManagementIntegration.tsx | 41 +-- .../settings/StripeIntegrationDetails.tsx | 260 +++++++++------- src/pages/settings/StripeIntegrations.tsx | 137 +++++---- 7 files changed, 692 insertions(+), 561 deletions(-) diff --git a/src/pages/settings/AdyenIntegrationDetails.tsx b/src/pages/settings/AdyenIntegrationDetails.tsx index d14c15962..405e185e5 100644 --- a/src/pages/settings/AdyenIntegrationDetails.tsx +++ b/src/pages/settings/AdyenIntegrationDetails.tsx @@ -36,6 +36,7 @@ import { useGetAdyenIntegrationsDetailsQuery, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import Adyen from '~/public/images/adyen.svg' import { MenuPopper, NAV_HEIGHT, PageHeader, PopperOpener, theme } from '~/styles' @@ -85,6 +86,7 @@ const AdyenIntegrationDetails = () => { const deleteDialogRef = useRef(null) const successRedirectUrlDialogRef = useRef(null) const { translate } = useInternationalization() + const { hasPermissions } = usePermissions() const { data, loading } = useGetAdyenIntegrationsDetailsQuery({ variables: { id: integrationId as string, @@ -101,6 +103,8 @@ const AdyenIntegrationDetails = () => { navigate(INTEGRATIONS_ROUTE) } } + const canEditIntegration = hasPermissions(['organizationIntegrationsUpdate']) + const canDeleteIntegration = hasPermissions(['organizationIntegrationsDelete']) return ( <> @@ -119,46 +123,52 @@ const AdyenIntegrationDetails = () => { )} - {translate('text_626162c62f790600f850b6fe')} - } - > - {({ closePopper }) => ( - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + {translate('text_626162c62f790600f850b6fe')} + } + > + {({ closePopper }) => ( + + {canEditIntegration && ( + + )} + {canDeleteIntegration && ( + + )} + + )} + + )} @@ -193,19 +203,22 @@ const AdyenIntegrationDetails = () => {
{translate('text_645d071272418a14c1c76a9a')} - + + {canEditIntegration && ( + + )} <> @@ -310,19 +323,21 @@ const AdyenIntegrationDetails = () => {
{translate('text_65367cb78324b77fcb6af21c')} - + {canEditIntegration && ( + + )} {loading ? ( @@ -353,57 +368,64 @@ const AdyenIntegrationDetails = () => { - ( - - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + ( + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} )} diff --git a/src/pages/settings/AdyenIntegrations.tsx b/src/pages/settings/AdyenIntegrations.tsx index 5faa2d544..d3bd0d035 100644 --- a/src/pages/settings/AdyenIntegrations.tsx +++ b/src/pages/settings/AdyenIntegrations.tsx @@ -37,6 +37,7 @@ import { useGetAdyenIntegrationsListQuery, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import Adyen from '~/public/images/adyen.svg' import { ItemContainer, @@ -75,6 +76,7 @@ gql` const AdyenIntegrations = () => { const navigate = useNavigate() + const { hasPermissions } = usePermissions() const addAdyenDialogRef = useRef(null) const deleteDialogRef = useRef(null) const successRedirectUrlDialogRef = useRef(null) @@ -86,6 +88,10 @@ const AdyenIntegrations = () => { const deleteDialogCallback = connections && connections.length === 1 ? () => navigate(INTEGRATIONS_ROUTE) : undefined + const canCreateIntegration = hasPermissions(['organizationIntegrationsCreate']) + const canEditIntegration = hasPermissions(['organizationIntegrationsUpdate']) + const canDeleteIntegration = hasPermissions(['organizationIntegrationsDelete']) + return ( <> @@ -103,14 +109,17 @@ const AdyenIntegrations = () => { )} - + + {canCreateIntegration && ( + + )} {loading ? ( @@ -181,58 +190,65 @@ const AdyenIntegrations = () => { - ( - - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + ( + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} ) })} diff --git a/src/pages/settings/GocardlessIntegrationDetails.tsx b/src/pages/settings/GocardlessIntegrationDetails.tsx index ba5ab4a1e..f53b20bba 100644 --- a/src/pages/settings/GocardlessIntegrationDetails.tsx +++ b/src/pages/settings/GocardlessIntegrationDetails.tsx @@ -39,6 +39,7 @@ import { useGetGocardlessIntegrationsDetailsQuery, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import GoCardless from '~/public/images/gocardless-large.svg' import { MenuPopper, NAV_HEIGHT, PageHeader, PopperOpener, theme } from '~/styles' @@ -80,6 +81,7 @@ const GocardlessIntegrationDetails = () => { const navigate = useNavigate() const { integrationId } = useParams() const { lagoOauthProxyUrl } = envGlobalVar() + const { hasPermissions } = usePermissions() const addDialogRef = useRef(null) const deleteDialogRef = useRef(null) const successRedirectUrlDialogRef = useRef(null) @@ -102,6 +104,9 @@ const GocardlessIntegrationDetails = () => { } } + const canEditIntegration = hasPermissions(['organizationIntegrationsUpdate']) + const canDeleteIntegration = hasPermissions(['organizationIntegrationsDelete']) + return (
@@ -119,59 +124,68 @@ const GocardlessIntegrationDetails = () => { )} - {translate('text_626162c62f790600f850b6fe')} - } - > - {({ closePopper }) => ( - - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + {translate('text_626162c62f790600f850b6fe')} + } + > + {({ closePopper }) => ( + + {canEditIntegration && ( + <> + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} {loading ? ( @@ -207,19 +221,22 @@ const GocardlessIntegrationDetails = () => {
{translate('text_637f813d31381b1ed90ab315')} - + + {canEditIntegration && ( + + )} {loading ? ( <> @@ -303,19 +320,22 @@ const GocardlessIntegrationDetails = () => {
{translate('text_65367cb78324b77fcb6af21c')} - + + {canEditIntegration && ( + + )} {loading ? ( @@ -346,57 +366,64 @@ const GocardlessIntegrationDetails = () => {
- ( - - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + ( + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} )} diff --git a/src/pages/settings/GocardlessIntegrations.tsx b/src/pages/settings/GocardlessIntegrations.tsx index 446afe87a..0602e8575 100644 --- a/src/pages/settings/GocardlessIntegrations.tsx +++ b/src/pages/settings/GocardlessIntegrations.tsx @@ -37,6 +37,7 @@ import { useGetGocardlessIntegrationsListQuery, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import Gocardless from '~/public/images/gocardless.svg' import { ItemContainer, @@ -75,6 +76,7 @@ gql` const GocardlessIntegrations = () => { const navigate = useNavigate() + const { hasPermissions } = usePermissions() const addGocardlessDialogRef = useRef(null) const deleteDialogRef = useRef(null) const successRedirectUrlDialogRef = useRef(null) @@ -86,6 +88,10 @@ const GocardlessIntegrations = () => { const deleteDialogCallback = connections && connections.length === 1 ? () => navigate(INTEGRATIONS_ROUTE) : undefined + const canCreateIntegration = hasPermissions(['organizationIntegrationsCreate']) + const canEditIntegration = hasPermissions(['organizationIntegrationsUpdate']) + const canDeleteIntegration = hasPermissions(['organizationIntegrationsDelete']) + return ( <> @@ -103,14 +109,17 @@ const GocardlessIntegrations = () => { )} - + + {canCreateIntegration && ( + + )} {loading ? ( @@ -181,58 +190,65 @@ const GocardlessIntegrations = () => { - ( - - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + ( + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} ) })} diff --git a/src/pages/settings/LagoTaxManagementIntegration.tsx b/src/pages/settings/LagoTaxManagementIntegration.tsx index 6f95fbac1..72cb4ffd2 100644 --- a/src/pages/settings/LagoTaxManagementIntegration.tsx +++ b/src/pages/settings/LagoTaxManagementIntegration.tsx @@ -30,6 +30,7 @@ import { useRemoveTaxManagementIntegrationMutation, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import LagoTaxManagement from '~/public/images/lago-tax-management.svg' import { HEADER_TABLE_HEIGHT, NAV_HEIGHT, PageHeader, theme } from '~/styles' @@ -66,6 +67,7 @@ gql` const LagoTaxManagementIntegration = () => { const navigate = useNavigate() const { translate } = useInternationalization() + const { hasPermissions } = usePermissions() const deleteConnectionRef = useRef(null) const { data: organizationData, loading: organizationLoading } = @@ -105,13 +107,15 @@ const LagoTaxManagementIntegration = () => { )} - + {hasPermissions(['organizationIntegrationsDelete']) && ( + + )} {loading ? ( @@ -167,7 +171,7 @@ const LagoTaxManagementIntegration = () => { )} - {!loading && ( + {!loading && hasPermissions(['organizationView']) && ( {
{translate('text_657078c28394d6b1ae1b9743')} - + + {hasPermissions(['organizationTaxesView']) && ( + + )} {loading ? ( diff --git a/src/pages/settings/StripeIntegrationDetails.tsx b/src/pages/settings/StripeIntegrationDetails.tsx index 8f5068b97..148677020 100644 --- a/src/pages/settings/StripeIntegrationDetails.tsx +++ b/src/pages/settings/StripeIntegrationDetails.tsx @@ -37,6 +37,7 @@ import { useGetStripeIntegrationsDetailsQuery, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import Stripe from '~/public/images/stripe.svg' import { MenuPopper, NAV_HEIGHT, PageHeader, PopperOpener, theme } from '~/styles' @@ -79,6 +80,7 @@ gql` const StripeIntegrationDetails = () => { const navigate = useNavigate() const { integrationId } = useParams() + const { hasPermissions } = usePermissions() const addDialogRef = useRef(null) const deleteDialogRef = useRef(null) const successRedirectUrlDialogRef = useRef(null) @@ -100,6 +102,9 @@ const StripeIntegrationDetails = () => { } } + const canEditIntegration = hasPermissions(['organizationIntegrationsUpdate']) + const canDeleteIntegration = hasPermissions(['organizationIntegrationsDelete']) + return ( <> @@ -117,46 +122,53 @@ const StripeIntegrationDetails = () => { )} - {translate('text_626162c62f790600f850b6fe')} - } - > - {({ closePopper }) => ( - - - - - )} - + {(canEditIntegration || canDeleteIntegration) && ( + {translate('text_626162c62f790600f850b6fe')} + } + > + {({ closePopper }) => ( + + {canEditIntegration && ( + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} @@ -191,19 +203,22 @@ const StripeIntegrationDetails = () => {
{translate('text_657078c28394d6b1ae1b9725')} - + + {canEditIntegration && ( + + )} @@ -274,19 +289,22 @@ const StripeIntegrationDetails = () => {
{translate('text_65367cb78324b77fcb6af21c')} - + + {canEditIntegration && ( + + )} {loading ? ( @@ -317,57 +335,65 @@ const StripeIntegrationDetails = () => { - ( - - - - - - )} - + + {(canEditIntegration || canDeleteIntegration) && ( + ( + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} )} diff --git a/src/pages/settings/StripeIntegrations.tsx b/src/pages/settings/StripeIntegrations.tsx index a045bd933..c8fdf84f3 100644 --- a/src/pages/settings/StripeIntegrations.tsx +++ b/src/pages/settings/StripeIntegrations.tsx @@ -37,6 +37,7 @@ import { useGetStripeIntegrationsListQuery, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { usePermissions } from '~/hooks/usePermissions' import Stripe from '~/public/images/stripe.svg' import { ItemContainer, @@ -75,6 +76,7 @@ gql` const StripeIntegrations = () => { const navigate = useNavigate() + const { hasPermissions } = usePermissions() const addStripeDialogRef = useRef(null) const deleteDialogRef = useRef(null) const successRedirectUrlDialogRef = useRef(null) @@ -86,6 +88,10 @@ const StripeIntegrations = () => { const deleteDialogCallback = connections && connections.length === 1 ? () => navigate(INTEGRATIONS_ROUTE) : undefined + const canCreateIntegration = hasPermissions(['organizationIntegrationsCreate']) + const canEditIntegration = hasPermissions(['organizationIntegrationsUpdate']) + const canDeleteIntegration = hasPermissions(['organizationIntegrationsDelete']) + return ( <> @@ -103,14 +109,17 @@ const StripeIntegrations = () => { )} - + + {canCreateIntegration && ( + + )} {loading ? ( @@ -181,58 +190,66 @@ const StripeIntegrations = () => { - ( - - - - - - )} - + + {(canEditIntegration || canDeleteIntegration) && ( + ( + + + + )} + + {canDeleteIntegration && ( + + )} + + )} + + )} ) })}