Skip to content

Commit

Permalink
ISPN-15125 Display correctly metrics when no entries and admin
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Oct 10, 2023
1 parent 4ccfd14 commit e2192eb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 43 deletions.
23 changes: 23 additions & 0 deletions cypress/e2e/rbac_func.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('RBAC Functionlity Tests', () => {
checkSecuredCacheDetailsView(true, false, false, 'monitor', 'indexed-cache');
checkNotOwnSecuredCache('super-cache');
checkNonSecuredCacheDetailView(true, false);
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with observer user', () => {
Expand All @@ -31,6 +32,7 @@ describe('RBAC Functionlity Tests', () => {
//Go to tasks (@TODO at the moment for observer no tasks are shown, add after fix)
checkSchemasPageView(false);
checkCountersPageView();
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with application user', () => {
Expand All @@ -45,6 +47,7 @@ describe('RBAC Functionlity Tests', () => {
//Go to tasks (@TODO at the moment for observer no tasks are shown, add after fix)
checkSchemasPageView(false);
checkCountersPageView();
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with deployer user', () => {
Expand All @@ -59,6 +62,7 @@ describe('RBAC Functionlity Tests', () => {
//Go to tasks (@TODO at the moment for observer no tasks are shown, add after fix)
checkSchemasPageView(true);
checkCountersPageView();
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with admin user', () => {
Expand All @@ -74,6 +78,7 @@ describe('RBAC Functionlity Tests', () => {
checkSchemasPageView(true);
checkCountersPageView();
checkTasksPage();
checkNoEntriesTabView(true);
});

function checkDataContainerView(isMonitor, isDeployer, isAdmin, isSuperAdmin) {
Expand Down Expand Up @@ -192,6 +197,24 @@ describe('RBAC Functionlity Tests', () => {
cy.contains(/cacheName$/).should('not.exist');
}

function checkNoEntriesTabView(isSuperAdmin) {
cy.get('[data-cy=detailButton-default]').click();
// nobody sees manage metrics tab for default cache
cy.get('[data-cy=manageEntriesTab]').should('not.exist');
cy.get('[data-cy=cacheMetricsTab]').should('exist');
if (isSuperAdmin) {
cy.get('[data-cy=cacheConfigurationTab]').should('exist');
// config tab is visible
cy.contains('JSON').should('exist');
} else {
// no config tab
cy.get('[data-cy=cacheConfigurationTab]').should('not.exist');
// metrics tab is visible
cy.contains('Data access').should('exist');
}

}

function checkNonSecuredCacheDetailView(isMonitor, isSuperAdmin) {
//Checking actions on non-secured cache
cy.get('[data-cy=detailButton-indexed-cache-no-auth]').click();
Expand Down
69 changes: 26 additions & 43 deletions src/app/Caches/DetailCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,28 @@ const DetailCache = (props: { cacheName: string }) => {
const encodingDocs = t('brandname.encoding-docs-link');
const { connectedUser } = useConnectedUser();
const { loading, error, cache, loadCache } = useCacheDetail();
const [activeTabKey1, setActiveTabKey1] = useState<number | string>(0);
const [activeTabKey1, setActiveTabKey1] = useState<number | string>('');
const [activeTabKey2, setActiveTabKey2] = useState<number | string>(10);
const [displayShowMore, setDisplayShowMore] = useState<boolean>(true);

useEffect(() => {
loadCache(cacheName);
}, []);

useEffect(() => {
if (activeTabKey1 != '' || !cache) {
return;
}

if (cache.editable && ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser)) {
setActiveTabKey1(0);
} else if (ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser)) {
setActiveTabKey1(1);
} else {
setActiveTabKey1(2);
}
}, [cache])

const encodingMessageDisplay = () => {
if (!ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser)) {
return '';
Expand Down Expand Up @@ -184,34 +198,19 @@ const DetailCache = (props: { cacheName: string }) => {
);
}

const displayEntries: boolean = cache.editable &&
ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser);

const displayConf: boolean = ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser);

if (
activeTabKey1 == 0 && displayEntries) {
if (activeTabKey1 == 0) {
return <React.Fragment>{buildEntriesTabContent(cache.queryable)}</React.Fragment>;
}

if (displayConf && (activeTabKey1 == 1 || (!displayEntries && activeTabKey1 == 0))) {
if (activeTabKey1 == 1) {
return (
cache.configuration && <CacheConfiguration cacheName={cache.name} editable={cache.editable} config={cache.configuration.config} />
);
}
let metricsKey = 2;
if (!displayConf) {
metricsKey --;
}
if (!displayEntries) {
metricsKey--;
}
if (activeTabKey1 == metricsKey) {
return (
<CacheMetrics cacheName={cacheName} display={activeTabKey1 == metricsKey} />
);
}
return '';

return (
<CacheMetrics cacheName={cacheName} display={activeTabKey1 == 2} />
);
};

const buildBackupsManage = () => {
Expand Down Expand Up @@ -404,33 +403,17 @@ const DetailCache = (props: { cacheName: string }) => {
return ;
}

let eventKey = 1;
if (!ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser) || !cache.editable) {
eventKey--;
}

return <Tab data-cy="cacheConfigurationTab" eventKey={eventKey} title={t('caches.tabs.configuration')} />;
return (
<Tab data-cy="cacheConfigurationTab" eventKey={1} title={t('caches.tabs.configuration')} />
);
};

const displayCacheStats = () => {
if (!cache.stats) {
return '';
}

let eventKey = 2;
if (!ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser) || !cache.editable) {
eventKey--;
}

if (!ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser)) {
eventKey--;
}

return (
<Tab
data-cy="cacheMetricsTab"
eventKey={eventKey}
title={cache.stats?.enabled ? t('caches.tabs.metrics-enabled') : t('caches.tabs.metrics-disabled')}
eventKey={2}
title={cache?.stats?.enabled ? t('caches.tabs.metrics-enabled') : t('caches.tabs.metrics-disabled')}
/>
);
};
Expand Down

0 comments on commit e2192eb

Please sign in to comment.