AccessControl: Include hidden roles in service account role display (#112924)

* AccessControl: Include hidden roles in service account role fetches

Add includeHidden=true parameter to role API calls to ensure service accounts
with hidden roles assigned properly display those roles in the UI.

Previously, service accounts with only hidden roles would appear to have no
roles assigned in the UI, even though the API showed they had roles when
queried with includeHidden=true.

This change affects both:
- Bulk role fetching for the service accounts list
- Individual user role fetching used by the role picker

* format
This commit is contained in:
Jo
2025-10-24 14:04:13 +02:00
committed by GitHub
parent e48eaa567e
commit 8b12bbcc55
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ export const fetchRoleOptions = async (orgId?: number): Promise<Role[]> => {
};
export const fetchUserRoles = async (userId: number, orgId?: number): Promise<Role[]> => {
let userRolesUrl = `/api/access-control/users/${userId}/roles?includeMapped=true`;
let userRolesUrl = `/api/access-control/users/${userId}/roles?includeMapped=true&includeHidden=true`;
if (orgId) {
userRolesUrl += `&targetOrgId=${orgId}`;
}
@@ -63,7 +63,10 @@ export function fetchServiceAccounts(
dispatch(rolesFetchBegin());
const orgId = contextSrv.user.orgId;
const userIds = result?.serviceAccounts.map((u: ServiceAccountDTO) => u.id);
const roles = await getBackendSrv().post(`/api/access-control/users/roles/search`, { userIds, orgId });
const roles = await getBackendSrv().post(`/api/access-control/users/roles/search?includeHidden=true`, {
userIds,
orgId,
});
result.serviceAccounts.forEach((u: ServiceAccountDTO) => {
u.roles = roles ? roles[u.id] || [] : [];
});