Skip to content

Commit 6c1db7b

Browse files
committed
feat(admin-ui): add delete dialog
1 parent 2837852 commit 6c1db7b

File tree

10 files changed

+124
-25
lines changed

10 files changed

+124
-25
lines changed

admin-ui/app/locales/en/translation.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"view": "View",
2323
"yes": "Yes",
2424
"change_password": "Change Password",
25-
"close": "Close"
25+
"close": "Close",
26+
"delete": "Delete"
2627
},
2728
"dashboard": {
2829
"summary_title": "Actives Users & Access Token Stats",

admin-ui/app/locales/fr/translation.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"test": "Test",
8181
"view": "Vue",
8282
"yes": "Oui",
83-
"close": "Fermer"
83+
"close": "Fermer",
84+
"delete": "Supprimez"
8485
},
8586
"fields": {
8687
"access_token_signing_alg": "Algorithme de signature de jeton d'accès",

admin-ui/app/locales/pt/translation.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"test": "Teste",
8080
"view": "Visualizar",
8181
"yes": "Sim",
82-
"close": "Fechar"
82+
"close": "Fechar",
83+
"delete": "Deletar"
8384
},
8485
"fields": {
8586
"access_token_signing_alg": "Algoritmo de assinatura de token de acesso",

admin-ui/app/routes/Apps/Gluu/GluuDialog.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const GluuDialog = ({ row, handler, modal, onAccept, subject, name }) => {
4747
style={{ color: 'red' }}
4848
className="fa fa-2x fa-warning fa-fw modal-icon mb-3"
4949
></i>
50-
{t('messages.action_deletion_for')} {subject} ({name}-{row.inum})
50+
{t('messages.action_deletion_for')} {subject} ({name}-{row.inum ? row.inum : row.id})
5151
</ModalHeader>
5252
<ModalBody>{t('messages.action_deletion_question')}</ModalBody>
5353
<ModalBody>

admin-ui/plugins/auth-server/components/Clients/ClientCibaParUmaPanel.js

+53-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useContext, useEffect } from 'react'
1+
import React, { useState } from 'react'
22
import Box from '@material-ui/core/Box'
33
import { Link } from 'react-router-dom'
44
import {
@@ -20,14 +20,14 @@ import GluuInputRow from 'Routes/Apps/Gluu/GluuInputRow'
2020
import GluuTypeAheadWithAdd from 'Routes/Apps/Gluu/GluuTypeAheadWithAdd'
2121
import { FormControlLabel, Radio, RadioGroup } from '@material-ui/core'
2222
import GluuTypeAheadForDn from 'Routes/Apps/Gluu/GluuTypeAheadForDn'
23-
import { ThemeContext } from 'Context/theme/themeContext'
2423
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
24+
import { deleteUMAResource } from 'Plugins/auth-server/redux/actions/UMAResourceActions'
25+
import GluuDialog from 'Routes/Apps/Gluu/GluuDialog'
26+
import { buildPayload } from 'Utils/PermChecker'
2527
const DOC_CATEGORY = 'openid_client'
2628

27-
function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
29+
function ClientCibaParUmaPanel({ client, dispatch, umaResources, scripts, formik }) {
2830
const { t } = useTranslation()
29-
const theme = useContext(ThemeContext)
30-
const selectedTheme = theme.state.theme
3131
const claim_uri_id = 'claim_uri_id'
3232
const cibaDeliveryModes = ['poll', 'push', 'ping']
3333
const claimRedirectURI = []
@@ -44,6 +44,7 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
4444
const [selectedUMA, setSelectedUMA] = useState()
4545
const [scopeExpression, setScopeExpression] = useState()
4646
const [showScopeSection, setShowScopeSection] = useState('scope')
47+
const [confirmModal, setConfirmModal] = useState(false)
4748

4849
const rptScripts = scripts
4950
.filter((item) => item.scriptType == 'UMA_RPT_CLAIMS')
@@ -53,12 +54,25 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
5354
const handleUMADetail = (uma) => {
5455
if (!isEmpty(uma)) {
5556
setSelectedUMA(uma)
56-
setScopeExpression(JSON.parse(uma.scopeExpression)?.data)
57+
if (!isEmpty(uma.scopeExpression)) {
58+
setScopeExpression(JSON.parse(uma.scopeExpression)?.data)
59+
}
5760
}
5861

5962
setOpen(true)
6063
}
6164

65+
const handleDeleteUMA = (uma) => {
66+
setSelectedUMA(uma)
67+
setConfirmModal(true)
68+
}
69+
70+
const onDeletionConfirmed = (message) => {
71+
buildPayload({}, message, selectedUMA.id)
72+
dispatch(deleteUMAResource(selectedUMA.id))
73+
setConfirmModal(false)
74+
}
75+
6276
return (
6377
<Container>
6478
<h2>{t(`titles.CIBA`)}</h2>
@@ -156,10 +170,24 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
156170
<Col sm={9}>
157171
{umaResources.length > 0 && umaResources?.map(uma => {
158172
return (
159-
<Box key={uma.id}>
173+
<Box key={uma.id} className="mb-2">
160174
<Box display="flex">
161-
<Box className="common-link cursor-pointer" onClick={() => handleUMADetail(uma)}>
162-
{uma.id}
175+
<Box width="40%">
176+
<a href="javascript:;" className="common-link cursor-pointer" onClick={() => handleUMADetail(uma)}>
177+
{uma.id}
178+
</a>
179+
</Box>
180+
<Box width="50%" className="text-dark">
181+
{uma.name}
182+
</Box>
183+
<Box width="10%">
184+
<Button
185+
color="danger"
186+
size="sm"
187+
onClick={() => handleDeleteUMA(uma)}
188+
>
189+
<span className="font-weight-bold">X</span>
190+
</Button>
163191
</Box>
164192
</Box>
165193
</Box>
@@ -247,15 +275,15 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
247275
</React.Fragment>
248276
) : (
249277
<React.Fragment>
250-
{!isEmpty(scopeExpression) && scopeExpression.map((expression, key) => (
278+
{!isEmpty(scopeExpression) ? scopeExpression.map((expression, key) => (
251279
<Box key={key}>
252280
<Box display="flex">
253281
<a href={expression} target="_blank" alt="scope expression" className="common-link" rel="noreferrer">
254282
{expression}
255283
</a>
256284
</Box>
257285
</Box>
258-
))}
286+
)) : '-'}
259287
</React.Fragment>
260288
)}
261289
</Col>
@@ -289,14 +317,23 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
289317
</ModalBody>
290318
<ModalFooter>
291319
<Button
292-
color={`primary-${selectedTheme}`}
293-
style={applicationStyle.buttonStyle}
294-
onClick={() => setOpen(!open)}
320+
color="danger"
321+
onClick={() => handleDeleteUMA(selectedUMA)}
295322
>
296-
{t('actions.close')}
323+
{t('actions.delete')}
297324
</Button>
298325
</ModalFooter>
299326
</Modal>
327+
{selectedUMA && (
328+
<GluuDialog
329+
row={selectedUMA}
330+
name={selectedUMA?.name}
331+
handler={() => setConfirmModal(!confirmModal)}
332+
modal={confirmModal}
333+
subject="uma resources"
334+
onAccept={onDeletionConfirmed}
335+
/>
336+
)}
300337
</Container>
301338
)
302339
}
@@ -308,5 +345,5 @@ const mapStateToProps = (state) => {
308345
scope: state.scopeReducer.item,
309346
}
310347
}
311-
export default connect(mapStateToProps)(ClientCibaParUmaPanel)
312348

349+
export default connect(mapStateToProps)(ClientCibaParUmaPanel)

admin-ui/plugins/auth-server/redux/actions/UMAResourceActions.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
GET_UMA_RESOURCES,
3-
GET_UMA_RESOURCES_RESPONSE
3+
GET_UMA_RESOURCES_RESPONSE,
4+
DELETE_UMA_RESOURCE,
5+
DELETE_UMA_RESOURCE_RESPONSE
46
} from './types'
57

68
export const getUMAResourcesByClient = (inum) => ({
@@ -12,3 +14,13 @@ export const getUMAResourcesByClientResponse = (data) => ({
1214
type: GET_UMA_RESOURCES_RESPONSE,
1315
payload: { data },
1416
})
17+
18+
export const deleteUMAResource = (action) => ({
19+
type: DELETE_UMA_RESOURCE,
20+
payload: { action },
21+
})
22+
23+
export const deleteUMAResourceResponse = (data) => ({
24+
type: DELETE_UMA_RESOURCE_RESPONSE,
25+
payload: { data },
26+
})

admin-ui/plugins/auth-server/redux/actions/types.js

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export const SET_VIEW = 'SET_VIEW'
4141
// UMA Resources
4242
export const GET_UMA_RESOURCES = 'GET_UMA_RESOURCES'
4343
export const GET_UMA_RESOURCES_RESPONSE = 'GET_UMA_RESOURCES_RESPONSE'
44+
export const DELETE_UMA_RESOURCE = 'DELETE_UMA_RESOURCE'
45+
export const DELETE_UMA_RESOURCE_RESPONSE = 'DELETE_UMA_RESOURCE_RESPONSE'
4446

4547
// Attributes types
4648
export const GET_ATTRIBUTES = 'GET_ATTRIBUTES'

admin-ui/plugins/auth-server/redux/api/UMAResourceApi.js

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export default class UMAResourceApi {
1111
})
1212
}
1313

14+
deteleUMAResources = async (id) => {
15+
return new Promise((resolve, reject) => {
16+
this.api.deleteOauthUmaResourcesById(id, (error, data) => {
17+
this.handleResponse(error, reject, resolve, data)
18+
})
19+
})
20+
}
21+
1422
handleResponse(error, reject, resolve, data) {
1523
if (error) {
1624
reject(error)

admin-ui/plugins/auth-server/redux/reducers/UMAResourceReducer.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
RESET,
33
GET_UMA_RESOURCES,
4-
GET_UMA_RESOURCES_RESPONSE
4+
GET_UMA_RESOURCES_RESPONSE,
5+
DELETE_UMA_RESOURCE,
6+
DELETE_UMA_RESOURCE_RESPONSE,
57
} from '../actions/types'
68
import reducerRegistry from 'Redux/reducers/ReducerRegistry'
79

@@ -29,6 +31,19 @@ export default function UMAResourceReducer(state = INIT_STATE, action) {
2931
return handleDefault()
3032
}
3133

34+
case DELETE_UMA_RESOURCE:
35+
return handleLoading()
36+
37+
case DELETE_UMA_RESOURCE_RESPONSE:
38+
if (action.payload.data) {
39+
return {
40+
...state,
41+
items: state.items.filter(({ id }) => id !== action.payload.data),
42+
loading: false,
43+
}
44+
}
45+
return handleDefault()
46+
3247
case RESET:
3348
return {
3449
...state,

admin-ui/plugins/auth-server/redux/sagas/UMAResourceSaga.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {
44
addAdditionalData,
55
} from 'Utils/TokenController'
66
import { postUserAction } from 'Redux/api/backend-api'
7-
import { getUMAResourcesByClientResponse } from '../actions/UMAResourceActions'
7+
import { getUMAResourcesByClientResponse, deleteUMAResourceResponse } from '../actions/UMAResourceActions'
88
import { getAPIAccessToken } from '../actions/AuthActions'
99
import { UMA } from '../audit/Resources'
10-
import { FETCH } from '../../../../app/audit/UserActionType'
11-
import { GET_UMA_RESOURCES } from '../actions/types'
10+
import { FETCH, DELETION } from '../../../../app/audit/UserActionType'
11+
import { DELETE_UMA_RESOURCE, GET_UMA_RESOURCES } from '../actions/types'
1212
import UMAResourceApi from '../api/UMAResourceApi'
1313
import { getClient } from 'Redux/api/base'
1414
const JansConfigApi = require('jans_config_api')
@@ -51,12 +51,34 @@ export function* getUMAResourcesByClient({ payload }) {
5151
}
5252
}
5353

54+
export function* deleteUMAResourceById({ payload }) {
55+
const audit = yield* initAudit()
56+
try {
57+
addAdditionalData(audit, DELETION, UMA, payload)
58+
const api = yield* newFunction()
59+
yield call(api.deleteUMAResourceById, payload.action.action_data)
60+
yield put(deleteUMAResourceResponse(payload.action.action_data))
61+
yield call(postUserAction, audit)
62+
} catch (e) {
63+
yield put(deleteUMAResourceResponse(null))
64+
if (isFourZeroOneError(e)) {
65+
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
66+
yield put(getAPIAccessToken(jwt))
67+
}
68+
}
69+
}
70+
5471
export function* getUMAResourcesByClientWatcher() {
5572
yield takeLatest(GET_UMA_RESOURCES, getUMAResourcesByClient)
5673
}
5774

75+
export function* deleteUMAResourceByIdWatcher() {
76+
yield takeLatest(DELETE_UMA_RESOURCE, deleteUMAResourceById)
77+
}
78+
5879
export default function* rootSaga() {
5980
yield all([
6081
fork(getUMAResourcesByClientWatcher),
82+
fork(deleteUMAResourceByIdWatcher),
6183
])
6284
}

0 commit comments

Comments
 (0)