Skip to content

Commit 9afdc12

Browse files
committed
check for permissions explicitly using can-i
Signed-off-by: Atif Ali <[email protected]>
1 parent 2c1bbfb commit 9afdc12

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

ui/src/app/applications/components/application-status-panel/application-status-panel.tsx

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ const getApplicationSetOwnerRef = (application: models.Application) => {
6262
return application.metadata.ownerReferences?.find(ref => ref.kind === 'ApplicationSet');
6363
};
6464

65-
const extractErrorText = (error: any): string => {
66-
const errorChildren = error.props?.children || [];
67-
return Array.isArray(errorChildren) ? errorChildren.map(child => (typeof child === 'string' ? child : '')).join('') : String(errorChildren);
68-
};
69-
70-
const isPermissionError = (error: any): boolean => {
71-
const errorText = extractErrorText(error);
72-
return errorText.includes('Failed to load data');
73-
};
74-
7565
const ProgressiveSyncStatus = ({application}: {application: models.Application}) => {
7666
const appSetRef = getApplicationSetOwnerRef(application);
7767
if (!appSetRef) {
@@ -81,12 +71,8 @@ const ProgressiveSyncStatus = ({application}: {application: models.Application})
8171
return (
8272
<DataLoader
8373
input={application}
84-
errorRenderer={(error: any) => {
85-
// If user doesn't have permission to read ApplicationSet, hide the panel
86-
if (isPermissionError(error)) {
87-
return null;
88-
}
89-
// For other errors, show a minimal error state
74+
errorRenderer={() => {
75+
// For any errors, show a minimal error state
9076
return (
9177
<div className='application-status-panel__item'>
9278
{sectionHeader({
@@ -101,6 +87,9 @@ const ProgressiveSyncStatus = ({application}: {application: models.Application})
10187
);
10288
}}
10389
load={async () => {
90+
// Check if user has permission to read ApplicationSets
91+
const canReadApplicationSets = await services.accounts.canI('applicationsets', 'get', application.spec.project + '/' + application.metadata.name);
92+
10493
// Find ApplicationSet by searching all namespaces dynamically
10594
const appSetList = await services.applications.listApplicationSets();
10695
const appSet = appSetList.items?.find(item => item.metadata.name === appSetRef.name);
@@ -109,16 +98,16 @@ const ProgressiveSyncStatus = ({application}: {application: models.Application})
10998
throw new Error(`ApplicationSet ${appSetRef.name} not found in any namespace`);
11099
}
111100

112-
// Only return the ApplicationSet if it has a strategy (Progressive Sync enabled)
113-
if (appSet?.spec?.strategy) {
114-
return appSet;
115-
}
116-
// Return a special value to indicate no strategy (Progressive Sync disabled)
117-
return 'NO_STRATEGY';
101+
return {canReadApplicationSets, appSet};
118102
}}>
119-
{(appSet: models.ApplicationSet | 'NO_STRATEGY') => {
120-
if (appSet === 'NO_STRATEGY') {
121-
// If the ApplicationSet has no strategy (Progressive Sync disabled), don't show Progressive Sync panel
103+
{({canReadApplicationSets, appSet}: {canReadApplicationSets: boolean; appSet: models.ApplicationSet}) => {
104+
// If user doesn't have permission to read ApplicationSets, don't show Progressive Sync panel
105+
if (!canReadApplicationSets) {
106+
return null;
107+
}
108+
109+
// If the ApplicationSet has no strategy (Progressive Sync disabled), don't show Progressive Sync panel
110+
if (!appSet?.spec?.strategy) {
122111
return null;
123112
}
124113

0 commit comments

Comments
 (0)