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 />, element: <CreateClientRole />,
breadcrumb: (t) => t("createRole"), breadcrumb: (t) => t("createRole"),
handle: { handle: {
access: "manage-clients", access: "query-clients",
}, },
}; };

View file

@ -50,6 +50,7 @@ export const RoleForm = ({
onSubmit={handleSubmit(onSubmit)} onSubmit={handleSubmit(onSubmit)}
role={role} role={role}
className="pf-v5-u-mt-lg" className="pf-v5-u-mt-lg"
fineGrainedAccess={true} // We would never want to show this form in read-only mode
> >
<TextControl <TextControl
name="name" name="name"

View file

@ -80,6 +80,8 @@ export default function RealmRoleTabs() {
"manage-authorization", "manage-authorization",
); );
const [canManageClientRole, setCanManageClientRole] = useState(false);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const convert = (role: RoleRepresentation) => { const convert = (role: RoleRepresentation) => {
const { attributes, ...rest } = role; const { attributes, ...rest } = role;
@ -116,6 +118,14 @@ export default function RealmRoleTabs() {
[key], [key],
); );
useFetch(
async () => adminClient.clients.findOne({ id: clientId }),
(client) => {
if (clientId) setCanManageClientRole(client?.access?.manage as boolean);
},
[],
);
const onSubmit: SubmitHandler<AttributeForm> = async (formValues) => { const onSubmit: SubmitHandler<AttributeForm> = async (formValues) => {
try { try {
const { attributes, ...rest } = formValues; const { attributes, ...rest } = formValues;
@ -312,6 +322,7 @@ export default function RealmRoleTabs() {
<AttributesForm <AttributesForm
form={form} form={form}
save={onSubmit} save={onSubmit}
fineGrainedAccess={canManageClientRole}
reset={() => reset={() =>
setValue("attributes", attributes, { shouldDirty: false }) setValue("attributes", attributes, { shouldDirty: false })
} }