Skip to content

Commit 7423e9f

Browse files
committed
fix(admin-ui): add user move redux to app
1 parent 1f7635f commit 7423e9f

File tree

9 files changed

+279
-43
lines changed

9 files changed

+279
-43
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {
2+
UM_GET_USERS,
3+
UM_UPDATE_USERS_RESPONSE,
4+
UM_UPDATE_LOADING,
5+
} from './types'
6+
7+
export const getUsers = (action) => ({
8+
type: UM_GET_USERS,
9+
payload: { action },
10+
})
11+
12+
export const updateUserResponse = (action) => ({
13+
type: UM_UPDATE_USERS_RESPONSE,
14+
payload: { action },
15+
})
16+
export const UMupdateUserLoading = (action) => ({
17+
type: UM_UPDATE_LOADING,
18+
payload: action,
19+
})

admin-ui/app/redux/actions/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from './AuthActions'
55
export * from './InitActions'
66
export * from './LicenseActions'
77
export * from './OidcDiscoveryActions'
8+
export * from './UserActions'

admin-ui/app/redux/actions/types.js

+8
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,22 @@ export const ACTIVATE_CHECK_USER_LICENSE_KEY_RESPONSE =
7070
'ACTIVATE_CHECK_USER_LICENSE_KEY_RESPONSE'
7171
export const ACTIVATE_CHECK_LICENCE_API_VALID =
7272
'ACTIVATE_CHECK_LICENCE_API_VALID'
73+
7374
//OIDC DISCOVERY
7475
export const GET_OIDC_DISCOVERY = 'GET_OIDC_DISCOVERY'
7576
export const GET_OIDC_DISCOVERY_RESPONSE = 'GET_OIDC_DISCOVERY_RESPONSE'
77+
7678
// Health
7779
export const GET_HEALTH = 'GET_HEALTH'
7880
export const GET_HEALTH_RESPONSE = 'GET_HEALTH_RESPONSE'
81+
7982
//License Details
8083
export const GET_LICENSE_DETAILS = 'GET_LICENSE_DETAILS'
8184
export const GET_LICENSE_DETAILS_RESPONSE = 'GET_LICENSE_DETAILS_RESPONSE'
8285
export const UPDATE_LICENSE_DETAILS = 'UPDATE_LICENSE_DETAILS'
8386
export const UPDATE_LICENSE_DETAILS_RESPONSE = 'UPDATE_LICENSE_DETAILS_RESPONSE'
87+
88+
//User Management
89+
export const UM_GET_USERS = 'UM_GET_USERS'
90+
export const UM_UPDATE_USERS_RESPONSE = 'UM_UPDATE_USERS_RESPONSE'
91+
export const UM_UPDATE_LOADING = 'UM_UPDATE_LOADING'

admin-ui/app/redux/api/UserApi.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default class UserApi {
2+
constructor(api) {
3+
this.api = api
4+
}
5+
6+
getUsers = () => {
7+
return new Promise((resolve, reject) => {
8+
this.api.getUser({}, (error, data) => {
9+
this.handleResponse(error, reject, resolve, data)
10+
})
11+
})
12+
}
13+
14+
handleResponse(error, reject, resolve, data) {
15+
if (error) {
16+
reject(error)
17+
} else {
18+
resolve(data)
19+
}
20+
}
21+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { UM_UPDATE_LOADING, UM_GET_USERS } from '../actions/types'
2+
import reducerRegistry from './ReducerRegistry'
3+
4+
const INIT_STATE = {
5+
items: [],
6+
selectedUserData: null,
7+
loading: true,
8+
redirectToUserListPage: false,
9+
}
10+
const reducerName = 'userReducer'
11+
12+
export default function userReducer(state = INIT_STATE, action) {
13+
switch (action.type) {
14+
case UM_GET_USERS:
15+
return {
16+
...state,
17+
loading: true,
18+
}
19+
case UM_UPDATE_LOADING:
20+
return {
21+
...state,
22+
loading: action.payload,
23+
}
24+
default:
25+
return handleDefault()
26+
}
27+
28+
function handleDefault() {
29+
return {
30+
...state,
31+
}
32+
}
33+
}
34+
reducerRegistry.register(reducerName, userReducer)

admin-ui/app/redux/reducers/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import logoutReducer from './LogoutReducer'
1010
import licenseReducer from './LicenseReducer'
1111
import licenseDetailsReducer from './LicenseDetailsReducer'
1212
import oidcDiscoveryReducer from './OidcDiscoveryReducer'
13-
13+
import userReducer from './UserReducer'
1414
const appReducers = {
1515
authReducer,
1616
fidoReducer,
@@ -21,6 +21,7 @@ const appReducers = {
2121
mauReducer,
2222
healthReducer,
2323
licenseDetailsReducer,
24+
userReducer,
2425
}
2526

2627
export default appReducers

admin-ui/app/redux/sagas/UserSaga.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { call, all, put, fork, select, takeEvery } from 'redux-saga/effects'
2+
import { FETCH } from '../../audit/UserActionType'
3+
import {
4+
isFourZeroOneError,
5+
addAdditionalData,
6+
} from '../../utils/TokenController'
7+
import { UM_GET_USERS } from '../actions/types'
8+
import UserApi from '../api/UserApi'
9+
import { getClient } from '../api/base'
10+
const JansConfigApi = require('jans_config_api')
11+
import { initAudit } from './SagaUtils'
12+
import { updateUserResponse, UMupdateUserLoading } from '../actions/UserActions'
13+
import { postUserAction } from '../api/backend-api'
14+
import { getAPIAccessToken } from '../actions'
15+
const API_USERS = 'api-users'
16+
17+
function* newFunction() {
18+
const token = yield select((state) => state.authReducer.token.access_token)
19+
const issuer = yield select((state) => state.authReducer.issuer)
20+
const api = new JansConfigApi.ConfigurationUserManagementApi(
21+
getClient(JansConfigApi, token, issuer),
22+
)
23+
return new UserApi(api)
24+
}
25+
26+
export function* getUsersSaga({ payload }) {
27+
const audit = yield* initAudit()
28+
try {
29+
addAdditionalData(audit, FETCH, API_USERS, payload)
30+
const userApi = yield* newFunction()
31+
const data = yield call(userApi.getUsers)
32+
yield put(updateUserResponse(data))
33+
yield put(UMupdateUserLoading(false))
34+
yield call(postUserAction, audit)
35+
} catch (e) {
36+
yield put(UMupdateUserLoading(false))
37+
if (isFourZeroOneError(e)) {
38+
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
39+
yield put(getAPIAccessToken(jwt))
40+
}
41+
}
42+
}
43+
44+
export function* watchGetUsers() {
45+
yield takeEvery(UM_GET_USERS, getUsersSaga)
46+
}
47+
48+
export default function* rootSaga() {
49+
yield all([fork(watchGetUsers)])
50+
}

admin-ui/app/redux/sagas/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import licenseSaga from './LicenseSaga'
1313
import licenseDetailsSaga from './LicenseDetailsSaga'
1414
import oidcDiscoverySaga from './OidcDiscoverySaga'
1515
import process from 'Plugins/PluginSagasResolver'
16-
16+
import userSaga from './UserSaga'
1717
export default function* rootSaga() {
1818
const pluginSagaArr = process()
1919
yield all(
@@ -27,6 +27,7 @@ export default function* rootSaga() {
2727
mauSaga(),
2828
healthSaga(),
2929
licenseDetailsSaga(),
30+
userSaga(),
3031
],
3132
pluginSagaArr,
3233
),

0 commit comments

Comments
 (0)