From 77fb1f0235dc820d20d689ae50f39b5811a8f67a Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Thu, 4 Jul 2024 16:23:33 +0200 Subject: [PATCH] UI service permissions (#2355) * change(ui): permission check for service accountts * change(ui): permission check for service accountts condition with or --- frontend/app/components/Assist/Assist.tsx | 3 +-- frontend/app/components/Session/Session.tsx | 4 +-- .../app/components/hocs/withPermissions.js | 25 ++++++++++--------- .../LiveSessionList/LiveSessionList.tsx | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/frontend/app/components/Assist/Assist.tsx b/frontend/app/components/Assist/Assist.tsx index 213de3f8f..92ffa2c56 100644 --- a/frontend/app/components/Assist/Assist.tsx +++ b/frontend/app/components/Assist/Assist.tsx @@ -15,7 +15,6 @@ function Assist(props: Props) { return ( ); - } const Cont = connect((state: any) => ({ @@ -25,5 +24,5 @@ const Cont = connect((state: any) => ({ }))(Assist); export default withPageTitle('Assist - OpenReplay')( - withPermissions(['ASSIST_LIVE', 'SERVICE_ASSIST_LIVE'])(withRouter(Cont)) + withPermissions(['ASSIST_LIVE', 'SERVICE_ASSIST_LIVE'], '', false, false)(withRouter(Cont)) ); diff --git a/frontend/app/components/Session/Session.tsx b/frontend/app/components/Session/Session.tsx index 72e048b3f..026ae0c7b 100644 --- a/frontend/app/components/Session/Session.tsx +++ b/frontend/app/components/Session/Session.tsx @@ -72,9 +72,7 @@ function Session({ } export default withPermissions( - ['SESSION_REPLAY', 'SERVICE_SESSION_REPLAY'], - '', - true + ['SESSION_REPLAY', 'SERVICE_SESSION_REPLAY'], '', true, false )( connect( (state: any, props: any) => { diff --git a/frontend/app/components/hocs/withPermissions.js b/frontend/app/components/hocs/withPermissions.js index f31730553..2b3a5d60a 100644 --- a/frontend/app/components/hocs/withPermissions.js +++ b/frontend/app/components/hocs/withPermissions.js @@ -1,20 +1,20 @@ -import React from "react"; -import { connect } from "react-redux"; -import { NoPermission, NoSessionPermission } from "UI"; +import React from 'react'; +import { connect } from 'react-redux'; +import { NoPermission, NoSessionPermission } from 'UI'; -export default (requiredPermissions, className, isReplay = false) => (BaseComponent) => { +export default (requiredPermissions, className, isReplay = false, andEd = true) => (BaseComponent) => { @connect((state, props) => ({ permissions: - state.getIn(["user", "account", "permissions"]) || [], + state.getIn(['user', 'account', 'permissions']) || [], isEnterprise: - state.getIn(["user", "account", "edition"]) === "ee", + state.getIn(['user', 'account', 'edition']) === 'ee' })) class WrapperClass extends React.PureComponent { render() { - const hasPermission = requiredPermissions.every( - (permission) => - this.props.permissions.includes(permission) - ); + const hasPermission = andEd ? + requiredPermissions.every((permission) => this.props.permissions.includes(permission)) : + requiredPermissions.some((permission) => this.props.permissions.includes(permission) + ); return !this.props.isEnterprise || hasPermission ? ( @@ -29,5 +29,6 @@ export default (requiredPermissions, className, isReplay = false) => (BaseCompon ); } } - return WrapperClass -} \ No newline at end of file + + return WrapperClass; +} diff --git a/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx b/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx index 6d4c68e51..746efce60 100644 --- a/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx +++ b/frontend/app/components/shared/LiveSessionList/LiveSessionList.tsx @@ -185,7 +185,7 @@ function LiveSessionList(props: Props) { ); } -export default withPermissions(['ASSIST_LIVE', 'SERVICE_ASSIST_LIVE'])( +export default withPermissions(['ASSIST_LIVE', 'SERVICE_ASSIST_LIVE'], '', false, false)( connect( (state: any) => ({ list: state.getIn(['liveSearch', 'list']),