From ce2f20cc323d32a4afbfaf39dcae27a63d124420 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 15 Aug 2022 14:45:48 +0530 Subject: [PATCH] feat(admin-ui): change in client --- admin-ui/app/locales/en/translation.json | 4 +- .../components/Clients/ClientAdvancedPanel.js | 48 ++++++++++++++----- .../components/Clients/ClientBasicPanel.js | 7 +++ .../components/Clients/ClientEditPage.js | 6 ++- .../Clients/ClientShowSpontaneousScopes.js | 42 ++++++++++++++++ .../components/Scopes/ScopeForm.js | 2 +- .../auth-server/redux/actions/ScopeActions.js | 12 +++++ .../auth-server/redux/actions/types.js | 2 + .../plugins/auth-server/redux/api/ScopeApi.js | 7 +++ .../redux/reducers/ScopeReducer.js | 7 +++ .../auth-server/redux/sagas/OAuthScopeSaga.js | 26 ++++++++-- 11 files changed, 144 insertions(+), 19 deletions(-) create mode 100644 admin-ui/plugins/auth-server/components/Clients/ClientShowSpontaneousScopes.js diff --git a/admin-ui/app/locales/en/translation.json b/admin-ui/app/locales/en/translation.json index 4b288295b..5933f4963 100644 --- a/admin-ui/app/locales/en/translation.json +++ b/admin-ui/app/locales/en/translation.json @@ -104,6 +104,7 @@ "id_token_encrypted_response_enc": "JWS enc for encryption", "id_token_signed_response_alg": "JWS alg for signing", "spontaneousScopes": "Spontaneous scopes", + "spontaneousScopesREGEX": "Spontaneous scope validation regex", "inactive": "InActive", "include_in_scim_extension": "Include In SCIM Extension?", "in_memory_configuration": "inMemoryConfiguration", @@ -352,7 +353,8 @@ "view_client_details": "View client details", "add_new_user": "Add User", "error_in_saving": "Error in saving.", - "no_scope_in_client": "No Scope data for this Client" + "no_scope_in_client": "No Scope data for this Client", + "no_scope_in_spontaneous_client": "No Spontaneous Scope data for this Client" }, "tooltips": { "add_attribute": "Add attribute", diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientAdvancedPanel.js b/admin-ui/plugins/auth-server/components/Clients/ClientAdvancedPanel.js index 3926cc661..238910373 100644 --- a/admin-ui/plugins/auth-server/components/Clients/ClientAdvancedPanel.js +++ b/admin-ui/plugins/auth-server/components/Clients/ClientAdvancedPanel.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useEffect, useState } from 'react' import { Col, Container, FormGroup, InputGroup, CustomInput } from 'Components' import GluuBooleanSelectBox from 'Routes/Apps/Gluu/GluuBooleanSelectBox' import GluuLabel from 'Routes/Apps/Gluu/GluuLabel' @@ -8,6 +8,8 @@ import GluuInputRow from 'Routes/Apps/Gluu/GluuInputRow' import GluuTypeAheadWithAdd from 'Routes/Apps/Gluu/GluuTypeAheadWithAdd' import { useTranslation } from 'react-i18next' import DatePicker from 'react-datepicker' +import ClientShowSpontaneousScopes from './ClientShowSpontaneousScopes' +import { useSelector } from 'react-redux' const DOC_CATEGORY = 'openid_client' function ClientAdvancedPanel({ client, scripts, formik, scopes }) { @@ -18,6 +20,26 @@ function ClientAdvancedPanel({ client, scripts, formik, scopes }) { const [expirable, setExpirable] = useState( client.expirationDate ? client.expirationDate : false, ) + const [scopesModal, setScopesModal] = useState(false) + const reduxScopes = useSelector((state) => state.scopeReducer.items) + const getPrintableScopes = () => { + let newScopes = [] + for (let i in reduxScopes) { + if (reduxScopes[i].attributes.spontaneousClientScopes) { + let obj = { + id: reduxScopes[i].dn, + name: reduxScopes[i].attributes.spontaneousClientScopes[0], + } + newScopes.push(obj) + } + } + return newScopes + } + + const handler = () => { + setScopesModal(!scopesModal) + } + function handleExpirable() { setExpirable(!expirable) } @@ -57,6 +79,7 @@ function ClientAdvancedPanel({ client, scripts, formik, scopes }) { } return ( + @@ -75,13 +98,7 @@ function ClientAdvancedPanel({ client, scripts, formik, scopes }) { - + - + {client.inum && ( + + + + View Current + + + )} { + { + dispatch(getScopeByCreator({ inum: clientData.inum })) buildPayload(userAction, '', options) if (scopes.length < 1) { dispatch(getScopes(options)) diff --git a/admin-ui/plugins/auth-server/components/Clients/ClientShowSpontaneousScopes.js b/admin-ui/plugins/auth-server/components/Clients/ClientShowSpontaneousScopes.js new file mode 100644 index 000000000..87dc2ebef --- /dev/null +++ b/admin-ui/plugins/auth-server/components/Clients/ClientShowSpontaneousScopes.js @@ -0,0 +1,42 @@ +import React, { useContext } from 'react' +import { useTranslation } from 'react-i18next' +import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap' +import { Badge } from 'Components' +import { useSelector } from 'react-redux' +import { ThemeContext } from 'Context/theme/themeContext' + +function ClientShowSpontaneousScopes({ handler, isOpen }) { + const { t } = useTranslation() + const scopesByCreator = useSelector( + (state) => state.scopeReducer.scopesByCreator, + ) + const theme = useContext(ThemeContext) + const selectedTheme = theme.state.theme + + return ( + + {t('fields.spontaneousScopes')} + + {scopesByCreator.length > 0 ? ( + scopesByCreator?.map((scope, key) => { + return ( +
+ + {scope?.attributes?.spontaneousClientScopes[0]} + +
+ ) + }) + ) : ( +
{t('messages.no_scope_in_spontaneous_client')}
+ )} +
+ + + +
+ ) +} +export default ClientShowSpontaneousScopes diff --git a/admin-ui/plugins/auth-server/components/Scopes/ScopeForm.js b/admin-ui/plugins/auth-server/components/Scopes/ScopeForm.js index c68d08b12..73d187e6c 100644 --- a/admin-ui/plugins/auth-server/components/Scopes/ScopeForm.js +++ b/admin-ui/plugins/auth-server/components/Scopes/ScopeForm.js @@ -407,7 +407,7 @@ function ScopeForm({ scope, scripts, attributes, handleSubmit }) { defaultValue={ ['CLIENT', 'USER'].includes(scope.creatorType) ? scope.creatorType + - '(' + + ' (' + scope.creatorId + ')' || '' : scope.creatorType diff --git a/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js b/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js index 651e99d4e..cef856176 100644 --- a/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js +++ b/admin-ui/plugins/auth-server/redux/actions/ScopeActions.js @@ -13,6 +13,8 @@ import { GET_SCOPE_BY_PATTERN, GET_SCOPE_BY_PATTERN_RESPONSE, SEARCH_SCOPES, + GET_SCOPE_BY_CREATOR, + GET_SCOPE_BY_CREATOR_RESPONSE, } from './types' export const getScopes = (action) => ({ @@ -84,3 +86,13 @@ 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/types.js b/admin-ui/plugins/auth-server/redux/actions/types.js index 4d7a29539..9c8e7a1e1 100644 --- a/admin-ui/plugins/auth-server/redux/actions/types.js +++ b/admin-ui/plugins/auth-server/redux/actions/types.js @@ -24,6 +24,8 @@ export const DELETE_SCOPE_RESPONSE = 'DELETE_SCOPE_RESPONSE' export const SET_SCOPE_ITEM = 'SET_SCOPE_ITEM' export const GET_SCOPE_BY_PATTERN = 'GET_SCOPE_BY_PATTERN' export const GET_SCOPE_BY_PATTERN_RESPONSE = 'GET_SCOPE_BY_PATTERN_RESPONSE' +export const GET_SCOPE_BY_CREATOR = 'GET_SCOPE_BY_CREATOR' +export const GET_SCOPE_BY_CREATOR_RESPONSE = 'GET_SCOPE_BY_CREATOR_RESPONSE' // Clients export const GET_OPENID_CLIENTS = 'GET_OPENID_CLIENTS' diff --git a/admin-ui/plugins/auth-server/redux/api/ScopeApi.js b/admin-ui/plugins/auth-server/redux/api/ScopeApi.js index 82f6b02d7..9b7034d0e 100644 --- a/admin-ui/plugins/auth-server/redux/api/ScopeApi.js +++ b/admin-ui/plugins/auth-server/redux/api/ScopeApi.js @@ -19,6 +19,13 @@ export default class ScopeApi { }) }) } + getScopeByCreator = async (inum) => { + return new Promise((resolve, reject) => { + this.api.getScopeByCreator(inum, (error, data) => { + this.handleResponse(error, reject, resolve, data) + }) + }) + } getScope = async (id) => { return new Promise((resolve, reject) => { diff --git a/admin-ui/plugins/auth-server/redux/reducers/ScopeReducer.js b/admin-ui/plugins/auth-server/redux/reducers/ScopeReducer.js index f77b58c56..2850a51b1 100644 --- a/admin-ui/plugins/auth-server/redux/reducers/ScopeReducer.js +++ b/admin-ui/plugins/auth-server/redux/reducers/ScopeReducer.js @@ -14,6 +14,7 @@ import { GET_SCOPE_BY_PATTERN, GET_SCOPE_BY_PATTERN_RESPONSE, SEARCH_SCOPES, + GET_SCOPE_BY_CREATOR_RESPONSE, } from '../actions/types' import reducerRegistry from 'Redux/reducers/ReducerRegistry' const INIT_STATE = { @@ -22,6 +23,7 @@ const INIT_STATE = { loading: false, saveOperationFlag: false, errorInSaveOperationFlag: false, + scopesByCreator: [], } const reducerName = 'scopeReducer' @@ -120,6 +122,11 @@ export default function scopeReducer(state = INIT_STATE, action) { return handleDefault() } + case GET_SCOPE_BY_CREATOR_RESPONSE: + return { + ...state, + scopesByCreator: action.payload.data, + } case SET_ITEM: return { ...state, diff --git a/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js b/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js index a59074c50..b28d28469 100644 --- a/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js +++ b/admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js @@ -14,6 +14,7 @@ import { addScopeResponse, editScopeResponse, deleteScopeResponse, + getScopeByCreatorResponse, } from '../actions/ScopeActions' import { GET_SCOPES, @@ -23,6 +24,7 @@ import { EDIT_SCOPE, DELETE_SCOPE, GET_SCOPE_BY_PATTERN, + GET_SCOPE_BY_CREATOR, } from '../actions/types' import { SCOPE } from '../audit/Resources' import { @@ -33,10 +35,7 @@ import { } from '../../../../app/audit/UserActionType' import ScopeApi from '../api/ScopeApi' import { getClient } from 'Redux/api/base' -import { - isFourZeroOneError, - addAdditionalData, -} from 'Utils/TokenController' +import { isFourZeroOneError, addAdditionalData } from 'Utils/TokenController' import { postUserAction } from 'Redux/api/backend-api' const JansConfigApi = require('jans_config_api') @@ -67,6 +66,21 @@ export function* getScopeByInum() { } } } +export function* getScopeByCreator({ payload }) { + 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) + } catch (e) { + if (isFourZeroOneError(e)) { + const jwt = yield select((state) => state.authReducer.userinfo_jwt) + yield put(getAPIAccessToken(jwt)) + } + } +} export function* getScopes({ payload }) { const audit = yield* initAudit() @@ -155,6 +169,9 @@ export function* deleteAnScope({ payload }) { export function* watchGetScopeByInum() { yield takeEvery(GET_SCOPE_BY_INUM, getScopeByInum) } +export function* watchGetScopeByCreator() { + yield takeEvery(GET_SCOPE_BY_CREATOR, getScopeByCreator) +} export function* watchGetScopes() { yield takeLatest(GET_SCOPES, getScopes) } @@ -183,5 +200,6 @@ export default function* rootSaga() { fork(watchAddScope), fork(watchEditScope), fork(watchDeleteScope), + fork(watchGetScopeByCreator), ]) }