Skip to content

Commit 0239088

Browse files
Add permision check for tables & analytics (#2097)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Fixes OPS-3683, OPS-3875
1 parent 4e19460 commit 0239088

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

packages/react-ui/src/app/features/navigation/lib/menu-links-hook.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ export const useMenuLinks = () => {
5555
to: '/tables',
5656
label: t('Tables'),
5757
icon: TableProperties,
58+
locked: !checkAccess(Permission.WRITE_TABLE),
5859
},
5960
...(hasAnalyticsAccess
6061
? [
6162
{
6263
to: '/analytics',
6364
label: t('Analytics'),
6465
icon: LucideBarChart2,
66+
locked: !checkAccess(Permission.WRITE_ANALYTICS),
6567
},
6668
]
6769
: []),

packages/react-ui/src/app/routes/openops-analytics/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { Navigate } from 'react-router-dom';
2+
3+
import { useAuthorization } from '@/app/common/hooks/authorization-hooks';
14
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
25
import { useDefaultSidebarState } from '@/app/common/hooks/use-default-sidebar-state';
36
import { useCandu } from '@/app/features/extensions/candu/use-candu';
4-
import { FlagId } from '@openops/shared';
7+
import { FlagId, Permission } from '@openops/shared';
58

69
import {
710
AnalyticsDashboardEmptyState,
@@ -14,7 +17,7 @@ import { useEmbedDashboard } from './use-embed-dashboard';
1417

1518
const OpenOpsAnalyticsPage = () => {
1619
useDefaultSidebarState('minimized');
17-
20+
const { checkAccess } = useAuthorization();
1821
const { isCanduEnabled, canduClientToken, canduUserId } = useCandu();
1922
const { data: analyticsPublicUrl } = flagsHooks.useFlag<string | undefined>(
2023
FlagId.ANALYTICS_PUBLIC_URL,
@@ -36,6 +39,10 @@ const OpenOpsAnalyticsPage = () => {
3639
canduUserId,
3740
});
3841

42+
if (!checkAccess(Permission.WRITE_ANALYTICS)) {
43+
return <Navigate to="/" replace />;
44+
}
45+
3946
if (!analyticsPublicUrl) {
4047
console.error('OpenOps Analytics URL is not defined');
4148
return null;

packages/react-ui/src/app/routes/openops-tables/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { t } from 'i18next';
2-
import { useLocation } from 'react-router-dom';
2+
import { Navigate, useLocation } from 'react-router-dom';
33

4+
import { useAuthorization } from '@/app/common/hooks/authorization-hooks';
45
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
56
import { useDefaultSidebarState } from '@/app/common/hooks/use-default-sidebar-state';
67
import { useCandu } from '@/app/features/extensions/candu/use-candu';
7-
import { FlagId } from '@openops/shared';
8+
import { FlagId, Permission } from '@openops/shared';
89

910
const OpenOpsTablesPage = () => {
1011
useDefaultSidebarState('minimized');
12+
const { checkAccess } = useAuthorization();
1113
const { isCanduEnabled, canduClientToken, canduUserId } = useCandu();
1214
const parentData = encodeURIComponent(
1315
JSON.stringify({ isCanduEnabled, userId: canduUserId, canduClientToken }),
@@ -22,6 +24,10 @@ const OpenOpsTablesPage = () => {
2224
FlagId.OPENOPS_TABLES_PUBLIC_URL,
2325
);
2426

27+
if (!checkAccess(Permission.WRITE_TABLE)) {
28+
return <Navigate to="/" replace />;
29+
}
30+
2531
if (!openopsTablesUrl) {
2632
console.error('OpenOps Tables URL is not defined');
2733
return null;

0 commit comments

Comments
 (0)