Skip to content

Commit

Permalink
feat(admin-ui): design the layout for api role management #327
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Dec 2, 2021
1 parent 14da9b9 commit 5d17005
Show file tree
Hide file tree
Showing 9 changed files with 524 additions and 36 deletions.
8 changes: 4 additions & 4 deletions app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@
"titles": {
"acrs": "ACRs",
"algorithmic_keys": "Algorithmic Keys",
"all_attributes": "All Attributes",
"all_custom_scripts": "All Custom Scripts",
"all_oidc_clients": "All OIDC Clients",
"all_scopes": "All Scopes",
"all_attributes": "Attributes/Claims",
"all_custom_scripts": "Custom Scripts",
"all_oidc_clients": "OpenID Clients",
"all_scopes": "OAuth/OpenID Scopes",
"client_advanced": "Advanced",
"client_attributes": "Client Attributes",
"client_basic": "Basic",
Expand Down
68 changes: 68 additions & 0 deletions plugins/admin/redux/actions/ApiPermissionActions.js
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 },
})
68 changes: 68 additions & 0 deletions plugins/admin/redux/actions/ApiRoleActions.js
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 },
})
31 changes: 31 additions & 0 deletions plugins/admin/redux/api/PermissionApi.js
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)
}
}
}
31 changes: 31 additions & 0 deletions plugins/admin/redux/api/RoleApi.js
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)
}
}
}
150 changes: 150 additions & 0 deletions plugins/admin/redux/sagas/ApiPermissionSaga.js
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),
])
}
Loading

0 comments on commit 5d17005

Please sign in to comment.