From 942b2f707fecf555907173386df4304a0da6f2c7 Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Wed, 13 Mar 2024 14:14:17 -0400 Subject: [PATCH 1/2] Add toast handling for purge cache action (#1824) --- .../apps/configuration/panels/get-started.tsx | 21 +++++++- .../panels/tenant-list/configure_tab1.tsx | 32 +----------- .../__snapshots__/get-started.test.tsx.snap | 14 +++++ .../panels/test/get-started.test.tsx | 51 +++++++++++++++++++ 4 files changed, 86 insertions(+), 32 deletions(-) diff --git a/public/apps/configuration/panels/get-started.tsx b/public/apps/configuration/panels/get-started.tsx index dcf4fed41..806d8d2f4 100644 --- a/public/apps/configuration/panels/get-started.tsx +++ b/public/apps/configuration/panels/get-started.tsx @@ -24,6 +24,7 @@ import { EuiSteps, EuiText, EuiTitle, + EuiGlobalToastList, } from '@elastic/eui'; import React from 'react'; import { FormattedMessage } from '@osd/i18n/react'; @@ -33,6 +34,8 @@ import { Action } from '../types'; import { ResourceType } from '../../../../common'; import { API_ENDPOINT_CACHE, DocLinks } from '../constants'; import { ExternalLink, ExternalLinkButton } from '../utils/display-utils'; +import { httpDelete } from '../utils/request-utils'; +import { createSuccessToast, createUnknownErrorToast, useToastState } from '../utils/toast-utils'; const addBackendStep = { title: 'Add backends', @@ -162,6 +165,7 @@ export function GetStarted(props: AppDependencies) { } else { steps = setOfSteps; } + const [toasts, addToast, removeToast] = useToastState(); return ( <> @@ -229,8 +233,20 @@ export function GetStarted(props: AppDependencies) { { - props.coreStart.http.delete(API_ENDPOINT_CACHE); + data-test-subj="purge-cache" + onClick={async () => { + try { + await httpDelete(props.coreStart.http, API_ENDPOINT_CACHE); + addToast( + createSuccessToast( + 'cache-flush-success', + 'Cache purge successful', + 'Cache purge successful' + ) + ); + } catch (err) { + addToast(createUnknownErrorToast('cache-flush-failed', 'purge cache')); + } }} > Purge cache @@ -274,6 +290,7 @@ export function GetStarted(props: AppDependencies) { + ); } diff --git a/public/apps/configuration/panels/tenant-list/configure_tab1.tsx b/public/apps/configuration/panels/tenant-list/configure_tab1.tsx index 820a4443d..dd8686664 100644 --- a/public/apps/configuration/panels/tenant-list/configure_tab1.tsx +++ b/public/apps/configuration/panels/tenant-list/configure_tab1.tsx @@ -14,14 +14,9 @@ */ import { - EuiBadge, EuiButton, - EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, - EuiInMemoryTable, - EuiLink, - EuiPageBody, EuiPageContent, EuiPageContentHeader, EuiPageContentHeaderSection, @@ -29,51 +24,28 @@ import { EuiText, EuiTitle, EuiGlobalToastList, - EuiSwitch, - Query, EuiHorizontalRule, - EuiFormRow, EuiDescribedFormGroup, EuiSpacer, EuiCheckbox, - EuiModal, - EuiModalHeader, - EuiModalHeaderTitle, - EuiModalBody, - EuiModalFooter, - EuiCodeBlock, EuiCallOut, EuiBottomBar, EuiComboBox, EuiIcon, - EuiPanel, } from '@elastic/eui'; -import { ChangeEvent } from 'react'; -import React, { ReactNode, useState, useCallback } from 'react'; +import React, { ReactNode, useState } from 'react'; import { SaveChangesModalGenerator } from './save_changes_modal'; import { AppDependencies } from '../../../types'; -import { displayBoolean } from '../../utils/display-utils'; -import { updateAuditLogging } from '../../utils/audit-logging-utils'; -import { AuditLoggingSettings } from '../audit-logging/types'; -import { AuthInfo } from '../../../../types'; -import { updateTenancyConfig } from '../../utils/tenancy-config_util'; import { TenancyConfigSettings } from '../tenancy-config/types'; -import { getAuthInfo } from '../../../../utils/auth-info-utils'; import { fetchTenants, transformTenantData, updateTenancyConfiguration, - updateTenant, } from '../../utils/tenant-utils'; -import { Action, Tenant } from '../../types'; -import { showTableStatusMessage } from '../../utils/loading-spinner-utils'; -import { useContextMenuState } from '../../utils/context-menu'; -import { TenantEditModal } from './edit-modal'; +import { Tenant } from '../../types'; import { createTenancyErrorToast, createTenancySuccessToast, - createUnknownErrorToast, - getSuccessToastMessage, useToastState, } from '../../utils/toast-utils'; import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils'; diff --git a/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap b/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap index d7fd749e2..82c3ec0b8 100644 --- a/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap +++ b/public/apps/configuration/panels/test/__snapshots__/get-started.test.tsx.snap @@ -189,6 +189,7 @@ exports[`Get started (landing page) renders when backend configuration is disabl By default, the security plugin caches authenticated users, along with their roles and permissions. This option will purge cached users, roles and permissions.

+ `; @@ -502,6 +509,7 @@ exports[`Get started (landing page) renders when backend configuration is enable By default, the security plugin caches authenticated users, along with their roles and permissions. This option will purge cached users, roles and permissions.

+ `; diff --git a/public/apps/configuration/panels/test/get-started.test.tsx b/public/apps/configuration/panels/test/get-started.test.tsx index e51af78f0..fdd09500a 100644 --- a/public/apps/configuration/panels/test/get-started.test.tsx +++ b/public/apps/configuration/panels/test/get-started.test.tsx @@ -20,6 +20,18 @@ import { Action } from '../../types'; import { ResourceType } from '../../../../../common'; import { buildHashUrl } from '../../utils/url-builder'; import { GetStarted } from '../get-started'; +import * as ToastUtils from '../../utils/toast-utils'; // Import all functions from toast-utils +import * as RequestUtils from '../../utils/request-utils'; // Import all functions from request-utils + +jest.mock('../../utils/toast-utils', () => ({ + createSuccessToast: jest.fn(), + createUnknownErrorToast: jest.fn(), + useToastState: jest.fn().mockReturnValue([[], jest.fn(), jest.fn()]), +})); + +jest.mock('../../utils/request-utils', () => ({ + httpDelete: jest.fn(), +})); describe('Get started (landing page)', () => { const mockCoreStart = { @@ -71,6 +83,7 @@ describe('Get started (landing page)', () => { config={config as any} /> ); + jest.clearAllMocks(); }); it('Review authentication and authorization button click', () => { @@ -120,4 +133,42 @@ describe('Get started (landing page)', () => { expect(window.location.hash).toBe(buildHashUrl(ResourceType.auditLogging)); }); }); + + describe('Tests purge cache button', () => { + let wrapper; + beforeEach(() => { + wrapper = shallow( + + ); + jest.clearAllMocks(); + }); + + it('Purge cache button fails', async () => { + const button = wrapper.find('[data-test-subj="purge-cache"]'); + expect(button).toHaveLength(1); + + // Failure case: Mock httpDelete to reject + jest + .spyOn(RequestUtils, 'httpDelete') + .mockRejectedValueOnce(new Error('Failed to purge cache')); + + await button.props().onClick(); // Simulate button click + expect(ToastUtils.createUnknownErrorToast).toHaveBeenCalledTimes(1); + }); + + it('Purge cache button works', async () => { + const button = wrapper.find('[data-test-subj="purge-cache"]'); + expect(button).toHaveLength(1); + + // Success case: Mock httpDelete to resolve + jest.spyOn(RequestUtils, 'httpDelete').mockResolvedValueOnce('nice'); + await button.props().onClick(); // Simulate button click + expect(ToastUtils.createSuccessToast).toHaveBeenCalledTimes(1); + }); + }); }); From 7c8058f376d235d651f76552d9bdd12840ebd329 Mon Sep 17 00:00:00 2001 From: Stephen Crawford <65832608+scrawfor99@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:49:48 -0400 Subject: [PATCH 2/2] 2.13 release notes (#1832) * 2.13 release notes Signed-off-by: Stephen Crawford * Fix style and package Signed-off-by: Stephen Crawford * Fix style and package Signed-off-by: Stephen Crawford * Fix link Signed-off-by: Stephen Crawford --------- Signed-off-by: Stephen Crawford --- ...urity-dashboards-plugin.release-notes-2.13.0.0.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 release-notes/opensearch-security-dashboards-plugin.release-notes-2.13.0.0.md diff --git a/release-notes/opensearch-security-dashboards-plugin.release-notes-2.13.0.0.md b/release-notes/opensearch-security-dashboards-plugin.release-notes-2.13.0.0.md new file mode 100644 index 000000000..6faa11f1d --- /dev/null +++ b/release-notes/opensearch-security-dashboards-plugin.release-notes-2.13.0.0.md @@ -0,0 +1,12 @@ +## 2024-03-19 Version 2.13.0.0 + +Compatible with OpenSearch-Dashboards 2.13.0 + +### Enhancements +* Clear the contents of opensearch_dashboards prior to putting settings ([#1781](https://github.com/opensearch-project/security-dashboards-plugin/pull/1781)) +* Add loose flag to OSD bootstrap ([#1789](https://github.com/opensearch-project/security-dashboards-plugin/pull/1789)) +* Hide tenant when disabled in the account nav button popover ([#1792](https://github.com/opensearch-project/security-dashboards-plugin/pull/1792)) +* Use start-opensearch and setup-opensearch-dashboards actions ([#1808](https://github.com/opensearch-project/security-dashboards-plugin/pull/1808)) +* Fix cookie expiry issues from IDP/JWT auth methods, disables keepalive for JWT/IDP ([#1806](https://github.com/opensearch-project/security-dashboards-plugin/pull/1806)) +* Copy tenant with Short URL ([#1812](https://github.com/opensearch-project/security-dashboards-plugin/pull/1812)) +* Add toast handling for purge cache action ([#1827](https://github.com/opensearch-project/security-dashboards-plugin/pull/1827))