Skip to content

Commit

Permalink
feat(admin-ui): get scope by inum api not triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
harryandriyan committed Aug 17, 2022
1 parent 6c1db7b commit a1b568c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import Box from '@material-ui/core/Box'
import { Link } from 'react-router-dom'
import {
Expand All @@ -22,11 +22,11 @@ import { FormControlLabel, Radio, RadioGroup } from '@material-ui/core'
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 { getScope } from 'Plugins/auth-server/redux/actions/ScopeActions'
import GluuDialog from 'Routes/Apps/Gluu/GluuDialog'
import { buildPayload } from 'Utils/PermChecker'
const DOC_CATEGORY = 'openid_client'

function ClientCibaParUmaPanel({ client, dispatch, umaResources, scripts, formik }) {
function ClientCibaParUmaPanel({ client, dispatch, umaResources, scope, scripts, formik }) {
const { t } = useTranslation()
const claim_uri_id = 'claim_uri_id'
const cibaDeliveryModes = ['poll', 'push', 'ping']
Expand Down Expand Up @@ -68,11 +68,26 @@ function ClientCibaParUmaPanel({ client, dispatch, umaResources, scripts, formik
}

const onDeletionConfirmed = (message) => {
buildPayload({}, message, selectedUMA.id)
dispatch(deleteUMAResource(selectedUMA.id))
const params = {
id: selectedUMA.id,
message
}
dispatch(deleteUMAResource(params))
setConfirmModal(false)
}

useEffect(() => {
if(!isEmpty(selectedUMA) && !isEmpty(selectedUMA.scopes) && selectedUMA.scopes?.length > 0) {
selectedUMA.scopes.map(scope => {
// scope data example [string] inum=9bc94613-f678-4bb9-a19d-ed026b492247,ou=scopes,o=jans
const getInum = scope.split(',')[0]
const inum = getInum.split('=')[1]

dispatch(getScope(inum))
})
}
}, [selectedUMA])

return (
<Container>
<h2>{t(`titles.CIBA`)}</h2>
Expand Down Expand Up @@ -255,16 +270,16 @@ function ClientCibaParUmaPanel({ client, dispatch, umaResources, scripts, formik
<Col sm={9} className="top-5">
{showScopeSection === 'scope' ? (
<React.Fragment>
{!isEmpty(selectedUMA) && selectedUMA?.scopes?.map((scope, key) => {
const getInum = scope.split(',')[0]
{!isEmpty(selectedUMA) && selectedUMA?.scopes?.map((scopeString, key) => {
const getInum = scopeString.split(',')[0]
const inum = getInum.length > 0 ? getInum.split('=')[1] : null

if (inum) {
if (!isEmpty(scope[inum])) {
return (
<Box key={key}>
<Box display="flex">
<Link to={`/auth-server/scope/edit:${inum}`} className="common-link">
{scope}
<Link to={`/auth-server/scope/edit:${scope[inum]?.inum}`} className="common-link">
{scope[inum]?.displayName}
</Link>
</Box>
</Box>
Expand Down
11 changes: 7 additions & 4 deletions admin-ui/plugins/auth-server/redux/actions/ScopeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export const deleteScopeResponse = (data) => ({
payload: { data },
})

export const setCurrentItem = (item) => ({
type: SET_ITEM,
payload: { item },
})
export const setCurrentItem = (item, inum) => {
console.log(item, inum)
return ({
type: SET_ITEM,
payload: { item, inum },
})
}
2 changes: 1 addition & 1 deletion admin-ui/plugins/auth-server/redux/api/ScopeApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ScopeApi {
})
}

getScope = async (id) => {
patchScope = async (id) => {
return new Promise((resolve, reject) => {
this.api.patchOauthScopesById(id, (error, data) => {
this.handleResponse(error, reject, resolve, data)
Expand Down
3 changes: 2 additions & 1 deletion admin-ui/plugins/auth-server/redux/api/UMAResourceApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export default class UMAResourceApi {
})
}

deteleUMAResources = async (id) => {
deteleUMAResource = async (id) => {
return new Promise((resolve, reject) => {
this.api.deleteOauthUmaResourcesById(id, (error, data) => {
console.log('delete uma')
this.handleResponse(error, reject, resolve, data)
})
})
Expand Down
18 changes: 13 additions & 5 deletions admin-ui/plugins/auth-server/redux/reducers/ScopeReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ export default function scopeReducer(state = INIT_STATE, action) {
}

case SET_ITEM:
return {
...state,
item: action.payload.item,
loading: false,
}
return setItem()
case RESET:
return {
...state,
Expand All @@ -135,6 +131,18 @@ export default function scopeReducer(state = INIT_STATE, action) {
default:
return handleDefault()
}
function setItem() {
const currentItem = state.item
const newItem = { ...currentItem, [action.payload.inum]: action.payload.item }

console.log('newItem', newItem)

return {
...state,
item: newItem,
loading: false,
}
}
function handleLoading() {
return {
...state,
Expand Down
3 changes: 2 additions & 1 deletion admin-ui/plugins/auth-server/redux/sagas/OAuthScopeSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export function* getScopeByInum({ payload }) {
addAdditionalData(audit, FETCH, SCOPE, {})
const scopeApi = yield* newFunction()
const data = yield call(scopeApi.getScope, payload.action)
yield put(setCurrentItem(data))
console.log('data', data)
yield put(setCurrentItem(data, payload.action))
yield call(postUserAction, audit)
} catch (e) {
yield put(deleteScopeResponse(null))
Expand Down
4 changes: 2 additions & 2 deletions admin-ui/plugins/auth-server/redux/sagas/UMAResourceSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function* deleteUMAResourceById({ payload }) {
try {
addAdditionalData(audit, DELETION, UMA, payload)
const api = yield* newFunction()
yield call(api.deleteUMAResourceById, payload.action.action_data)
yield put(deleteUMAResourceResponse(payload.action.action_data))
yield call(api.deteleUMAResource, payload.action.id)
yield put(deleteUMAResourceResponse(payload.action.id))
yield call(postUserAction, audit)
} catch (e) {
yield put(deleteUMAResourceResponse(null))
Expand Down

0 comments on commit a1b568c

Please sign in to comment.