Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init GroupPermissionGrid and RolePermissionGrid #151

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion assets/fallbackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var shogunApplicationConfig = {
'Application',
'Layer',
'User',
'Group'
'Group',
'Role'
],
dashboard: {
news: {
Expand Down
128 changes: 128 additions & 0 deletions assets/formconfigs/role.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"i18n": {
"de": {
"entityName": "Rolle",
"navigationTitle": "Rollen",
"labelId": "ID",
"labelEstabl": "Erstellt am",
"labelEdit": "Zuletzt editiert am",
"labelKey": "Keycloak ID",
"labelKeyProvDetail": "Keycloak Details",
"titleId": "ID",
"titleKeyId": "Keycloak ID",
"roleDoesNotExistTitle": "Die Rolle existiert nicht in Keycloak",
"titleRolename": "Rollenname",
"titleLink": "Link zur Rolle",
"titleOpen": "Öffne Rolle in Keycloak"
},
"en": {
"entityName": "Role",
"navigationTitle": "Roles",
"labelId": "ID",
"labelEstabl": "Created at",
"labelEdit": "Last edited on",
"labelKey": "Keycloak ID",
"labelKeyProvDetail": "Keycloak details",
"titleId": "ID",
"titleKeyId": "Keycloak ID",
"roleDoesNotExistTitle": "Role does not exist in Keycloak",
"titleRolename": "Role name",
"titleLink": "Link to role",
"titleOpen": "Open role in Keycloak"
}
},
"endpoint": "/roles",
"entityType": "role",
"entityName": "#i18n.entityName",
"navigationTitle": "#i18n.navigationTitle",
"subTitle": "",
"formConfig": {
"name": "role",
"fields": [
{
"dataType": "number",
"dataField": "id",
"readOnly": true,
"label": "#i18n.labelId"
},
{
"dataField": "created",
"dataType": "date",
"readOnly": "true",
"component": "DateField",
"label": "#i18n.labelEstabl",
"fieldProps": {
"dateFormat": "DD.MM.YYYY HH:mm"
}
},
{
"dataField": "modified",
"dataType": "date",
"readOnly": "true",
"label": "#i18n.labelEdit",
"component": "DateField",
"fieldProps": {
"dateFormat": "DD.MM.YYYY HH:mm"
}
},
{
"dataType": "string",
"dataField": "authProviderId",
"label": "#i18n.labelKey"
},
{
"component": "JSONEditor",
"dataField": "providerDetails",
"label": "#i18n.labelKeyProvDetail",
"fieldProps": {}
}
]
},
"tableConfig": {
"columnDefinition": [
{
"title": "#i18n.titleId",
"dataIndex": "id",
"sortConfig": {
"isSortable": true
}
},
{
"title": "#i18n.titleRolename",
"dataIndex": ["providerDetails", "name"],
"key": "name",
"sortConfig": {
"isSortable": true
},
"filterConfig": {
"isFilterable": true
}
},
{
"title": "#i18n.titleKeyId",
"dataIndex": "authProviderId",
"key": "authProviderId",
"cellRenderComponentName": "VerifyProviderDetailsCell",
"cellRenderComponentProps": {
"title": "#i18n.roleDoesNotExistTitle"
},
"sortConfig": {
"isSortable": true
},
"filterConfig": {
"isFilterable": true
}
},
{
"title": "#i18n.titleLink",
"dataIndex": "authProviderId",
"key": "link",
"cellRenderComponentName": "LinkCell",
"cellRenderComponentProps": {
"title": "#i18n.titleOpen",
"template": "/auth/admin/master/console/#/SHOGun/roles/{}/details"
}
}
]
}
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@monaco-editor/react": "4.6.0",
"@terrestris/base-util": "2.0.0",
"@terrestris/ol-util": "19.0.0",
"@terrestris/shogun-util": "8.3.2",
"@terrestris/shogun-util": "8.4.0",
"@uiw/react-md-editor": "4.0.4",
"antd": "5.17.2",
"i18next": "23.11.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import GroupPermissionGrid from './GroupPermissionGrid';

describe('<GroupPermissionGrid />', () => {

it('is defined', () => {
expect(GroupPermissionGrid).not.toBeUndefined();
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React, {
useCallback
} from 'react';

import {
useTranslation
} from 'react-i18next';

import BaseEntity from '@terrestris/shogun-util/dist/model/BaseEntity';
import PermissionCollectionType from '@terrestris/shogun-util/dist/model/enum/PermissionCollectionType';
import Group from '@terrestris/shogun-util/dist/model/Group';
import GroupInstancePermission from '@terrestris/shogun-util/dist/model/security/GroupInstancePermission';
import GenericEntityService from '@terrestris/shogun-util/dist/service/GenericEntityService';
import { PageOpts } from '@terrestris/shogun-util/dist/service/GenericService';

import useSHOGunAPIClient from '../../../../Hooks/useSHOGunAPIClient';
import InstancePermissionGrid, {
DataType,
InstancePermissionGridProps
} from '../InstancePermissionGrid/InstancePermissionGrid';

export interface GroupPermissionGridProps extends Omit<InstancePermissionGridProps<GroupInstancePermission>,
'getInstancePermissions' | 'setInstancePermission' | 'deleteInstancePermission' | 'toDataType' |
'nameColumnDefinition' | 'getReferences' | 'toTag' | 'modalProps'> { };

const GroupPermissionGrid: React.FC<GroupPermissionGridProps> = ({
entityType,
...passThroughProps
}) => {

const { t } = useTranslation();
const client = useSHOGunAPIClient();

const service = useCallback(() => {
return (client?.[entityType] as () => GenericEntityService<BaseEntity>)();
}, [client, entityType]);

const getGroupInstancePermissions = async (id: number) => {
return await service()?.getGroupInstancePermissions(id);
};

const setGroupInstancePermission = async (id: number, referenceId: number, permission: PermissionCollectionType) => {
await service()?.setGroupInstancePermission(id, referenceId, permission);
};

const deleteGroupInstancePermission = async (id: number, referenceId: number) => {
await service()?.deleteGroupInstancePermission(id, referenceId);
};

const getGroups = async (pageOpts?: PageOpts) => {
return await client?.group().findAll(pageOpts);
};

const toGroupDataType = (permission: GroupInstancePermission): DataType<Group> => {
return {
key: permission.group?.id,
reference: permission.group,
name: permission.group?.providerDetails?.name,
permission: permission.permission?.name
};
};

const toTag = (group: Group) => {
return {
value: group.id,
filterValues: [
group.id,
group.authProviderId,
group.providerDetails?.name
],
label: (
<span>{group.providerDetails?.name}</span>
)
};
};

const colDefinition = () => {
return {
sorter: (a: DataType<Group>, b: DataType<Group>) => {
const aName = a.reference?.providerDetails?.name;
const bName = b.reference?.providerDetails?.name;

if (!aName || !bName) {
return 0;
}

return bName.localeCompare(aName);
}
};
};

return (
<InstancePermissionGrid
entityType={entityType}
getInstancePermissions={getGroupInstancePermissions}
setInstancePermission={setGroupInstancePermission}
deleteInstancePermission={deleteGroupInstancePermission}
toDataType={toGroupDataType}
nameColumnDefinition={colDefinition()}
modalProps={{
toTag: toTag,
getReferences: getGroups,
setInstancePermission: setGroupInstancePermission,
descriptionText: t('GroupPermissionGrid.modal.description'),
referenceLabelText: t('GroupPermissionGrid.modal.referenceSelectLabel'),
referenceExtraText: t('GroupPermissionGrid.modal.referenceSelectExtra'),
referenceSelectPlaceholderText: t('GroupPermissionGrid.modal.referenceSelectPlaceholder'),
permissionSelectLabel: t('GroupPermissionGrid.modal.permissionSelectLabel'),
permissionSelectExtra: t('GroupPermissionGrid.modal.permissionSelectExtra'),
saveErrorMsg: (placeholder: string) => {
return t('GroupPermissionGrid.modal.saveErrorMsg', {
referenceIds: placeholder
});
}
}}
{...passThroughProps}
/>
);
};

export default GroupPermissionGrid;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.permission-grid {
.operation-column {
.instance-permission-grid {
.ant-table-cell.operation-column {
font-size: 1.5em;
text-align: center;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import InstancePermissionGrid from './InstancePermissionGrid';

describe('<InstancePermissionGrid />', () => {

it('is defined', () => {
expect(InstancePermissionGrid).not.toBeUndefined();
});

});
Loading