Skip to content

Commit

Permalink
Let create/edit client role w/ fine-grained auth.
Browse files Browse the repository at this point in the history
Fixes keycloak#31537

Signed-off-by: Stan Silvert <[email protected]>
  • Loading branch information
ssilvert committed Aug 19, 2024
1 parent 74fec50 commit 21d0978
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/apps/admin-ui/src/clients/routes/NewRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const NewRoleRoute: AppRouteObject = {
element: <CreateClientRole />,
breadcrumb: (t) => t("createRole"),
handle: {
access: "manage-clients",
access: "query-clients",
},
};

Expand Down
1 change: 1 addition & 0 deletions js/apps/admin-ui/src/components/role-form/RoleForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const RoleForm = ({
onSubmit={handleSubmit(onSubmit)}
role={role}
className="pf-v5-u-mt-lg"
fineGrainedAccess={true} // We would never want to show this form in read-only mode
>
<TextControl
name="name"
Expand Down
11 changes: 11 additions & 0 deletions js/apps/admin-ui/src/realm-roles/RealmRoleTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export default function RealmRoleTabs() {
"manage-authorization",
);

const [canManageClientRole, setCanManageClientRole] = useState(false);

const [open, setOpen] = useState(false);
const convert = (role: RoleRepresentation) => {
const { attributes, ...rest } = role;
Expand Down Expand Up @@ -116,6 +118,14 @@ export default function RealmRoleTabs() {
[key],
);

useFetch(
async () => adminClient.clients.findOne({ id: clientId }),
(client) => {
if (clientId) setCanManageClientRole(client?.access?.manage as boolean);
},
[],
);

const onSubmit: SubmitHandler<AttributeForm> = async (formValues) => {
try {
const { attributes, ...rest } = formValues;
Expand Down Expand Up @@ -312,6 +322,7 @@ export default function RealmRoleTabs() {
<AttributesForm
form={form}
save={onSubmit}
fineGrainedAccess={canManageClientRole}
reset={() =>
setValue("attributes", attributes, { shouldDirty: false })
}
Expand Down

0 comments on commit 21d0978

Please sign in to comment.