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 6, 2021
1 parent 1cc2789 commit a421a70
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
20 changes: 16 additions & 4 deletions plugins/admin/components/Roles/UiRoleListPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import MaterialTable from 'material-table'
import { Paper } from '@material-ui/core'
import UiRoleDetailPage from './UiRoleDetailPage'
Expand All @@ -9,16 +9,28 @@ import { useTranslation } from 'react-i18next'
import GluuViewWrapper from '../../../../app/routes/Apps/Gluu/GluuViewWrapper'
import GluuRibbon from '../../../../app/routes/Apps/Gluu/GluuRibbon'
import applicationStyle from '../../../../app/routes/Apps/Gluu/styles/applicationstyle'
import {
deleteRole,
getRoles,
setCurrentItem,
} from '../../redux/actions/ApiRoleActions'
import {
hasPermission,
buildPayload,
SCRIPT_READ,
SCRIPT_WRITE,
} from '../../../../app/utils/PermChecker'

function UiRoleListPage({ apiRoles, permissions, loading }) {
function UiRoleListPage({ apiRoles, permissions, loading, dispatch }) {
const { t } = useTranslation()
const myActions = []
const options = []
const userAction = {}
const pageSize = localStorage.getItem('paggingSize') || 10
useEffect(() => {
buildPayload(userAction, 'ROLES', options)
dispatch(getRoles(userAction))
}, [])

if (hasPermission(permissions, SCRIPT_READ)) {
myActions.push((rowData) => ({
Expand Down Expand Up @@ -69,9 +81,9 @@ function UiRoleListPage({ apiRoles, permissions, loading }) {
columns={[
{
title: `${t('fields.name')}`,
field: 'name',
field: 'role',
width: '20%',
render: (rowData) => <Badge color="info">{rowData.name}</Badge>,
render: (rowData) => <Badge color="info">{rowData.role}</Badge>,
},
{ title: `${t('fields.description')}`, field: 'description' },
]}
Expand Down
8 changes: 4 additions & 4 deletions plugins/admin/components/Roles/roles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const roles = [
{
name: 'api-admin',
role: 'api-admin',
description:
'This role allows a user to access all list and search features available. Not possible for this role to perform edition nor deletion',
scopes: [
Expand All @@ -9,7 +9,7 @@ export const roles = [
],
},
{
name: 'api-viewer',
role: 'api-viewer',
description:
'This role allows a user to perform all possible actions on api objects',
scopes: [
Expand All @@ -18,7 +18,7 @@ export const roles = [
],
},
{
name: 'api-editor',
role: 'api-editor',
description:
'This role allow a user to list, search, add and edit on all available objects excepts the configuration object which is critical for a running server',
scopes: [
Expand All @@ -27,7 +27,7 @@ export const roles = [
],
},
{
name: 'api-manager',
role: 'api-manager',
description:
'This role allows a user to list, search, add, edit and delete all available objects include the configuration object(only in view mode). The user cannot edit nor delete the configuration object.',
scopes: [
Expand Down
10 changes: 9 additions & 1 deletion plugins/admin/plugin-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SettingsPage from './components/Settings/SettingsPage'
import mauSaga from './redux/sagas/MauSaga'
import scriptSaga from './redux/sagas/CustomScriptSaga'
import licenseDetailsSaga from './redux/sagas/LicenseDetailsSaga'
import apiRoleSaga from './redux/sagas/ApiRoleSaga'
import apiPermissionSaga from './redux/sagas/ApiPermissionSaga'

import mauReducer from './redux/reducers/MauReducer'
import scriptReducer from './redux/reducers/CustomScriptReducer'
Expand Down Expand Up @@ -133,7 +135,13 @@ const pluginMetadata = {
{ name: 'apiPermissionReducer', reducer: apiPermissionReducer },
{ name: 'licenseDetailsReducer', reducer: licenseDetailsReducer },
],
sagas: [mauSaga(), scriptSaga(), licenseDetailsSaga()],
sagas: [
mauSaga(),
scriptSaga(),
licenseDetailsSaga(),
apiRoleSaga(),
apiPermissionSaga(),
],
}

export default pluginMetadata
3 changes: 3 additions & 0 deletions plugins/admin/redux/api/RoleApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default class RoleApi {
getRoles = () => {
return new Promise((resolve, reject) => {
console.log('=============get roles')
this.api.getAdminuiRoles((error, data) => {
this.handleResponse(error, reject, resolve, data)
})
})
}
getRole = (options) => {
Expand Down
5 changes: 2 additions & 3 deletions plugins/admin/redux/reducers/ApiRoleReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import {
RESET,
} from '../actions/types'
import reducerRegistry from '../../../../app/redux/reducers/ReducerRegistry'
import roles from '../../components/Roles/roles'

const INIT_STATE = {
items: roles,
loading: true,
items: [],
loading: false,
}
const reducerName = 'apiRoleReducer'

Expand Down
2 changes: 1 addition & 1 deletion plugins/admin/redux/sagas/ApiRoleSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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(
const api = new JansConfigApi.AdminUIRoleApi(
getClient(JansConfigApi, token, issuer),
)
return new RoleApi(api)
Expand Down

0 comments on commit a421a70

Please sign in to comment.