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 3bb974b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 46 deletions.
29 changes: 29 additions & 0 deletions cypress/e2e/rbac_func.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('RBAC Functionlity Tests', () => {
checkSecuredCacheDetailsView(true, false, false, 'monitor', 'indexed-cache');
checkNotOwnSecuredCache('super-cache');
checkNonSecuredCacheDetailView(true, false);
cy.login(monitorUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with observer user', () => {
Expand All @@ -31,6 +33,8 @@ describe('RBAC Functionlity Tests', () => {
//Go to tasks (@TODO at the moment for observer no tasks are shown, add after fix)
checkSchemasPageView(false);
checkCountersPageView();
cy.login(observerUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with application user', () => {
Expand All @@ -45,6 +49,8 @@ describe('RBAC Functionlity Tests', () => {
//Go to tasks (@TODO at the moment for observer no tasks are shown, add after fix)
checkSchemasPageView(false);
checkCountersPageView();
cy.login(applicationUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with deployer user', () => {
Expand All @@ -59,6 +65,8 @@ describe('RBAC Functionlity Tests', () => {
//Go to tasks (@TODO at the moment for observer no tasks are shown, add after fix)
checkSchemasPageView(true);
checkCountersPageView();
cy.login(deployerUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
});

it('successfully logins and performs actions with admin user', () => {
Expand All @@ -74,6 +82,8 @@ describe('RBAC Functionlity Tests', () => {
checkSchemasPageView(true);
checkCountersPageView();
checkTasksPage();
cy.login(Cypress.env('username'), Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
});

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

function checkNoEntriesTabView(isSuperAdmin) {
// 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');
cy.get('[data-cy=cacheMetricsTab]').click();
cy.contains('Data access').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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "infinispan-console",
"version": "14.0.7",
"version": "14.0.13",
"description": "The console for Infinispan/Red Hat Data Grid",
"main": "index.js",
"repository": "https://github.com/infinispan/infinispan-console.git",
Expand Down
23 changes: 21 additions & 2 deletions src/app/CacheManagers/CacheTableDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Select,
SelectGroup,
SelectOption,
SelectVariant,
SelectVariant, Spinner,
Text,
TextContent,
TextVariants,
Expand Down Expand Up @@ -287,7 +287,26 @@ const CacheTableDisplay = (props: { cmName: string; setCachesCount: (count: numb
disableActions: boolean;
}[];

if (currentPageCaches.length == 0 || loadingCaches || errorCaches != '') {
if (loadingCaches) {
currentRows = [
{
heightAuto: true,
disableActions: true,
cells: [
{
props: { colSpan: 5 },
title: (
<Bullseye>
<EmptyState variant={EmptyStateVariant.small}>
<EmptyStateBody><Spinner size={"lg"}/></EmptyStateBody>
</EmptyState>
</Bullseye>
)
}
]
}
];
} else if (currentPageCaches.length == 0 || errorCaches != '') {
currentRows = [
{
heightAuto: true,
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 3bb974b

Please sign in to comment.