Merge pull request #1726 from automatisch/AUT-839
refactor: rewrite usePermissionCatalog with RQ
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
import permissionCatalog from '../../helpers/permission-catalog.ee.js';
|
|
||||||
|
|
||||||
const getPermissionCatalog = async () => {
|
|
||||||
return permissionCatalog;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getPermissionCatalog;
|
|
@@ -9,7 +9,6 @@ import getDynamicFields from './queries/get-dynamic-fields.js';
|
|||||||
import getFlow from './queries/get-flow.js';
|
import getFlow from './queries/get-flow.js';
|
||||||
import getFlows from './queries/get-flows.js';
|
import getFlows from './queries/get-flows.js';
|
||||||
import getNotifications from './queries/get-notifications.js';
|
import getNotifications from './queries/get-notifications.js';
|
||||||
import getPermissionCatalog from './queries/get-permission-catalog.ee.js';
|
|
||||||
import getSamlAuthProviderRoleMappings from './queries/get-saml-auth-provider-role-mappings.ee.js';
|
import getSamlAuthProviderRoleMappings from './queries/get-saml-auth-provider-role-mappings.ee.js';
|
||||||
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
import getStepWithTestExecutions from './queries/get-step-with-test-executions.js';
|
||||||
import getUsers from './queries/get-users.js';
|
import getUsers from './queries/get-users.js';
|
||||||
@@ -27,7 +26,6 @@ const queryResolvers = {
|
|||||||
getFlow,
|
getFlow,
|
||||||
getFlows,
|
getFlows,
|
||||||
getNotifications,
|
getNotifications,
|
||||||
getPermissionCatalog,
|
|
||||||
getSamlAuthProviderRoleMappings,
|
getSamlAuthProviderRoleMappings,
|
||||||
getStepWithTestExecutions,
|
getStepWithTestExecutions,
|
||||||
getUsers,
|
getUsers,
|
||||||
|
@@ -25,7 +25,6 @@ type Query {
|
|||||||
): [SubstepArgument]
|
): [SubstepArgument]
|
||||||
getBillingAndUsage: GetBillingAndUsage
|
getBillingAndUsage: GetBillingAndUsage
|
||||||
getConfig(keys: [String]): JSONObject
|
getConfig(keys: [String]): JSONObject
|
||||||
getPermissionCatalog: PermissionCatalog
|
|
||||||
getNotifications: [Notification]
|
getNotifications: [Notification]
|
||||||
getSamlAuthProviderRoleMappings(id: String!): [SamlAuthProvidersRoleMapping]
|
getSamlAuthProviderRoleMappings(id: String!): [SamlAuthProvidersRoleMapping]
|
||||||
getUsers(limit: Int!, offset: Int!): UserConnection
|
getUsers(limit: Int!, offset: Int!): UserConnection
|
||||||
@@ -643,12 +642,6 @@ type Permission {
|
|||||||
conditions: [String]
|
conditions: [String]
|
||||||
}
|
}
|
||||||
|
|
||||||
type PermissionCatalog {
|
|
||||||
actions: [Action]
|
|
||||||
subjects: [Subject]
|
|
||||||
conditions: [Condition]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Action {
|
type Action {
|
||||||
label: String
|
label: String
|
||||||
key: String
|
key: String
|
||||||
|
@@ -10,18 +10,24 @@ import TableHead from '@mui/material/TableHead';
|
|||||||
import TableRow from '@mui/material/TableRow';
|
import TableRow from '@mui/material/TableRow';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import ControlledCheckbox from 'components/ControlledCheckbox';
|
import ControlledCheckbox from 'components/ControlledCheckbox';
|
||||||
import usePermissionCatalog from 'hooks/usePermissionCatalog.ee';
|
import usePermissionCatalog from 'hooks/usePermissionCatalog.ee';
|
||||||
import PermissionSettings from './PermissionSettings.ee';
|
import PermissionSettings from './PermissionSettings.ee';
|
||||||
import PermissionCatalogFieldLoader from './PermissionCatalogFieldLoader';
|
import PermissionCatalogFieldLoader from './PermissionCatalogFieldLoader';
|
||||||
|
|
||||||
const PermissionCatalogField = ({
|
const PermissionCatalogField = ({
|
||||||
name = 'permissions',
|
name = 'permissions',
|
||||||
disabled = false,
|
disabled = false,
|
||||||
defaultChecked = false,
|
defaultChecked = false,
|
||||||
}) => {
|
}) => {
|
||||||
const { permissionCatalog, loading } = usePermissionCatalog();
|
const { data, isLoading: isPermissionCatalogLoading } =
|
||||||
|
usePermissionCatalog();
|
||||||
|
const permissionCatalog = data?.data;
|
||||||
const [dialogName, setDialogName] = React.useState();
|
const [dialogName, setDialogName] = React.useState();
|
||||||
if (loading) return <PermissionCatalogFieldLoader />;
|
|
||||||
|
if (isPermissionCatalogLoading) return <PermissionCatalogFieldLoader />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
<Table>
|
<Table>
|
||||||
@@ -29,7 +35,7 @@ const PermissionCatalogField = ({
|
|||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell component="th" />
|
<TableCell component="th" />
|
||||||
|
|
||||||
{permissionCatalog.actions.map((action) => (
|
{permissionCatalog?.actions.map((action) => (
|
||||||
<TableCell component="th" key={action.key}>
|
<TableCell component="th" key={action.key}>
|
||||||
<Typography
|
<Typography
|
||||||
variant="subtitle1"
|
variant="subtitle1"
|
||||||
@@ -48,7 +54,7 @@ const PermissionCatalogField = ({
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{permissionCatalog.subjects.map((subject) => (
|
{permissionCatalog?.subjects.map((subject) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={subject.key}
|
key={subject.key}
|
||||||
sx={{ '&:last-child td': { border: 0 } }}
|
sx={{ '&:last-child td': { border: 0 } }}
|
||||||
@@ -58,7 +64,7 @@ const PermissionCatalogField = ({
|
|||||||
<Typography variant="subtitle2">{subject.label}</Typography>
|
<Typography variant="subtitle2">{subject.label}</Typography>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
{permissionCatalog.actions.map((action) => (
|
{permissionCatalog?.actions.map((action) => (
|
||||||
<TableCell key={`${subject.key}.${action.key}`} align="center">
|
<TableCell key={`${subject.key}.${action.key}`} align="center">
|
||||||
<Typography variant="subtitle2">
|
<Typography variant="subtitle2">
|
||||||
{action.subjects.includes(subject.key) && (
|
{action.subjects.includes(subject.key) && (
|
||||||
@@ -91,8 +97,8 @@ const PermissionCatalogField = ({
|
|||||||
onClose={() => setDialogName('')}
|
onClose={() => setDialogName('')}
|
||||||
fieldPrefix={`${name}.${subject.key}`}
|
fieldPrefix={`${name}.${subject.key}`}
|
||||||
subject={subject.key}
|
subject={subject.key}
|
||||||
actions={permissionCatalog.actions}
|
actions={permissionCatalog?.actions}
|
||||||
conditions={permissionCatalog.conditions}
|
conditions={permissionCatalog?.conditions}
|
||||||
defaultChecked={defaultChecked}
|
defaultChecked={defaultChecked}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
@@ -1,20 +0,0 @@
|
|||||||
import { gql } from '@apollo/client';
|
|
||||||
export const GET_PERMISSION_CATALOG = gql`
|
|
||||||
query GetPermissionCatalog {
|
|
||||||
getPermissionCatalog {
|
|
||||||
subjects {
|
|
||||||
key
|
|
||||||
label
|
|
||||||
}
|
|
||||||
conditions {
|
|
||||||
key
|
|
||||||
label
|
|
||||||
}
|
|
||||||
actions {
|
|
||||||
label
|
|
||||||
key
|
|
||||||
subjects
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
@@ -1,6 +1,18 @@
|
|||||||
import { useQuery } from '@apollo/client';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { GET_PERMISSION_CATALOG } from 'graphql/queries/get-permission-catalog.ee';
|
|
||||||
|
import api from 'helpers/api';
|
||||||
|
|
||||||
export default function usePermissionCatalog() {
|
export default function usePermissionCatalog() {
|
||||||
const { data, loading } = useQuery(GET_PERMISSION_CATALOG);
|
const query = useQuery({
|
||||||
return { permissionCatalog: data?.getPermissionCatalog, loading };
|
queryKey: ['permissionCatalog'],
|
||||||
|
queryFn: async ({ signal }) => {
|
||||||
|
const { data } = await api.get('/v1/admin/permissions/catalog', {
|
||||||
|
signal,
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user