Skip to content

Commit a6a4172

Browse files
committed
feat(admin-ui): provide roles and permissions management screens in Admin UI #339
1 parent 6dcf479 commit a6a4172

File tree

4 files changed

+99
-81
lines changed

4 files changed

+99
-81
lines changed

plugins/admin/components/Permissions/UiPermListPage.js

+43-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import MaterialTable from 'material-table'
33
import { Paper } from '@material-ui/core'
44
import UiPermDetailPage from './UiPermDetailPage'
@@ -9,7 +9,12 @@ import { useTranslation } from 'react-i18next'
99
import GluuViewWrapper from '../../../../app/routes/Apps/Gluu/GluuViewWrapper'
1010
import GluuRibbon from '../../../../app/routes/Apps/Gluu/GluuRibbon'
1111
import applicationStyle from '../../../../app/routes/Apps/Gluu/styles/applicationstyle'
12-
import { getPermissions } from '../../redux/actions/ApiPermissionActions'
12+
import {
13+
getPermissions,
14+
deletePermission,
15+
editPermission,
16+
addPermission,
17+
} from '../../redux/actions/ApiPermissionActions'
1318
import {
1419
hasPermission,
1520
buildPayload,
@@ -19,50 +24,39 @@ import {
1924

2025
function UiPermListPage({ apiPerms, permissions, loading, dispatch }) {
2126
const { t } = useTranslation()
27+
const [modal, setModal] = useState(false)
28+
const toggle = () => setModal(!modal)
2229
const myActions = []
2330
const options = []
2431
const userAction = {}
2532
const pageSize = localStorage.getItem('paggingSize') || 10
2633
useEffect(() => {
27-
buildPayload(userAction, 'PERMISSIONS', options)
28-
dispatch(getPermissions(userAction))
34+
doFetchList()
2935
}, [])
3036

31-
if (hasPermission(permissions, PERMISSION_READ)) {
32-
myActions.push((aRow) => ({
33-
icon: 'visibility',
34-
iconProps: {
35-
color: 'primary',
36-
id: 'viewRole' + aRow.inum,
37-
},
38-
tooltip: `${t('messages.view_role_details')}`,
39-
onClick: (e, v) => handleGoToPermissionEditPage(v, true),
40-
disabled: false,
41-
}))
42-
}
43-
44-
if (hasPermission(permissions, PERMISSION_WRITE)) {
45-
myActions.push((rowD) => ({
46-
icon: 'edit',
47-
iconProps: {
48-
color: 'primary',
49-
id: 'editRole' + rowD.inum,
50-
},
51-
tooltip: `${t('messages.edit_role')}`,
52-
onClick: (e, entry) => handleGoToPermissionEditPage(entry, false),
53-
disabled: false,
54-
}))
55-
}
5637
if (hasPermission(permissions, PERMISSION_WRITE)) {
5738
myActions.push({
5839
icon: 'add',
59-
tooltip: `${t('messages.add_role')}`,
40+
tooltip: `${t('messages.add_permission')}`,
6041
iconProps: { color: 'primary' },
6142
isFreeAction: true,
62-
onClick: () => handleGoToPermissionAddPage(),
43+
onClick: () => handleAddNewPermission(),
6344
})
6445
}
6546

47+
function handleAddNewPermission() {
48+
toggle()
49+
}
50+
function doFetchList() {
51+
buildPayload(userAction, 'PERMISSIONS', options)
52+
dispatch(getPermissions(userAction))
53+
}
54+
function onAddConfirmed(roleData) {
55+
buildPayload(userAction, 'message', roleData)
56+
dispatch(addPermission(userAction))
57+
toggle()
58+
doFetchList()
59+
}
6660
return (
6761
<Card>
6862
<GluuRibbon title={t('titles.roles')} fromLeft />
@@ -78,12 +72,13 @@ function UiPermListPage({ apiPerms, permissions, loading, dispatch }) {
7872
{
7973
title: `${t('fields.name')}`,
8074
field: 'permission',
75+
editable: false,
8176
width: '50%',
8277
render: (rowData) => (
8378
<Badge color="info">{rowData.permission}</Badge>
8479
),
8580
},
86-
//{ title: `${t('fields.description')}`, field: 'description' },
81+
{ title: `${t('fields.description')}`, field: 'description' },
8782
]}
8883
data={apiPerms}
8984
isLoading={loading || false}
@@ -103,6 +98,22 @@ function UiPermListPage({ apiPerms, permissions, loading, dispatch }) {
10398
detailPanel={(rowD) => {
10499
return <UiPermDetailPage row={rowD} />
105100
}}
101+
editable={{
102+
onRowUpdate: (newData, oldData) =>
103+
new Promise((resolve, reject) => {
104+
buildPayload(userAction, 'Edit permision', newData)
105+
dispatch(editPermission(userAction))
106+
resolve()
107+
doFetchList()
108+
}),
109+
onRowDelete: (oldData) =>
110+
new Promise((resolve, reject) => {
111+
buildPayload(userAction, 'Remove permission', oldData)
112+
dispatch(deletePermission(userAction))
113+
resolve()
114+
doFetchList()
115+
}),
116+
}}
106117
/>
107118
</GluuViewWrapper>
108119
</CardBody>

plugins/admin/components/Roles/UiRoleListPage.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ function UiRoleListPage({ apiRoles, permissions, loading, dispatch }) {
2929
const toggle = () => setModal(!modal)
3030
const myActions = []
3131
const options = []
32-
const item = {}
3332
const userAction = {}
3433
const pageSize = localStorage.getItem('paggingSize') || 10
3534
useEffect(() => {
@@ -103,15 +102,15 @@ function UiRoleListPage({ apiRoles, permissions, loading, dispatch }) {
103102
new Promise((resolve, reject) => {
104103
buildPayload(userAction, 'Edit role', newData)
105104
dispatch(editRole(userAction))
106-
doFetchList()
107105
resolve()
106+
doFetchList()
108107
}),
109108
onRowDelete: (oldData) =>
110109
new Promise((resolve, reject) => {
111110
buildPayload(userAction, 'remove role', oldData)
112111
dispatch(deleteRole(userAction))
113-
doFetchList()
114112
resolve()
113+
doFetchList()
115114
}),
116115
}}
117116
/>
+39-39
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
export const roles = [
2-
{
3-
role: 'api-admin',
4-
description:
5-
'This role allows a user to access all list and search features available. Not possible for this role to perform edition nor deletion',
6-
scopes: [
7-
'https://jans.io/oauth/config/attributes.readonly',
8-
'https://jans.io/oauth/config/acrs.readonly',
9-
],
10-
},
11-
{
12-
role: 'api-viewer',
13-
description:
14-
'This role allows a user to perform all possible actions on api objects',
15-
scopes: [
16-
'https://jans.io/oauth/config/attributes.readonly',
17-
'https://jans.io/oauth/config/acrs.readonly',
18-
],
19-
},
20-
{
21-
role: 'api-editor',
22-
description:
23-
'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',
24-
scopes: [
25-
'https://jans.io/oauth/config/attributes.readonly',
26-
'https://jans.io/oauth/config/acrs.readonly',
27-
],
28-
},
29-
{
30-
role: 'api-manager',
31-
description:
32-
'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.',
33-
scopes: [
34-
'https://jans.io/oauth/config/attributes.readonly',
35-
'https://jans.io/oauth/config/acrs.readonly',
36-
],
37-
},
38-
]
39-
40-
export default roles
2+
{
3+
role: 'api-admin',
4+
description:
5+
'This role allows a user to access all list and search features available. Not possible for this role to perform edition nor deletion',
6+
scopes: [
7+
'https://jans.io/oauth/config/attributes.readonly',
8+
'https://jans.io/oauth/config/acrs.readonly',
9+
],
10+
},
11+
{
12+
role: 'api-viewer',
13+
description:
14+
'This role allows a user to perform all possible actions on api objects',
15+
scopes: [
16+
'https://jans.io/oauth/config/attributes.readonly',
17+
'https://jans.io/oauth/config/acrs.readonly',
18+
],
19+
},
20+
{
21+
role: 'api-editor',
22+
description:
23+
'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',
24+
scopes: [
25+
'https://jans.io/oauth/config/attributes.readonly',
26+
'https://jans.io/oauth/config/acrs.readonly',
27+
],
28+
},
29+
{
30+
role: 'api-manager',
31+
description:
32+
'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.',
33+
scopes: [
34+
'https://jans.io/oauth/config/attributes.readonly',
35+
'https://jans.io/oauth/config/acrs.readonly',
36+
],
37+
},
38+
]
39+
40+
export default roles

plugins/admin/redux/api/PermissionApi.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,35 @@ export default class PermissionApi {
1010
})
1111
})
1212
}
13-
getPermission = (options) => {
14-
return new Promise((resolve, reject) => {
15-
console.log('============= get single permission')
16-
})
17-
}
1813

1914
addPermission = (data) => {
15+
const options = {}
16+
options['adminPermission'] = data
2017
return new Promise((resolve, reject) => {
2118
console.log('============= add permission')
19+
this.api.addAdminuiPermission(options, (error, data) => {
20+
this.handleResponse(error, reject, resolve, data)
21+
})
2222
})
2323
}
2424

2525
editPermission = (data) => {
26+
const options = {}
27+
options['adminPermission'] = data
2628
return new Promise((resolve, reject) => {
2729
console.log('=============edit permission')
30+
this.api.editAdminuiPermission(options, (error, data) => {
31+
this.handleResponse(error, reject, resolve, data)
32+
})
2833
})
2934
}
30-
31-
deletePermission = async (inum) => {
35+
permission
36+
deletePermission = async (data) => {
3237
return new Promise((resolve, reject) => {
3338
console.log('=============delete permission')
39+
this.api.deleteAdminuiPermission(data.role, (error, data) => {
40+
this.handleResponse(error, reject, resolve, data)
41+
})
3442
})
3543
}
3644

0 commit comments

Comments
 (0)