-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): design the layout for api role management #327
- Loading branch information
Showing
9 changed files
with
524 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
GET_PERMISSIONS, | ||
GET_PERMISSIONS_RESPONSE, | ||
ADD_PERMISSION, | ||
ADD_PERMISSION_RESPONSE, | ||
EDIT_PERMISSION, | ||
EDIT_PERMISSION_RESPONSE, | ||
GET_PERMISSION, | ||
GET_PERMISSION_RESPONSE, | ||
DELETE_PERMISSION, | ||
DELETE_PERMISSION_RESPONSE, | ||
SET_PERMISSION_ITEM, | ||
} from './types' | ||
|
||
export const getPermisions = (action) => ({ | ||
type: GET_PERMISSIONS, | ||
payload: { action }, | ||
}) | ||
|
||
export const getPermissionsResponse = (data) => ({ | ||
type: GET_PERMISSIONS_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const addPermission = (action) => ({ | ||
type: ADD_PERMISSION, | ||
payload: { action }, | ||
}) | ||
|
||
export const addPermissionResponse = (data) => ({ | ||
type: ADD_PERMISSION_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const editPermission = (action) => ({ | ||
type: EDIT_PERMISSION, | ||
payload: { action }, | ||
}) | ||
|
||
export const editPermissionResponse = (data) => ({ | ||
type: EDIT_PERMISSION_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const getPermission = (action) => ({ | ||
type: GET_PERMISSION, | ||
payload: { action }, | ||
}) | ||
|
||
export const getPermissionResponse = (data) => ({ | ||
type: GET_PERMISSION_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const deletePermission = (action) => ({ | ||
type: DELETE_PERMISSION, | ||
payload: { action }, | ||
}) | ||
|
||
export const deletePermissionResponse = (inum) => ({ | ||
type: DELETE_PERMISSION_RESPONSE, | ||
payload: { inum }, | ||
}) | ||
|
||
export const setCurrentItem = (item) => ({ | ||
type: SET_PERMISSION_ITEM, | ||
payload: { item }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
GET_ROLES, | ||
GET_ROLES_RESPONSE, | ||
ADD_ROLE, | ||
ADD_ROLE_RESPONSE, | ||
EDIT_ROLE, | ||
EDIT_ROLE_RESPONSE, | ||
GET_ROLE, | ||
GET_ROLE_RESPONSE, | ||
DELETE_ROLE, | ||
DELETE_ROLE_RESPONSE, | ||
SET_ROLE_ITEM, | ||
} from './types' | ||
|
||
export const getRoles = (action) => ({ | ||
type: GET_ROLES, | ||
payload: { action }, | ||
}) | ||
|
||
export const getRolesResponse = (data) => ({ | ||
type: GET_ROLES_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const addRole = (action) => ({ | ||
type: ADD_ROLE, | ||
payload: { action }, | ||
}) | ||
|
||
export const addRoleResponse = (data) => ({ | ||
type: ADD_ROLE_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const editRole = (action) => ({ | ||
type: EDIT_ROLE, | ||
payload: { action }, | ||
}) | ||
|
||
export const editRoleResponse = (data) => ({ | ||
type: EDIT_ROLE_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const getRole = (action) => ({ | ||
type: GET_ROLE, | ||
payload: { action }, | ||
}) | ||
|
||
export const getRoleResponse = (data) => ({ | ||
type: GET_ROLE_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const deleteRole = (action) => ({ | ||
type: DELETE_ROLE, | ||
payload: { action }, | ||
}) | ||
|
||
export const deleteRoleResponse = (inum) => ({ | ||
type: DELETE_ROLE_RESPONSE, | ||
payload: { inum }, | ||
}) | ||
|
||
export const setCurrentItem = (item) => ({ | ||
type: SET_ROLE_ITEM, | ||
payload: { item }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default class PermissionApi { | ||
constructor(api) { | ||
this.api = api | ||
} | ||
getPermissions = () => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
getPermission = (options) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
addPermission = (data) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
editPermission = (data) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
deletePermission = async (inum) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
handleResponse(error, reject, resolve, data) { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(data) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default class RoleApi { | ||
constructor(api) { | ||
this.api = api | ||
} | ||
getRoles = () => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
getRole = (options) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
addRole = (data) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
editRole = (data) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
deleteRole = async (inum) => { | ||
return new Promise((resolve, reject) => {}) | ||
} | ||
|
||
handleResponse(error, reject, resolve, data) { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(data) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import { call, all, put, fork, takeLatest, select } from 'redux-saga/effects' | ||
import { getAPIAccessToken } from '../../../../app/redux/actions/AuthActions' | ||
import { API_PERMISSION } from '../audit/Resources' | ||
import PermissionApi from '../api/PermissionApi' | ||
import { getClient } from '../../../../app/redux/api/base' | ||
import { postUserAction } from '../../../../app/redux/api/backend-api' | ||
import { | ||
getPermissionsResponse, | ||
addPermissionResponse, | ||
editPermissionResponse, | ||
deletePermissionResponse, | ||
} from '../actions/ApiPermissionActions' | ||
import { | ||
CREATE, | ||
UPDATE, | ||
DELETION, | ||
FETCH, | ||
} from '../../../../app/audit/UserActionType' | ||
import { | ||
isFourZeroOneError, | ||
addAdditionalData, | ||
} from '../../../../app/utils/TokenController' | ||
import { | ||
GET_PERMISSIONS, | ||
ADD_PERMISSION, | ||
EDIT_PERMISSION, | ||
DELETE_PERMISSION, | ||
GET_PERMISSION, | ||
} from '../actions/types' | ||
|
||
const JansConfigApi = require('jans_config_api') | ||
import { initAudit } from '../../../../app/redux/sagas/SagaUtils' | ||
|
||
function* newFunction() { | ||
const token = yield select((state) => state.authReducer.token.access_token) | ||
const issuer = yield select((state) => state.authReducer.issuer) | ||
const api = new JansConfigApi.CustomScriptsApi( | ||
getClient(JansConfigApi, token, issuer), | ||
) | ||
return new PermissionApi(api) | ||
} | ||
|
||
export function* getPermissions({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
addAdditionalData(audit, FETCH, API_PERMISSION, payload) | ||
const permApi = yield* newFunction() | ||
const data = yield call(permApi.getPermissions) | ||
yield put(getPermissionsResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(getPermissionsResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
export function* getPermission({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
addAdditionalData(audit, FETCH, API_PERMISSION, payload) | ||
const permApi = yield* newFunction() | ||
const data = yield call(permApi.getPermission, payload.action.action_data) | ||
yield put(getPermissionResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(getPermissionResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
export function* addPermission({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
addAdditionalData(audit, CREATE, API_PERMISSION, payload) | ||
const permApi = yield* newFunction() | ||
const data = yield call(permApi.addPermission, payload.action.action_data) | ||
yield put(addPermissionResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(addPermissionResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
export function* editPermission({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
addAdditionalData(audit, UPDATE, API_PERMISSION, payload) | ||
const permApi = yield* newFunction() | ||
const data = yield call(permApi.editPermission, payload.action.action_data) | ||
yield put(editPermissionResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(editPermissionResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
|
||
export function* deletePermission({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
addAdditionalData(audit, DELETION, API_PERMISSION, payload) | ||
const permApi = yield* newFunction() | ||
yield call(permApi.deletePermission, payload.action.action_data) | ||
yield put(deletePermissionResponse(payload.action.action_data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(deletePermissionResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
|
||
export function* watchGetPermissions() { | ||
yield takeLatest(GET_PERMISSIONS, getPermissions) | ||
} | ||
|
||
export function* watchAddPermission() { | ||
yield takeLatest(ADD_PERMISSION, addPermission) | ||
} | ||
|
||
export function* watchEditPermission() { | ||
yield takeLatest(EDIT_PERMISSION, editPermission) | ||
} | ||
export function* watchDeletePermission() { | ||
yield takeLatest(DELETE_PERMISSION, deletePermission) | ||
} | ||
export function* watchGetPermission() { | ||
yield takeLatest(GET_PERMISSION, getPermission) | ||
} | ||
export default function* rootSaga() { | ||
yield all([ | ||
fork(watchGetPermissions), | ||
fork(watchAddPermission), | ||
fork(watchEditPermission), | ||
fork(watchGetPermission), | ||
fork(watchDeletePermission), | ||
]) | ||
} |
Oops, something went wrong.