Skip to content

Commit 63b2314

Browse files
authored
Merge pull request #2053 from redpanda-data/create-acl-redirect
UI: allow redirects to CreateACL page to include principal information
2 parents c28bc69 + db02331 commit 63b2314

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

frontend/src/components/pages/acls/new-acl/acl-create-page.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import { useToast } from '@redpanda-data/ui';
1313
import {
1414
convertRulesToCreateACLRequests,
1515
handleResponses,
16+
type PrincipalType,
17+
PrincipalTypeRedpandaRole,
1618
PrincipalTypeUser,
1719
parsePrincipal,
1820
type Rule,
1921
} from 'components/pages/acls/new-acl/acl.model';
2022
import CreateACL from 'components/pages/acls/new-acl/create-acl';
2123
import { useEffect } from 'react';
22-
import { useNavigate } from 'react-router-dom';
24+
import { useNavigate, useSearchParams } from 'react-router-dom';
2325
import { uiState } from 'state/ui-state';
2426

2527
import { useCreateAcls } from '../../../../react-query/api/acl';
@@ -28,6 +30,20 @@ import PageContent from '../../../misc/page-content';
2830
const AclCreatePage = () => {
2931
const toast = useToast();
3032
const navigate = useNavigate();
33+
const [searchParams] = useSearchParams();
34+
35+
const principalTypeParam = searchParams.get('principalType')?.toLowerCase();
36+
const principalName = searchParams.get('principalName');
37+
38+
const principalTypeMap: Record<string, PrincipalType> = {
39+
redpandarole: PrincipalTypeRedpandaRole,
40+
user: PrincipalTypeUser,
41+
};
42+
43+
const principalType = principalTypeParam ? principalTypeMap[principalTypeParam] : undefined;
44+
45+
const sharedConfig =
46+
principalName && principalType ? { principal: `${principalType}${principalName}`, host: '*' } : undefined;
3147

3248
useEffect(() => {
3349
uiState.pageBreadcrumbs = [
@@ -53,7 +69,8 @@ const AclCreatePage = () => {
5369
edit={false}
5470
onCancel={() => navigate('/security/acls')}
5571
onSubmit={createAclMutation}
56-
principalType={PrincipalTypeUser}
72+
principalType={principalType}
73+
sharedConfig={sharedConfig}
5774
/>
5875
</PageContent>
5976
);

frontend/src/components/pages/acls/user-create.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ const CreateUserConfirmationModal = observer((p: { state: CreateUserModalState;
363363

364364
<Flex gap={4} mt={8}>
365365
<Button onClick={p.closeModal}>Done</Button>
366-
<Button as={ReactRouterLink} to="/security/acls" variant="link">
366+
<Button
367+
as={ReactRouterLink}
368+
to={`/security/acls/create?principalType=User&principalName=${encodeURIComponent(p.state.username)}`}
369+
variant="link"
370+
>
367371
Create ACLs
368372
</Button>
369373
</Flex>

0 commit comments

Comments
 (0)