From d00d49f17d750e4d5ea1a16f8bccbc0d972ce29b Mon Sep 17 00:00:00 2001 From: Jeet Viramgama Date: Thu, 25 May 2023 23:26:40 +0530 Subject: [PATCH] fix(admin-ui): removed redux & action types --- admin-ui/app/redux/store/index.js | 3 +- .../Apps/Gluu/Tests/GluuAppSiderbar.test.js | 8 +- .../routes/License/LicenseDetailsPage.test.js | 11 +- admin-ui/package.json | 1 - .../CustomScripts/CustomScriptAddPage.test.js | 11 +- .../CustomScriptEditPage.test.js | 11 +- .../components/Roles/UiRoleListPage.test.js | 11 +- .../components/Clients/ClientAddPage.js | 4 +- .../components/Clients/ClientAddPage.test.js | 11 +- .../components/Clients/ClientBasicPanel.js | 9 +- .../Clients/ClientCibaParUmaPanel.js | 4 +- .../components/Clients/ClientEditPage.js | 6 +- .../components/Clients/ClientEditPage.test.js | 8 +- .../components/Clients/ClientListPage.js | 4 +- .../components/Clients/ClientListPage.test.js | 11 +- .../Configuration/ConfigPage.test.js | 8 +- .../Defaults/LoggingPage.test.js | 10 +- .../Configuration/Keys/Jwks/JwksPage.test.js | 9 +- .../Configuration/Keys/KeysPage.test.js | 8 +- .../components/Scopes/ScopeAddPage.js | 4 +- .../components/Scopes/ScopeAddPage.test.js | 11 +- .../components/Scopes/ScopeEditPage.js | 6 +- .../components/Scopes/ScopeEditPage.test.js | 10 +- .../components/Scopes/ScopeListPage.js | 20 +- .../components/Scopes/ScopeListPage.test.js | 9 +- .../components/Sessions/SessionListPage.js | 2 +- .../auth-server/redux/actions/ScopeActions.js | 110 -------- .../redux/actions/SessionActions.js | 32 --- .../auth-server/redux/features/scopeSlice.js | 53 +++- .../redux/features/sessionSlice.js | 14 +- .../auth-server/redux/sagas/OAuthScopeSaga.js | 244 +++++++++--------- .../auth-server/redux/sagas/SessionSaga.js | 8 +- .../Person/AttributeAddPage.test.js | 9 +- .../Person/AttributeEditPage.test.js | 11 +- .../Person/AttributeListPage.test.js | 11 +- 35 files changed, 306 insertions(+), 396 deletions(-) delete mode 100644 admin-ui/plugins/auth-server/redux/actions/ScopeActions.js delete mode 100644 admin-ui/plugins/auth-server/redux/actions/SessionActions.js diff --git a/admin-ui/app/redux/store/index.js b/admin-ui/app/redux/store/index.js index fcd9d6b79..a6ea4c78f 100644 --- a/admin-ui/app/redux/store/index.js +++ b/admin-ui/app/redux/store/index.js @@ -1,5 +1,4 @@ -import { combineReducers } from 'redux' -import { configureStore } from '@reduxjs/toolkit' +import { configureStore, combineReducers } from '@reduxjs/toolkit' import createSagaMiddleware from 'redux-saga' import appReducers from '../reducers' import RootSaga from '../sagas' diff --git a/admin-ui/app/routes/Apps/Gluu/Tests/GluuAppSiderbar.test.js b/admin-ui/app/routes/Apps/Gluu/Tests/GluuAppSiderbar.test.js index d72b9a6c6..a7ccec3c0 100644 --- a/admin-ui/app/routes/Apps/Gluu/Tests/GluuAppSiderbar.test.js +++ b/admin-ui/app/routes/Apps/Gluu/Tests/GluuAppSiderbar.test.js @@ -1,12 +1,12 @@ import React from 'react' import { render } from '@testing-library/react' import GluuAppSidebar from '../GluuAppSidebar' -import { combineReducers, createStore } from 'redux' import { BrowserRouter as Router } from 'react-router-dom' import { Provider } from 'react-redux' import i18n from '../../../../i18n' import { I18nextProvider } from 'react-i18next' import Sidebar from 'Components/Sidebar' +import { configureStore, combineReducers } from '@reduxjs/toolkit' jest.spyOn(global.console, 'log').mockImplementation(jest.fn()) jest.spyOn(global.console, 'error').mockImplementation(jest.fn()) @@ -20,12 +20,12 @@ const INIT_STATE = { permissions: permissions, } -const store = createStore( - combineReducers({ +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const pageConfig = {} const Wrapper = ({ children }) => ( diff --git a/admin-ui/app/routes/License/LicenseDetailsPage.test.js b/admin-ui/app/routes/License/LicenseDetailsPage.test.js index 7c6d2d7e4..95d2bb47d 100644 --- a/admin-ui/app/routes/License/LicenseDetailsPage.test.js +++ b/admin-ui/app/routes/License/LicenseDetailsPage.test.js @@ -1,23 +1,24 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import LicenseDetailsPage from './LicenseDetailsPage' -import { createStore, combineReducers } from 'redux' +import LicenseDetailsPage from './LicenseDetailsPage' import { Provider } from 'react-redux' import i18n from '../../i18n' import { I18nextProvider } from 'react-i18next' import license from "./license" import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const INIT_LICENSE_DETAIL_STATE = { item: license, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ licenseDetailsReducer: (state = INIT_LICENSE_DETAIL_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/package.json b/admin-ui/package.json index be2a266d9..7d21437a1 100644 --- a/admin-ui/package.json +++ b/admin-ui/package.json @@ -154,7 +154,6 @@ "react-tooltip": "^5.10.5", "reactstrap": "^9.1.8", "recharts": "^2.5.0", - "redux": "^4.2.1", "redux-persist": "^6.0.0", "redux-saga": "^1.2.3", "sass": "^1.60.0", diff --git a/admin-ui/plugins/admin/components/CustomScripts/CustomScriptAddPage.test.js b/admin-ui/plugins/admin/components/CustomScripts/CustomScriptAddPage.test.js index e1f575bfd..c8a777034 100644 --- a/admin-ui/plugins/admin/components/CustomScripts/CustomScriptAddPage.test.js +++ b/admin-ui/plugins/admin/components/CustomScripts/CustomScriptAddPage.test.js @@ -1,12 +1,12 @@ import React from 'react' import { render, screen } from '@testing-library/react' import CustomScriptAddPage from './CustomScriptAddPage' -import { createStore, combineReducers } from 'redux' import { Provider } from 'react-redux' import i18n from '../../../../app/i18n' import { I18nextProvider } from 'react-i18next' import item from "./item" import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/attributes.readonly', @@ -21,14 +21,15 @@ const INIT_CUSTOM_SCRIPT_STATE = { item, ], loading: false, -} -const store = createStore( - combineReducers({ +} + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, customScriptReducer: (state = INIT_CUSTOM_SCRIPT_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/admin/components/CustomScripts/CustomScriptEditPage.test.js b/admin-ui/plugins/admin/components/CustomScripts/CustomScriptEditPage.test.js index b71b3f28a..6aedd73d5 100644 --- a/admin-ui/plugins/admin/components/CustomScripts/CustomScriptEditPage.test.js +++ b/admin-ui/plugins/admin/components/CustomScripts/CustomScriptEditPage.test.js @@ -1,11 +1,11 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import CustomScriptEditPage from './CustomScriptEditPage' -import { createStore, combineReducers } from 'redux' +import CustomScriptEditPage from './CustomScriptEditPage' import { Provider } from 'react-redux' import item from "./item" import script from "./script.test" import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/attributes.readonly', @@ -22,13 +22,14 @@ const INIT_CUSTOM_SCRIPT_STATE = { item: item, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, customScriptReducer: (state = INIT_CUSTOM_SCRIPT_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/admin/components/Roles/UiRoleListPage.test.js b/admin-ui/plugins/admin/components/Roles/UiRoleListPage.test.js index 66cc1762a..5829b2a0e 100644 --- a/admin-ui/plugins/admin/components/Roles/UiRoleListPage.test.js +++ b/admin-ui/plugins/admin/components/Roles/UiRoleListPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { render } from '@testing-library/react' -import UiRoleListPage from './UiRoleListPage' -import { createStore, combineReducers } from 'redux' +import UiRoleListPage from './UiRoleListPage' import { Provider } from 'react-redux' import roles from "./roles" import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/attributes.readonly', @@ -18,13 +18,14 @@ const INIT_API_ROLE_STATE = { items: roles, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, apiRoleReducer: (state = INIT_API_ROLE_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.js b/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.js index 3ef8e9d3f..f7e315a2d 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.js @@ -5,7 +5,7 @@ import GluuLoader from 'Routes/Apps/Gluu/GluuLoader' import { useNavigate } from 'react-router-dom' import { addNewClientAction } from 'Plugins/auth-server/redux/actions/OIDCActions' import { getOidcDiscovery } from 'Redux/actions/OidcDiscoveryActions' -import { getScopes } from 'Plugins/auth-server/redux/actions/ScopeActions' +import { getScopes } from 'Plugins/auth-server/redux/features/scopeSlice' import { getScripts } from 'Redux/actions/InitActions' import { buildPayload } from 'Utils/PermChecker' import GluuAlert from 'Routes/Apps/Gluu/GluuAlert' @@ -29,7 +29,7 @@ function ClientAddPage({ useEffect(() => { buildPayload(userAction, '', options) if (scopes.length < 1) { - dispatch(getScopes(userAction)) + dispatch(getScopes({ action: userAction })) } if (scripts.length < 1) { dispatch(getScripts(userAction)) diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.test.js b/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.test.js index da84b4690..54fca205d 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.test.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientAddPage.test.js @@ -1,8 +1,7 @@ import React from 'react' import { render, screen } from '@testing-library/react' import ClientAddPage from './ClientAddPage' -import { BrowserRouter as Router } from 'react-router-dom' -import { createStore, combineReducers } from 'redux' +import { BrowserRouter as Router } from 'react-router-dom' import { Provider } from 'react-redux' import i18n from '../../../../app/i18n' import { I18nextProvider } from 'react-i18next' @@ -11,6 +10,7 @@ import oidcDiscoveryReducer from 'Redux/reducers/OidcDiscoveryReducer' import { reducer as scopeReducer} from 'Plugins/auth-server/redux/features/scopeSlice' import umaResourceReducer from 'Plugins/auth-server/redux/reducers/UMAResourceReducer' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/openid/clients.readonly', 'https://jans.io/oauth/config/openid/clients.write', @@ -37,8 +37,9 @@ const INIT_SCPOPES_STATE = { item: {}, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, oidcReducer: (state = INIT_SCPOPES_STATE) => state, umaResourceReducer, @@ -47,7 +48,7 @@ const store = createStore( oidcDiscoveryReducer, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientBasicPanel.js b/admin-ui/plugins/auth-server/components/Clients/ClientBasicPanel.js index f46f55589..7bce8b079 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientBasicPanel.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientBasicPanel.js @@ -22,10 +22,9 @@ import { useTranslation } from 'react-i18next' import { getClientScopeByInum } from '../../../../app/utils/Util' import { useDispatch, useSelector } from 'react-redux' import { PER_PAGE_SCOPES } from '../../common/Constants' -import { getClientScopes } from '../../redux/actions/ScopeActions' import { isEmpty } from 'lodash' import _debounce from 'lodash/debounce' -import { getScopes } from 'Plugins/auth-server/redux/actions/ScopeActions' +import { getScopes, getClientScopes } from 'Plugins/auth-server/redux/features/scopeSlice' const DOC_CATEGORY = 'openid_client' const ClientBasicPanel = ({ @@ -94,7 +93,7 @@ const ClientBasicPanel = ({ } userAction["pattern"] = scopeInums.join(",") userAction["limit"] = PER_PAGE_SCOPES - dispatch(getClientScopes(userAction)) + dispatch(getClientScopes({ action: userAction })) } }, []) @@ -108,7 +107,7 @@ const ClientBasicPanel = ({ delete userScopeAction.startIndex } if (totalItems + PER_PAGE_SCOPES > userScopeAction.limit) { - dispatch(getScopes(userScopeAction)) + dispatch(getScopes({ action: userScopeAction })) } }; @@ -122,7 +121,7 @@ const ClientBasicPanel = ({ function handleDebounceFn(inputValue) { userScopeAction['pattern'] = inputValue delete userScopeAction.startIndex - dispatch(getScopes(userScopeAction)) + dispatch(getScopes({ action: userScopeAction })) } return ( diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientCibaParUmaPanel.js b/admin-ui/plugins/auth-server/components/Clients/ClientCibaParUmaPanel.js index 89c10bab5..b8ec7bf0f 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientCibaParUmaPanel.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientCibaParUmaPanel.js @@ -17,7 +17,7 @@ import { FormControlLabel, Radio, RadioGroup } from '@mui/material' import GluuTypeAheadForDn from 'Routes/Apps/Gluu/GluuTypeAheadForDn' import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' import { deleteUMAResource } from 'Plugins/auth-server/redux/actions/UMAResourceActions' -import { setCurrentItem } from 'Plugins/auth-server/redux/actions/ScopeActions' +import { setCurrentItem } from 'Plugins/auth-server/redux/features/scopeSlice' import { setCurrentItem as setCurrentItemClient, viewOnly, @@ -95,7 +95,7 @@ function ClientCibaParUmaPanel({ } const handleScopeEdit = (scope) => { - dispatch(setCurrentItem(scope)) + dispatch(setCurrentItem({ item: scope })) return navigate(`/auth-server/scope/edit:${scope.inum}`) } diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.js b/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.js index bf349072f..50aad493b 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.js @@ -4,7 +4,7 @@ import GluuLoader from 'Routes/Apps/Gluu/GluuLoader' import { useNavigate } from 'react-router-dom' import { connect } from 'react-redux' import { editClient } from 'Plugins/auth-server/redux/actions/OIDCActions' -import { getScopes, getScopeByCreator } from 'Plugins/auth-server/redux/actions/ScopeActions' +import { getScopes, getScopeByCreator } from 'Plugins/auth-server/redux/features/scopeSlice' import { getOidcDiscovery } from 'Redux/actions/OidcDiscoveryActions' import { getUMAResourcesByClient } from 'Plugins/auth-server/redux/actions/UMAResourceActions' import { getScripts } from 'Redux/actions/InitActions' @@ -33,10 +33,10 @@ function ClientEditPage({ const navigate =useNavigate() useEffect(() => { - dispatch(getScopeByCreator({ inum: clientData.inum })) + dispatch(getScopeByCreator({ action: { inum: clientData.inum } })) buildPayload(userAction, '', options) if (scopes.length < 1) { - dispatch(getScopes(options)) + dispatch(getScopes({ action: options })) } if (scripts.length < 1) { dispatch(getScripts(options)) diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.test.js b/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.test.js index 48fe30f73..7e133a2d4 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.test.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientEditPage.test.js @@ -1,7 +1,6 @@ import React from 'react' import { render, screen } from '@testing-library/react' import ClientEditPage from './ClientEditPage' -import { createStore, combineReducers } from 'redux' import { Provider } from 'react-redux' import clients from './clients.test' import initReducer from 'Redux/reducers/InitReducer' @@ -9,6 +8,7 @@ import oidcDiscoveryReducer from 'Redux/reducers/OidcDiscoveryReducer' import { reducer as scopeReducer} from 'Plugins/auth-server/redux/features/scopeSlice' import umaResourceReducer from 'Plugins/auth-server/redux/reducers/UMAResourceReducer' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/openid/clients.readonly', 'https://jans.io/oauth/config/openid/clients.write', @@ -25,8 +25,8 @@ const INIT_CLIENTS_STATE = { errorInSaveOperationFlag: false } -const store = createStore( - combineReducers({ +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, oidcReducer: (state = INIT_CLIENTS_STATE) => state, umaResourceReducer, @@ -35,7 +35,7 @@ const store = createStore( oidcDiscoveryReducer, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientListPage.js b/admin-ui/plugins/auth-server/components/Clients/ClientListPage.js index 259584049..6d60b6725 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientListPage.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientListPage.js @@ -5,7 +5,7 @@ import { useNavigate, useLocation } from 'react-router-dom' import { useSelector, useDispatch } from 'react-redux' import { Paper, TablePagination } from '@mui/material' import { Card, CardBody, Badge } from 'Components' -import { getScopes } from 'Plugins/auth-server/redux/actions/ScopeActions' +import { getScopes } from 'Plugins/auth-server/redux/features/scopeSlice' import { resetUMAResources } from 'Plugins/auth-server/redux/actions/UMAResourceActions' import GluuDialog from 'Routes/Apps/Gluu/GluuDialog' import ClientDetailPage from '../Clients/ClientDetailPage' @@ -190,7 +190,7 @@ function ClientListPage() { buildPayload(userAction, '', options) userAction['limit'] = 100 - dispatch(getScopes(userAction)) + dispatch(getScopes({ action: userAction })) setTimeout(() => { setIsPageLoading(false) diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientListPage.test.js b/admin-ui/plugins/auth-server/components/Clients/ClientListPage.test.js index bd68769f6..c51333311 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientListPage.test.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientListPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { fireEvent, render, screen, waitFor } from '@testing-library/react' -import ClientListPage from './ClientListPage' -import { combineReducers, createStore} from 'redux' +import ClientListPage from './ClientListPage' import { Provider } from 'react-redux' import clients from './clients.test' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/openid/clients.readonly', @@ -40,14 +40,15 @@ const INIT_SCPOPES_STATE = { item: {}, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, oidcReducer: (state = INIT_CLIENTS_STATE) => state, scopeReducer: (state = INIT_SCPOPES_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Configuration/ConfigPage.test.js b/admin-ui/plugins/auth-server/components/Configuration/ConfigPage.test.js index ba76db10c..20dc5555b 100644 --- a/admin-ui/plugins/auth-server/components/Configuration/ConfigPage.test.js +++ b/admin-ui/plugins/auth-server/components/Configuration/ConfigPage.test.js @@ -1,11 +1,11 @@ import React from 'react' import { render, screen, waitFor } from '@testing-library/react' import ConfigPage from './ConfigPage' -import { combineReducers, createStore } from 'redux' import { Provider } from 'react-redux' import i18n from '../../../../app/i18n' import { I18nextProvider } from 'react-i18next' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const config = { issuer: 'https://admin-ui-test.gluu.org', @@ -155,15 +155,15 @@ const INIT_STATE = { backendIsUp: true, } -const store = createStore( - combineReducers({ +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, jsonConfigReducer: (state = CONFIG_STATE) => state, noReducer: (state = {}) => state, acrReducer: (state = ACER_STATE) => state, initReducer: (state = SCRIPTS_STATE) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Configuration/Defaults/LoggingPage.test.js b/admin-ui/plugins/auth-server/components/Configuration/Defaults/LoggingPage.test.js index a05fe32a1..85e36c2cb 100644 --- a/admin-ui/plugins/auth-server/components/Configuration/Defaults/LoggingPage.test.js +++ b/admin-ui/plugins/auth-server/components/Configuration/Defaults/LoggingPage.test.js @@ -1,9 +1,9 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import LoggingPage from './LoggingPage' -import { combineReducers, createStore } from 'redux' +import LoggingPage from './LoggingPage' import { Provider } from 'react-redux' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/logging.readonly', @@ -26,13 +26,13 @@ const LOGGING_STATE = { loading: false, } -const store = createStore( - combineReducers({ +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = AUTH_STATE) => state, loggingReducer: (state = LOGGING_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Configuration/Keys/Jwks/JwksPage.test.js b/admin-ui/plugins/auth-server/components/Configuration/Keys/Jwks/JwksPage.test.js index 670e8fe29..9e4223577 100644 --- a/admin-ui/plugins/auth-server/components/Configuration/Keys/Jwks/JwksPage.test.js +++ b/admin-ui/plugins/auth-server/components/Configuration/Keys/Jwks/JwksPage.test.js @@ -1,11 +1,11 @@ import React from 'react' import { render, screen } from '@testing-library/react' import JwksPage from './JwksPage' -import { combineReducers, createStore } from 'redux' import { Provider } from 'react-redux' import i18n from '../../../../../../app/i18n' import { I18nextProvider } from 'react-i18next' import moment from 'moment' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const jwks_config = { keys: [ { @@ -28,12 +28,13 @@ const INIT_STATE = { jwks: jwks_config, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ jwksReducer: (state = INIT_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Configuration/Keys/KeysPage.test.js b/admin-ui/plugins/auth-server/components/Configuration/Keys/KeysPage.test.js index f355cf80e..df72a5ab4 100644 --- a/admin-ui/plugins/auth-server/components/Configuration/Keys/KeysPage.test.js +++ b/admin-ui/plugins/auth-server/components/Configuration/Keys/KeysPage.test.js @@ -1,11 +1,11 @@ import React from 'react' import { render, screen } from '@testing-library/react' import KeysPage from './KeysPage' -import { combineReducers, createStore } from 'redux' import { Provider } from 'react-redux' import i18n from '../../../../../app/i18n' import { I18nextProvider } from 'react-i18next' import moment from 'moment' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const jwks_config = { keys: [ @@ -30,12 +30,12 @@ const INIT_STATE = { loading: false, } -const store = createStore( - combineReducers({ +const store = configureStore({ + reducer: combineReducers({ jwksReducer: (state = INIT_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.js index 32a07ad45..bab62a08d 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.js @@ -3,7 +3,7 @@ import { connect } from 'react-redux' import { useNavigate } from 'react-router-dom' import { CardBody, Card } from 'Components' import ScopeForm from './ScopeForm' -import { addScope } from 'Plugins/auth-server/redux/actions/ScopeActions' +import { addScope } from 'Plugins/auth-server/redux/features/scopeSlice' import { buildPayload } from 'Utils/PermChecker' import GluuLoader from 'Routes/Apps/Gluu/GluuLoader' import { getAttributes, getScripts } from 'Redux/actions/InitActions' @@ -46,7 +46,7 @@ function ScopeAddPage({ delete data.action_message postBody['scope'] = data buildPayload(userAction, message, postBody) - dispatch(addScope(userAction)) + dispatch(addScope({ action: userAction })) } } diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.test.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.test.js index fac443b9e..dbc5b298d 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.test.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import ScopeAddPage from './ScopeAddPage' -import { createStore, combineReducers } from 'redux' +import ScopeAddPage from './ScopeAddPage' import { Provider } from 'react-redux' import scopes from './scopes.test' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/openid/clients.readonly', @@ -24,14 +24,15 @@ const STATE = { scripts: [], attributes: [], } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, initReducer: (state = STATE) => state, scopeReducer: (state = SCPOPES_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.js index 765d3b992..b60845497 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.js @@ -3,8 +3,7 @@ import { connect } from 'react-redux' import { useNavigate } from 'react-router-dom' import { CardBody, Card } from 'Components' import GluuLoader from 'Routes/Apps/Gluu/GluuLoader' -import ScopeForm from './ScopeForm' -import { editScope } from 'Plugins/auth-server/redux/actions/ScopeActions' +import ScopeForm from './ScopeForm' import { buildPayload } from 'Utils/PermChecker' import { getAttributes, @@ -13,6 +12,7 @@ import { import GluuAlert from 'Routes/Apps/Gluu/GluuAlert' import { useTranslation } from 'react-i18next' import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' +import { editScope } from 'Plugins/auth-server/redux/features/scopeSlice' function ScopeEditPage({ scope, loading, dispatch, scripts, attributes, saveOperationFlag, errorInSaveOperationFlag }) { const userAction = {} @@ -49,7 +49,7 @@ function ScopeEditPage({ scope, loading, dispatch, scripts, attributes, saveOper delete data.action_message postBody['scope'] = data buildPayload(userAction, message, postBody) - dispatch(editScope(userAction)) + dispatch(editScope({ action: userAction })) } } return ( diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.test.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.test.js index 1dd975580..6cb5d322b 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.test.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import ScopeEditPage from './ScopeEditPage' -import { createStore, combineReducers } from 'redux' +import ScopeEditPage from './ScopeEditPage' import { Provider } from 'react-redux' import scopes from './scopes.test' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/scopes.readonly', @@ -25,14 +25,14 @@ const SCOPE_REDUCER = { loading: false } -const store = createStore( - combineReducers({ +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, initReducer: (state = INIT_SHARED_STATE) => state, noReducer: (state = {}) => state, scopeReducer: (state = SCOPE_REDUCER) => state }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.js index a020f19da..0a79e9ef2 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.js @@ -13,11 +13,7 @@ import GluuViewWrapper from 'Routes/Apps/Gluu/GluuViewWrapper' import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' import ScopeDetailPage from '../Scopes/ScopeDetailPage' import { useTranslation } from 'react-i18next' -import { - getScopes, - deleteScope, -} from 'Plugins/auth-server/redux/actions/ScopeActions' -import { setCurrentItem } from 'Plugins/auth-server/redux/features/scopeSlice' +import { setCurrentItem, getScopes, searchScopes, deleteScope } from 'Plugins/auth-server/redux/features/scopeSlice' import { hasPermission, buildPayload, @@ -100,7 +96,7 @@ function ScopeListPage() { useEffect(() => { makeOptions() - dispatch(getScopes(options)) + dispatch(getScopes({ action: options })) }, []) function handleOptionsChange(event) { @@ -129,19 +125,19 @@ function ScopeListPage() { return navigate('/auth-server/scope/new') } function handleGoToScopeEditPage(row) { - dispatch(setCurrentItem(row)) + dispatch(setCurrentItem({ item: row })) return navigate(`/auth-server/scope/edit/:` + row.inum) } function handleScopeDelete(row) { - dispatch(setCurrentItem(row)) + dispatch(setCurrentItem({ item: row })) setItem(row) toggle() } function onDeletionConfirmed(message) { buildPayload(userAction, message, item.inum) - dispatch(deleteScope(userAction)) + dispatch(deleteScope({ action: userAction })) navigate('/auth-server/scopes') toggle() } @@ -185,7 +181,7 @@ function ScopeListPage() { onClick: () => { makeOptions() // buildPayload(userAction, SEARCHING_SCOPES, options) - dispatch(getScopes(options)) + dispatch(searchScopes({ action: options })) }, }) } @@ -219,7 +215,7 @@ function ScopeListPage() { options['startIndex'] = parseInt(startCount) options['limit'] = limit setPageNumber(page) - dispatch(getScopes(options)) + dispatch(getScopes({ action: options })) } const onRowCountChangeClick = (count) => { makeOptions() @@ -227,7 +223,7 @@ function ScopeListPage() { options['limit'] = count setPageNumber(0) setLimit(count) - dispatch(getScopes(options)) + dispatch(getScopes({ action: options })) } return ( diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.test.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.test.js index c464732b4..8222558ab 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.test.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeListPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { render, screen } from '@testing-library/react' import ScopeListPage from './ScopeListPage' -import { createStore, combineReducers } from 'redux' import { Provider } from 'react-redux' import scopes from './scopes.test' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/scopes.readonly', @@ -20,13 +20,14 @@ const INIT_SCPOPES_STATE = { item: {}, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, scopeReducer: (state = INIT_SCPOPES_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js b/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js index 633600d8b..c8c5ec066 100644 --- a/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js +++ b/admin-ui/plugins/auth-server/components/Sessions/SessionListPage.js @@ -11,7 +11,7 @@ import GluuViewWrapper from 'Routes/Apps/Gluu/GluuViewWrapper' import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' import GluuDialog from 'Routes/Apps/Gluu/GluuDialog' import { useTranslation } from 'react-i18next' -import { getSessions, revokeSession } from 'Plugins/auth-server/redux/actions/SessionActions' +import { getSessions, revokeSession } from 'Plugins/auth-server/redux/features/sessionSlice' import SetTitle from 'Utils/SetTitle' import { ThemeContext } from 'Context/theme/themeContext' import getThemeColor from 'Context/theme/config' diff --git a/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js b/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js deleted file mode 100644 index a909d374a..000000000 --- a/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js +++ /dev/null @@ -1,110 +0,0 @@ -import { - GET_SCOPES, - GET_SCOPES_RESPONSE, - ADD_SCOPE, - ADD_SCOPE_RESPONSE, - EDIT_SCOPE, - EDIT_SCOPE_RESPONSE, - DELETE_SCOPE, - DELETE_SCOPE_RESPONSE, - GET_SCOPE_BY_INUM, - GET_SCOPE_BY_INUM_RESPONSE, - SET_ITEM, - GET_SCOPE_BY_PATTERN, - GET_SCOPE_BY_PATTERN_RESPONSE, - SEARCH_SCOPES, - GET_SCOPE_BY_CREATOR, - GET_SCOPE_BY_CREATOR_RESPONSE, - GET_CLIENT_SCOPES, - GET_CLIENT_SCOPES_RESPONSE, -} from './types' - -export const getScopes = (action) => ({ - type: GET_SCOPES, - payload: { action }, -}) - -export const getClientScopes = (action) => ({ - type: GET_CLIENT_SCOPES, - payload: { action }, -}) - -export const searchScopes = (action) => ({ - type: SEARCH_SCOPES, - payload: { action }, -}) - -export const getScopesResponse = (data) => ({ - type: GET_SCOPES_RESPONSE, - payload: { data }, -}) - -export const getClientScopesResponse = (data) => ({ - type: GET_CLIENT_SCOPES_RESPONSE, - payload: { data }, -}) - -export const getScope = (action) => ({ - type: GET_SCOPE_BY_INUM, - payload: { action }, -}) - -export const getScopeResponse = (data) => ({ - type: GET_SCOPE_BY_INUM_RESPONSE, - payload: { data }, -}) - -export const getScopeByPattern = (action) => ({ - type: GET_SCOPE_BY_PATTERN, - payload: { action }, -}) - -export const getScopeByPatternResponse = (data) => ({ - type: GET_SCOPE_BY_PATTERN_RESPONSE, - payload: { data }, -}) - -export const addScope = (action) => ({ - type: ADD_SCOPE, - payload: { action }, -}) - -export const addScopeResponse = (data) => ({ - type: ADD_SCOPE_RESPONSE, - payload: { data }, -}) - -export const editScope = (action) => ({ - type: EDIT_SCOPE, - payload: { action }, -}) - -export const editScopeResponse = (data) => ({ - type: EDIT_SCOPE_RESPONSE, - payload: { data }, -}) - -export const deleteScope = (action) => ({ - type: DELETE_SCOPE, - payload: { action }, -}) - -export const deleteScopeResponse = (data) => ({ - type: DELETE_SCOPE_RESPONSE, - payload: { data }, -}) - -export const setCurrentItem = (item) => ({ - type: SET_ITEM, - payload: { item }, -}) - -export const getScopeByCreator = (item) => ({ - type: GET_SCOPE_BY_CREATOR, - payload: { item }, -}) - -export const getScopeByCreatorResponse = (data) => ({ - type: GET_SCOPE_BY_CREATOR_RESPONSE, - payload: { data }, -}) diff --git a/admin-ui/plugins/auth-server/redux/actions/SessionActions.js b/admin-ui/plugins/auth-server/redux/actions/SessionActions.js deleted file mode 100644 index 2e499f1c1..000000000 --- a/admin-ui/plugins/auth-server/redux/actions/SessionActions.js +++ /dev/null @@ -1,32 +0,0 @@ -import { - GET_SESSIONS, - GET_SESSIONS_RESPONSE, - REVOKE_SESSION, - REVOKE_SESSION_RESPONSE, - RESET -} from './types' - -export const getSessions = () => ({ - type: GET_SESSIONS, - payload: { }, -}) - -export const getSessionsResponse = (data) => ({ - type: GET_SESSIONS_RESPONSE, - payload: { data }, -}) - -export const revokeSession = (action) => ({ - type: REVOKE_SESSION, - payload: { action }, -}) - -export const revokeSessionsResponse = (data) => ({ - type: REVOKE_SESSION_RESPONSE, - payload: { data }, -}) - -export const resetSessions = () => ({ - type: RESET, - payload: {}, -}) diff --git a/admin-ui/plugins/auth-server/redux/features/scopeSlice.js b/admin-ui/plugins/auth-server/redux/features/scopeSlice.js index 98cdb23c8..15b51a1ca 100644 --- a/admin-ui/plugins/auth-server/redux/features/scopeSlice.js +++ b/admin-ui/plugins/auth-server/redux/features/scopeSlice.js @@ -17,7 +17,12 @@ const scopeSlice = createSlice({ name: "scope", initialState, reducers: { - scopeHandleLoading: (state, action) => { + scopeHandleLoading: (state) => { + state.loading = true; + state.saveOperationFlag = false; + state.errorInSaveOperationFlag = false; + }, + getScopes: (state) => { state.loading = true; state.saveOperationFlag = false; state.errorInSaveOperationFlag = false; @@ -34,9 +39,14 @@ const scopeSlice = createSlice({ } }, setCurrentItem: (state, action) => { - state.item = action.payload; + state.item = action.payload.item; state.loading = false; }, + deleteScope: (state) => { + state.loading = true; + state.saveOperationFlag = false; + state.errorInSaveOperationFlag = false; + }, deleteScopeResponse: (state, action) => { state.loading = false; if (action.payload.data) { @@ -49,7 +59,7 @@ const scopeSlice = createSlice({ editScopeResponse: (state, action) => { state.loading = false; state.saveOperationFlag = true; - if (action.payload.data) { + if (action.payload?.data) { state.items = [...state.items]; state.errorInSaveOperationFlag = false; } else { @@ -79,6 +89,7 @@ const scopeSlice = createSlice({ state.scopesByCreator = action.payload.data; }, getClientScopesResponse: (state, action) => { + state.loading = false; if (action.payload.data) { state.clientScopes = action.payload.data.entries; state.loadingClientScopes = false; @@ -87,11 +98,34 @@ const scopeSlice = createSlice({ state.errorInSaveOperationFlag = false; } }, + searchScopes: (state, action) => { + state.loading = true; + state.saveOperationFlag = false; + state.errorInSaveOperationFlag = false; + }, + addScope: (state) => { + state.loading = true; + state.saveOperationFlag = false; + state.errorInSaveOperationFlag = false; + }, + editScope: (state) => { + state.loading = true; + state.saveOperationFlag = false; + state.errorInSaveOperationFlag = false; + }, + getScopeByCreator: () => {}, + getScopeByPattern: () => {}, + getScopeByInum: (state) => { + state.loading = true; + state.saveOperationFlag = false; + state.errorInSaveOperationFlag = false; + }, + getClientScopes: (state) => { + state.loadingClientScopes = true; + }, }, }); -reducerRegistry.register("scopeReducer", reducer); - export const { scopeHandleLoading, handleUpdateScopeResponse, @@ -102,5 +136,14 @@ export const { addScopeResponse, getScopeByCreatorResponse, getClientScopesResponse, + getScopes, + searchScopes, + deleteScope, + addScope, + editScope, + getScopeByCreator, + getScopeByInum, + getClientScopes, } = scopeSlice.actions; export const { actions, reducer, state } = scopeSlice; +reducerRegistry.register("scopeReducer", reducer); diff --git a/admin-ui/plugins/auth-server/redux/features/sessionSlice.js b/admin-ui/plugins/auth-server/redux/features/sessionSlice.js index 3c0e327dd..4cff61c98 100644 --- a/admin-ui/plugins/auth-server/redux/features/sessionSlice.js +++ b/admin-ui/plugins/auth-server/redux/features/sessionSlice.js @@ -13,7 +13,7 @@ const sessionSlice = createSlice({ reducers: { toggleLoader: (state, action) => { state.loading = action.payload; - }, + }, handleUpdateSessionsResponse: (state, action) => { state.loading = false; state.items = action.payload.data || []; @@ -23,15 +23,23 @@ const sessionSlice = createSlice({ state.items = state.items.filter( ({ userDn }) => userDn !== action.payload.data ); - } + }, + getSessions: (state) => { + state.loading = true; + }, + revokeSession: (state) => { + state.loading = true; + }, }, }); -reducerRegistry.register("SessionReducer", reducer); export const { handleUpdateSessionsResponse, toggleLoader, handleRevokeSession, + getSessions, + revokeSession, } = sessionSlice.actions; export const { actions, reducer, state } = sessionSlice; +reducerRegistry.register("SessionReducer", reducer); diff --git a/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js b/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js index 9e03807bc..5bc1c1367 100644 --- a/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js +++ b/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js @@ -6,217 +6,217 @@ import { takeEvery, takeLatest, select, -} from 'redux-saga/effects' -import { getAPIAccessToken } from '../actions/AuthActions' -import { updateToast } from 'Redux/actions/ToastAction' -import { - GET_SCOPES, - SEARCH_SCOPES, - GET_SCOPE_BY_INUM, - ADD_SCOPE, - EDIT_SCOPE, - DELETE_SCOPE, - GET_SCOPE_BY_PATTERN, - GET_SCOPE_BY_CREATOR, - GET_CLIENT_SCOPES, -} from '../actions/types' -import { SCOPE } from '../audit/Resources' +} from "redux-saga/effects"; +import { getAPIAccessToken } from "../actions/AuthActions"; +import { updateToast } from "Redux/actions/ToastAction"; +import { SCOPE } from "../audit/Resources"; import { CREATE, UPDATE, DELETION, FETCH, -} from '../../../../app/audit/UserActionType' -import ScopeApi from '../api/ScopeApi' -import { getClient } from 'Redux/api/base' -import { isFourZeroOneError, addAdditionalData } from 'Utils/TokenController' -import { postUserAction } from 'Redux/api/backend-api' +} from "../../../../app/audit/UserActionType"; +import ScopeApi from "../api/ScopeApi"; +import { getClient } from "Redux/api/base"; +import { isFourZeroOneError, addAdditionalData } from "Utils/TokenController"; +import { postUserAction } from "Redux/api/backend-api"; -const JansConfigApi = require('jans_config_api') -import { initAudit } from 'Redux/sagas/SagaUtils' -import { deleteScopeResponse, handleUpdateScopeResponse, - scopeHandleLoading, setCurrentItem, editScopeResponse, - addScopeResponse , getScopeByCreatorResponse, getClientScopesResponse } from '../features/scopeSlice' +const JansConfigApi = require("jans_config_api"); +import { initAudit } from "Redux/sagas/SagaUtils"; +import { + deleteScopeResponse, + handleUpdateScopeResponse, + scopeHandleLoading, + setCurrentItem, + editScopeResponse, + addScopeResponse, + getScopeByCreatorResponse, + getClientScopesResponse, +} from "../features/scopeSlice"; function* newFunction() { - const token = yield select((state) => state.authReducer.token.access_token) - const issuer = yield select((state) => state.authReducer.issuer) + const token = yield select((state) => state.authReducer.token.access_token); + const issuer = yield select((state) => state.authReducer.issuer); const api = new JansConfigApi.OAuthScopesApi( - getClient(JansConfigApi, token, issuer), - ) - return new ScopeApi(api) + getClient(JansConfigApi, token, issuer) + ); + return new ScopeApi(api); } export function* getScopeByInum({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - addAdditionalData(audit, FETCH, SCOPE, {}) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.getScope, payload.action) - yield put(setCurrentItem(data)) - yield call(postUserAction, audit) + addAdditionalData(audit, FETCH, SCOPE, {}); + const scopeApi = yield* newFunction(); + const data = yield call(scopeApi.getScope, payload.action); + yield put(setCurrentItem(data)); + yield call(postUserAction, audit); } catch (e) { - yield put(deleteScopeResponse(null)) + yield put(deleteScopeResponse(null)); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* getScopeByCreator({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - addAdditionalData(audit, FETCH, SCOPE, {}) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.getScopeByCreator, payload.item.inum) - yield put(getScopeByCreatorResponse(data)) - yield call(postUserAction, audit) + addAdditionalData(audit, FETCH, SCOPE, {}); + const scopeApi = yield* newFunction(); + const data = yield call(scopeApi.getScopeByCreator, payload.item.inum); + yield put(getScopeByCreatorResponse(data)); + yield call(postUserAction, audit); } catch (e) { if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* getScopes({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - yield put(scopeHandleLoading()) - addAdditionalData(audit, FETCH, SCOPE, payload) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.getAllScopes, payload.action) - yield put(handleUpdateScopeResponse({ data: data })) - yield call(postUserAction, audit) + yield put(scopeHandleLoading()); + addAdditionalData(audit, FETCH, SCOPE, payload); + const scopeApi = yield* newFunction(); + const data = yield call(scopeApi.getAllScopes, payload.action); + yield put(handleUpdateScopeResponse({ data: data })); + yield call(postUserAction, audit); } catch (e) { - yield put(handleUpdateScopeResponse({ data: null })) + yield put(handleUpdateScopeResponse({ data: null })); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* getClientScopes({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - addAdditionalData(audit, FETCH, SCOPE, payload) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.getAllScopes, payload.action) - yield put(getClientScopesResponse({ data })) - yield call(postUserAction, audit) + yield put(scopeHandleLoading()); + addAdditionalData(audit, FETCH, SCOPE, payload); + const scopeApi = yield* newFunction(); + const data = yield call(scopeApi.getAllScopes, payload.action); + yield put(getClientScopesResponse({ data })); + yield call(postUserAction, audit); } catch (e) { - yield put(getClientScopesResponse(null)) + yield put(getClientScopesResponse(null)); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* getScopeBasedOnOpts({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - addAdditionalData(audit, FETCH, SCOPE, payload) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.getScopeByOpts, payload.action.action_data) - yield put(getScopeByPatternResponse({ data })) - yield call(postUserAction, audit) + addAdditionalData(audit, FETCH, SCOPE, payload); + const scopeApi = yield* newFunction(); + const data = yield call( + scopeApi.getScopeByOpts, + payload.action.action_data + ); + yield put(getScopeByPatternResponse({ data })); + yield call(postUserAction, audit); } catch (e) { - yield put(getScopeByPatternResponse(null)) + yield put(getScopeByPatternResponse(null)); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* addAScope({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - yield put(scopeHandleLoading()) - addAdditionalData(audit, CREATE, SCOPE, payload) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.addNewScope, payload.action.action_data) - yield put(updateToast(true, 'success')) - yield put(addScopeResponse({ data })) - yield call(postUserAction, audit) + yield put(scopeHandleLoading()); + addAdditionalData(audit, CREATE, SCOPE, payload); + const scopeApi = yield* newFunction(); + const data = yield call(scopeApi.addNewScope, payload.action.action_data); + yield put(updateToast(true, "success")); + yield put(addScopeResponse({ data })); + yield call(postUserAction, audit); } catch (e) { - yield put(updateToast(true, 'error')) - yield put(addScopeResponse(null)) + yield put(updateToast(true, "error")); + yield put(addScopeResponse(null)); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* editAnScope({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - yield put(scopeHandleLoading()) - addAdditionalData(audit, UPDATE, SCOPE, payload) - const scopeApi = yield* newFunction() - const data = yield call(scopeApi.editAScope, payload.action.action_data) - yield put(updateToast(true, 'success')) - yield put(editScopeResponse({ data })) - yield call(postUserAction, audit) + yield put(scopeHandleLoading()); + addAdditionalData(audit, UPDATE, SCOPE, payload); + const scopeApi = yield* newFunction(); + const data = yield call(scopeApi.editAScope, payload.action.action_data); + yield put(updateToast(true, "success")); + yield put(editScopeResponse({ data })); + yield call(postUserAction, audit); } catch (e) { - yield put(updateToast(true, 'error')) - yield put(editScopeResponse(null)) + yield put(updateToast(true, "error")); + yield put(editScopeResponse(null)); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.authReducer.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.authReducer.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* deleteAnScope({ payload }) { - const audit = yield* initAudit() + const audit = yield* initAudit(); try { - yield put(scopeHandleLoading()) - addAdditionalData(audit, DELETION, SCOPE, payload) - const scopeApi = yield* newFunction() - yield call(scopeApi.deleteAScope, payload.action.action_data) - yield put(updateToast(true, 'success')) - yield put(deleteScopeResponse({ data: payload.action.action_data })) - yield call(postUserAction, audit) + yield put(scopeHandleLoading()); + addAdditionalData(audit, DELETION, SCOPE, payload); + const scopeApi = yield* newFunction(); + yield call(scopeApi.deleteAScope, payload.action.action_data); + yield put(updateToast(true, "success")); + yield put(deleteScopeResponse({ data: payload.action.action_data })); + yield call(postUserAction, audit); } catch (e) { - yield put(updateToast(true, 'error')) - yield put(deleteScopeResponse(null)) + yield put(updateToast(true, "error")); + yield put(deleteScopeResponse(null)); if (isFourZeroOneError(e)) { - const jwt = yield select((state) => state.s.userinfo_jwt) - yield put(getAPIAccessToken(jwt)) + const jwt = yield select((state) => state.s.userinfo_jwt); + yield put(getAPIAccessToken(jwt)); } } } export function* watchGetScopeByInum() { - yield takeEvery(GET_SCOPE_BY_INUM, getScopeByInum) + yield takeEvery("scope/getScopeByInum", getScopeByInum); } export function* watchGetScopeByCreator() { - yield takeEvery(GET_SCOPE_BY_CREATOR, getScopeByCreator) + yield takeEvery("scope/getScopeByCreator", getScopeByCreator); } export function* watchGetScopes() { - yield takeLatest(GET_SCOPES, getScopes) + yield takeLatest("scope/getScopes", getScopes); } export function* watchGetClientScopes() { - yield takeLatest(GET_CLIENT_SCOPES, getClientScopes) + yield takeLatest("scope/getClientScopes", getClientScopes); } export function* watchSearchScopes() { - yield takeLatest(SEARCH_SCOPES, getScopes) + yield takeLatest("scope/searchScopes", getScopes); } export function* watchGetScopeByOpts() { - yield takeLatest(GET_SCOPE_BY_PATTERN, getScopeBasedOnOpts) + yield takeLatest("scope/getScopeByPattern", getScopeBasedOnOpts); } export function* watchAddScope() { - yield takeLatest(ADD_SCOPE, addAScope) + yield takeLatest("scope/addScope", addAScope); } export function* watchEditScope() { - yield takeLatest(EDIT_SCOPE, editAnScope) + yield takeLatest("scope/editScope", editAnScope); } export function* watchDeleteScope() { - yield takeLatest(DELETE_SCOPE, deleteAnScope) + yield takeLatest("scope/deleteScope", deleteAnScope); } export default function* rootSaga() { @@ -229,6 +229,6 @@ export default function* rootSaga() { fork(watchEditScope), fork(watchDeleteScope), fork(watchGetScopeByCreator), - fork(watchGetClientScopes) - ]) + fork(watchGetClientScopes), + ]); } diff --git a/admin-ui/plugins/auth-server/redux/sagas/SessionSaga.js b/admin-ui/plugins/auth-server/redux/sagas/SessionSaga.js index 272f0b695..d3e93077a 100644 --- a/admin-ui/plugins/auth-server/redux/sagas/SessionSaga.js +++ b/admin-ui/plugins/auth-server/redux/sagas/SessionSaga.js @@ -7,7 +7,6 @@ import { postUserAction } from 'Redux/api/backend-api' import { getAPIAccessToken } from '../actions/AuthActions' import { SESSION } from '../audit/Resources' import { FETCH, DELETION } from '../../../../app/audit/UserActionType' -import { GET_SESSIONS, REVOKE_SESSION } from '../actions/types' import SessionApi from '../api/SessionApi' import { getClient } from 'Redux/api/base' const JansConfigApi = require('jans_config_api') @@ -32,7 +31,6 @@ function* newFunction() { export function* getSessions({ payload }) { const audit = yield* initAudit() try { - yield put(toggleLoader(true)) payload = payload ? payload : { action: {} } addAdditionalData(audit, FETCH, SESSION, payload) const sessionApi = yield* newFunction() @@ -47,8 +45,6 @@ export function* getSessions({ payload }) { const jwt = yield select((state) => state.authReducer.userinfo_jwt) yield put(getAPIAccessToken(jwt)) } - } finally { - yield put(toggleLoader(false)) } } @@ -73,11 +69,11 @@ export function* revokeSessionByUserDn({ payload }) { } export function* getSessionsWatcher() { - yield takeLatest(GET_SESSIONS, getSessions) + yield takeLatest('session/getSessions', getSessions) } export function* deleteSessionByUserDnWatcher() { - yield takeLatest(REVOKE_SESSION, revokeSessionByUserDn) + yield takeLatest('session/revokeSession', revokeSessionByUserDn) } export default function* rootSaga() { diff --git a/admin-ui/plugins/schema/components/Person/AttributeAddPage.test.js b/admin-ui/plugins/schema/components/Person/AttributeAddPage.test.js index 023c69590..b217d9686 100644 --- a/admin-ui/plugins/schema/components/Person/AttributeAddPage.test.js +++ b/admin-ui/plugins/schema/components/Person/AttributeAddPage.test.js @@ -1,9 +1,9 @@ import React from 'react' import { render, screen } from '@testing-library/react' import AttributeAddPage from './AttributeAddPage' -import { createStore, combineReducers } from 'redux' import { Provider } from 'react-redux' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/attributes.readonly', @@ -34,13 +34,14 @@ const INIT_ATTRIBUTE_STATE = { item: {}, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, attributeReducer: (state = INIT_ATTRIBUTE_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/schema/components/Person/AttributeEditPage.test.js b/admin-ui/plugins/schema/components/Person/AttributeEditPage.test.js index 96238a89d..3831378b5 100644 --- a/admin-ui/plugins/schema/components/Person/AttributeEditPage.test.js +++ b/admin-ui/plugins/schema/components/Person/AttributeEditPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import AttributeEditPage from './AttributeEditPage' -import { combineReducers, createStore } from 'redux' +import AttributeEditPage from './AttributeEditPage' import { Provider } from 'react-redux' import attributes from './attributes' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/attributes.readonly', 'https://jans.io/oauth/config/attributes.write', @@ -18,13 +18,14 @@ const INIT_ATTRIBUTE_STATE = { item: {}, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, attributeReducer: (state = INIT_ATTRIBUTE_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => ( diff --git a/admin-ui/plugins/schema/components/Person/AttributeListPage.test.js b/admin-ui/plugins/schema/components/Person/AttributeListPage.test.js index 704f16cef..f2562e580 100644 --- a/admin-ui/plugins/schema/components/Person/AttributeListPage.test.js +++ b/admin-ui/plugins/schema/components/Person/AttributeListPage.test.js @@ -1,10 +1,10 @@ import React from 'react' import { render, screen } from '@testing-library/react' -import AttributeListPage from './AttributeListPage' -import { combineReducers, createStore } from 'redux' +import AttributeListPage from './AttributeListPage' import { Provider } from 'react-redux' import attributes from './attributes' import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test' +import { combineReducers, configureStore } from '@reduxjs/toolkit' const permissions = [ 'https://jans.io/oauth/config/attributes.readonly', @@ -20,13 +20,14 @@ const INIT_ATTRIBUTE_STATE = { item: {}, loading: false, } -const store = createStore( - combineReducers({ + +const store = configureStore({ + reducer: combineReducers({ authReducer: (state = INIT_STATE) => state, attributeReducer: (state = INIT_ATTRIBUTE_STATE) => state, noReducer: (state = {}) => state, }), -) +}) const Wrapper = ({ children }) => (