Let create/edit client role w/ fine-grained auth. (#32249)

Fixes #31537

Signed-off-by: Stan Silvert <ssilvert@redhat.com>
This commit is contained in:
Stan Silvert 2024-08-20 05:28:08 -04:00 committed by GitHub
parent eeae50fb43
commit 85a0fa389c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View file

@ -12,7 +12,7 @@ export const NewRoleRoute: AppRouteObject = {
element: <CreateClientRole />,
breadcrumb: (t) => t("createRole"),
handle: {
access: "manage-clients",
access: "query-clients",
},
};

View file

@ -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"

View file

@ -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;
@ -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;
@ -312,6 +322,7 @@ export default function RealmRoleTabs() {
<AttributesForm
form={form}
save={onSubmit}
fineGrainedAccess={canManageClientRole}
reset={() =>
setValue("attributes", attributes, { shouldDirty: false })
}