Skip to content

Commit

Permalink
feat(admin-ui): add uma resources function
Browse files Browse the repository at this point in the history
  • Loading branch information
harryandriyan committed Aug 8, 2022
1 parent d33a7db commit 94c513a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion admin-ui/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
'generator-star-spacing': 'off',
'space-in-parens': ['error', 'never'],
'comma-spacing': ['error', { before: false, after: true }],
indent: ['error', 2, { ignoredNodes: ['JSXElement'] }],
indent: ['error', 2, { ignoredNodes: ['JSXElement'], "SwitchCase": 1 }],
'react/jsx-indent': ['error', 2],
'react/jsx-indent-props': ['error', 2],
'react/display-name': [0, { ignoreTranspilerName: false }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import ClientWizardForm from './ClientWizardForm'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import { useHistory } from 'react-router-dom'
import { connect } from 'react-redux'
import { editClient } from 'Plugins/auth-server/redux/actions/OIDCActions'
import { editClient, getUMAResourcesByClient } from 'Plugins/auth-server/redux/actions/OIDCActions'
import { getScopes } from 'Plugins/auth-server/redux/actions/ScopeActions'
import { getOidcDiscovery } from 'Redux/actions/OidcDiscoveryActions'
import { getScripts } from 'Redux/actions/InitActions'
import { buildPayload } from 'Utils/PermChecker'
import GluuAlert from 'Routes/Apps/Gluu/GluuAlert'
import { useTranslation } from 'react-i18next'
import isEmpty from 'lodash/isEmpty'

function ClientEditPage({
clientData,
Expand All @@ -22,6 +23,7 @@ function ClientEditPage({
oidcConfiguration,
saveOperationFlag,
errorInSaveOperationFlag,
umaResources,
}) {
const userAction = {}
const options = {}
Expand All @@ -37,6 +39,10 @@ function ClientEditPage({
if (scripts.length < 1) {
dispatch(getScripts(options))
}
console.log('umaResources', umaResources)
if (isEmpty(umaResources)) {
dispatch(getUMAResourcesByClient(clientData?.inum))
}
dispatch(getOidcDiscovery())
}, [])
useEffect(() => {
Expand Down Expand Up @@ -86,6 +92,7 @@ const mapStateToProps = (state) => {
oidcConfiguration: state.oidcDiscoveryReducer.configuration,
saveOperationFlag: state.oidcReducer.saveOperationFlag,
errorInSaveOperationFlag: state.oidcReducer.errorInSaveOperationFlag,
umaResources: state.oidcReducer.umaResources,
}
}
export default connect(mapStateToProps)(ClientEditPage)
6 changes: 6 additions & 0 deletions admin-ui/plugins/auth-server/redux/actions/OIDCActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SET_CLIENT_ITEM,
SET_VIEW,
SEARCH_CLIENTS,
GET_UMA_RESOURCES
} from './types'

export const getOpenidClients = (action) => ({
Expand Down Expand Up @@ -65,3 +66,8 @@ export const viewOnly = (view) => ({
type: SET_VIEW,
payload: { view },
})

export const getUMAResourcesByClient = (inum) => ({
type: GET_UMA_RESOURCES,
payload: { inum },
})
1 change: 1 addition & 0 deletions admin-ui/plugins/auth-server/redux/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const DELETE_CLIENT = 'DELETE_CLIENT'
export const DELETE_CLIENT_RESPONSE = 'DELETE_CLIENT_RESPONSE'
export const SET_CLIENT_ITEM = 'SET_CLIENT_ITEM'
export const SET_VIEW = 'SET_VIEW'
export const GET_UMA_RESOURCES = 'GET_UMA_RESOURCES'

// Attributes types
export const GET_ATTRIBUTES = 'GET_ATTRIBUTES'
Expand Down
8 changes: 8 additions & 0 deletions admin-ui/plugins/auth-server/redux/api/OIDCApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ export default class OIDCApi {
})
}

getUMAResources = async (clientId) => {
return new Promise((resolve, reject) => {
this.api.getUMAResourcesByClient(clientId, (error, data) => {
this.handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
Expand Down
8 changes: 7 additions & 1 deletion admin-ui/plugins/auth-server/redux/reducers/OIDCReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RESET,
SEARCH_CLIENTS,
SET_VIEW,
GET_UMA_RESOURCES
} from '../actions/types'
import reducerRegistry from 'Redux/reducers/ReducerRegistry'

Expand All @@ -21,6 +22,7 @@ const INIT_STATE = {
loading: false,
saveOperationFlag: false,
errorInSaveOperationFlag: false,
umaResources: {},
}

const reducerName = 'oidcReducer'
Expand Down Expand Up @@ -127,7 +129,11 @@ export default function oidcReducer(state = INIT_STATE, action) {
} else {
return handleDefault()
}

case GET_UMA_RESOURCES:
return {
...state,
umaResources: action.payload.item,
}
case RESET:
return {
...state,
Expand Down
22 changes: 22 additions & 0 deletions admin-ui/plugins/auth-server/redux/sagas/OIDCSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EDIT_CLIENT,
DELETE_CLIENT,
SEARCH_CLIENTS,
GET_UMA_RESOURCES
} from '../actions/types'
import OIDCApi from '../api/OIDCApi'
import { getClient } from 'Redux/api/base'
Expand Down Expand Up @@ -122,6 +123,23 @@ export function* deleteAClient({ payload }) {
}
}

export function* getUMAResourcesByClient(inum) {
const audit = yield* initAudit()
try {
addAdditionalData(audit, FETCH, GET_UMA_RESOURCES, {})
const api = yield* newFunction()
const data = yield call(api.getOauthUmaResourcesByClientid, inum)
yield put(deleteClientResponse(data))
yield call(postUserAction, audit)
} catch (e) {
yield put(deleteClientResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}

export function* getOpenidClientsWatcher() {
yield takeLatest(GET_OPENID_CLIENTS, getOauthOpenidClients)
}
Expand All @@ -140,6 +158,9 @@ export function* editClientWatcher() {
export function* deleteClientWatcher() {
yield takeLatest(DELETE_CLIENT, deleteAClient)
}
export function* getUMAResourcesByClientWatcher() {
yield takeLatest(GET_UMA_RESOURCES, getUMAResourcesByClient)
}

export default function* rootSaga() {
yield all([
Expand All @@ -148,5 +169,6 @@ export default function* rootSaga() {
fork(addClientWatcher),
fork(editClientWatcher),
fork(deleteClientWatcher),
fork(getUMAResourcesByClientWatcher),
])
}

0 comments on commit 94c513a

Please sign in to comment.