[7.17] Fix upgrade assistant warning for optional roles and roleTemplate properties (#179818) (#180467)

# Backport

This will backport the following commits from `main` to `7.17`:
- [Fix upgrade assistant warning for optional roles and roleTemplate
properties (#179818)](https://github.com/elastic/kibana/pull/179818)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)
This commit is contained in:
Sid 2024-04-10 17:45:38 +02:00 committed by GitHub
parent c97059012a
commit 261bb8eda3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

View file

@ -202,8 +202,11 @@ async function getRoleMappingsDeprecations(
const roleMappingsWithReportingRole: string[] = Object.entries(roleMappings).reduce(
(roleSet, current) => {
const [roleName, role] = current;
const foundMapping = role.roles.find((roll) => deprecatedRoles.includes(roll));
return foundMapping ? [...roleSet, `${roleName}[${foundMapping}]`] : roleSet;
const foundMapping = role.roles?.find((roll) => deprecatedRoles.includes(roll));
if (foundMapping) {
roleSet.push(`${roleName}[${foundMapping}]`);
}
return roleSet;
},
[] as string[]
);

View file

@ -160,7 +160,7 @@ async function getRoleMappingsDeprecations(
}
const roleMappingsWithKibanaUserRole = Object.entries(roleMappings)
.filter(([, roleMapping]) => roleMapping.roles.includes(KIBANA_USER_ROLE_NAME))
.filter(([, roleMapping]) => roleMapping.roles?.includes(KIBANA_USER_ROLE_NAME))
.map(([mappingName]) => mappingName);
if (roleMappingsWithKibanaUserRole.length === 0) {
return [];

View file

@ -103,7 +103,7 @@ export function defineKibanaUserRoleDeprecationRoutes({ router, logger }: RouteD
}
const roleMappingsWithKibanaUserRole = Object.entries(roleMappings).filter(([, mapping]) =>
mapping.roles.includes(KIBANA_USER_ROLE_NAME)
mapping.roles?.includes(KIBANA_USER_ROLE_NAME)
);
if (roleMappingsWithKibanaUserRole.length === 0) {