From 2e58c5af7533dc727cfb13b5248a4e23b594cf3b Mon Sep 17 00:00:00 2001 From: Rohit0301 Date: Fri, 4 Dec 2026 13:03:36 +0530 Subject: [PATCH 1/3] Fixes #39766: Show the Admin role in user tables, as the Access tab does Admin is the isAdmin flag, not a role entity. The Access tab added it as a synthetic chip, but the user tables only read user.roles, so admins showed no role. One helper, getUserRoleRefs, now builds the list for the Access tab and every user table, with Admin first and rendered as text, not a link. --- .../Profile/components/RolesRow.tsx | 25 +++-------- .../tabs/members/MembersOnlineUsersPanel.tsx | 7 ++- .../tabs/members/MembersTeamDetail.utils.tsx | 7 ++- .../tabs/members/MembersUserColumns.tsx | 27 +++++++----- .../tabs/members/MembersUsersPanel.test.tsx | 15 +++++++ .../tabs/members/MembersUsersPanel.tsx | 7 ++- .../Profile/tabs/personas/PersonaUsersTab.tsx | 7 ++- .../ui/src/utils/Users.util.test.tsx | 31 ++++++++++++- .../resources/ui/src/utils/Users.util.tsx | 43 +++++++++---------- .../resources/ui/src/utils/UsersPureUtils.ts | 27 +++++++++++- 10 files changed, 133 insertions(+), 63 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx index edae3e32a585..631abc4654a4 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx @@ -19,15 +19,13 @@ import type { Key } from 'react-aria-components'; import { useTranslation } from 'react-i18next'; import { TERM_ADMIN } from '../../../../../constants/constants'; import { Role } from '../../../../../generated/entity/teams/role'; -import { - EntityReference, - User, -} from '../../../../../generated/entity/teams/user'; +import { User } from '../../../../../generated/entity/teams/user'; import { useAuth } from '../../../../../hooks/authHooks'; import { useProfileCopy } from '../../../../../hooks/discovery/personal-space/useUserProfile'; import { searchRoles } from '../../../../../rest/rolesAPIV1'; import { getEntityName } from '../../../../../utils/EntityNameUtils'; import { showErrorToast } from '../../../../../utils/ToastUtils'; +import { getUserRoleRefs } from '../../../../../utils/UsersPureUtils'; import ChipBadgeList from './ChipBadgeList'; import InlineEditCard from './InlineEditCard'; @@ -126,21 +124,10 @@ const RolesRow: React.FC = ({ ); }; - // Admin is stored as `isAdmin`, not as a role entity, so surface it as a - // synthetic chip — otherwise an admin-only user reads as "No roles assigned". - const roleChips = useMemo(() => { - const chips: EntityReference[] = [...(userData.roles ?? [])]; - if (userData.isAdmin) { - chips.push({ - id: TERM_ADMIN, - type: 'role', - name: t('label.admin-superuser'), - displayName: t('label.admin-superuser'), - }); - } - - return chips; - }, [userData.roles, userData.isAdmin, t]); + const roleChips = useMemo( + () => getUserRoleRefs(userData, t('label.admin-superuser')), + [userData, t] + ); return ( = () => { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx index 592f61862e4f..8c258199f131 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx @@ -25,7 +25,10 @@ import { Team, TeamType } from '../../../../../../generated/entity/teams/team'; import { User } from '../../../../../../generated/entity/teams/user'; import { EntityReference } from '../../../../../../generated/entity/type'; import { getEntityName } from '../../../../../../utils/EntityNameUtils'; -import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; +import { + getUserIdentifier, + getUserRoleRefs, +} from '../../../../../../utils/UsersPureUtils'; import RichTextEditorPreviewerV1 from '../../../../../common/RichTextEditor/RichTextEditorPreviewerV1'; import type { ColumnsType } from '../../../../../common/Table/Table.interface'; import type { MembersView } from './Members.types'; @@ -250,7 +253,7 @@ export const getUserColumns = ( ), diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUserColumns.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUserColumns.tsx index 38b76398e821..56cf4befebf4 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUserColumns.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUserColumns.tsx @@ -19,6 +19,7 @@ import { } from '@openmetadata/ui-core-components'; import { FC } from 'react'; import { useTranslation } from 'react-i18next'; +import { TERM_ADMIN } from '../../../../../../constants/constants'; import { usePermissionProvider } from '../../../../../../context/PermissionProvider/PermissionProvider'; import type { User } from '../../../../../../generated/entity/teams/user'; import type { EntityReference } from '../../../../../../generated/entity/type'; @@ -80,16 +81,22 @@ export const EntityLinksCell: FC<{ return <>{emptyLabel}; } - const renderItem = (item: EntityReference) => ( - - {getEntityName(item)} - - ); + // The synthetic Admin role has no role page to link to. + const renderItem = (item: EntityReference) => + item.id === TERM_ADMIN ? ( + + {getEntityName(item)} + + ) : ( + + {getEntityName(item)} + + ); return ( { }); }); + it('shows Admin in the roles column for an admin with no role entities', async () => { + mockGetUsers.mockResolvedValue({ + data: [{ ...usersPage({}).data[0], isAdmin: true, roles: [] }], + paging: { total: 1 }, + }); + renderComponent(); + + expect(await screen.findByTestId('role-link')).toHaveTextContent( + 'label.admin-superuser' + ); + expect( + screen.queryByText('label.no-entity{"entity":"label.role"}') + ).not.toBeInTheDocument(); + }); + it('shows the display name in the name column and the email beside it', async () => { renderComponent(); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx index 3ac67ecc422e..b0da85665ec7 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx @@ -77,7 +77,10 @@ import { useCursorPageJump, } from '../../../../../../hooks/paging/useCursorPageJump'; import { shouldShowPager } from '../../../../../../utils/PaginationUtils'; -import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; +import { + getUserIdentifier, + getUserRoleRefs, +} from '../../../../../../utils/UsersPureUtils'; import type { MembersUsersPanelProps } from './Members.types'; import { EntityLinksCell, UserNameCell } from './MembersUserColumns'; import { profileHash } from './profileHash.utils'; @@ -389,7 +392,7 @@ const MembersUsersPanel: React.FC = ({ diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx index 8da1b80b08e7..dac977439cf8 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx @@ -33,7 +33,10 @@ import { searchQuery } from '../../../../../../rest/searchAPI'; import { getEntityName } from '../../../../../../utils/EntityNameUtils'; import { getTermQuery } from '../../../../../../utils/SearchPureUtils'; import { showErrorToast } from '../../../../../../utils/ToastUtils'; -import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; +import { + getUserIdentifier, + getUserRoleRefs, +} from '../../../../../../utils/UsersPureUtils'; import NoDataPlaceholder from '../../../../../common/EmptyPlaceholder/NoDataPlaceholder'; import UserPopOverCard from '../../../../../common/PopOverCard/UserPopOverCard'; import { UserTeamSelectableList } from '../../../../../common/UserTeamSelectableList/UserTeamSelectableList.component'; @@ -162,7 +165,7 @@ const PersonaUsersTab = ({ case 'teams': return renderRefList(user.teams); case 'roles': - return renderRefList(user.roles); + return renderRefList(getUserRoleRefs(user, t('label.admin-superuser'))); case 'actions': return canEdit ? ( ({ getUserByName: jest.fn(), @@ -93,3 +98,27 @@ describe('User Utils -- isMaskedEmail', () => { expect(result).toBe(false); }); }); + +describe('User Utils -- getUserRoleRefs', () => { + const role = { id: 'r1', type: 'role', name: 'DataSteward' }; + + it('returns the role entities of a non-admin', () => { + expect(getUserRoleRefs({ roles: [role] }, 'Admin')).toEqual([role]); + expect(getUserRoleRefs({}, 'Admin')).toEqual([]); + }); + + it('adds Admin first for an admin, with or without role entities', () => { + const admin = { + id: TERM_ADMIN, + type: 'role', + name: 'Admin', + displayName: 'Admin', + }; + + expect(getUserRoleRefs({ isAdmin: true }, 'Admin')).toEqual([admin]); + expect(getUserRoleRefs({ isAdmin: true, roles: [role] }, 'Admin')).toEqual([ + admin, + role, + ]); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx index 684befe4ce40..21be1cac9b4e 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx @@ -25,13 +25,27 @@ import { Button as AriaButton } from 'react-aria-components'; import { Link } from 'react-router-dom'; import UserPopOverCard from '../components/common/PopOverCard/UserPopOverCard'; import { ColumnsType } from '../components/common/Table/Table.interface'; +import { TERM_ADMIN } from '../constants/constants'; import { EntityReference, User } from '../generated/entity/teams/user'; import { getEntityName } from './EntityNameUtils'; import { t } from './i18next/LocalUtil'; import { LIST_CAP } from './PermissionsUtils'; import { getRoleWithFqnPath, getTeamsWithFqnPath } from './RouterUtils'; import { getSettingsLink } from './SettingsModalLinkUtils'; -import { getUserIdentifier } from './UsersPureUtils'; +import { getUserIdentifier, getUserRoleRefs } from './UsersPureUtils'; + +// The synthetic Admin role has no role page to link to. +const renderRole = (role: EntityReference) => + role.id === TERM_ADMIN ? ( + {getEntityName(role)} + ) : ( + + {getEntityName(role)} + + ); export const userCellRenderer = (user: EntityReference | User) => { return user.name ? ( @@ -163,14 +177,15 @@ export const commonUserDetailColumns = ( dataIndex: 'roles', key: 'roles', render: (_, record) => { - const listLength = record.roles?.length ?? 0; + const roles = getUserRoleRefs(record, t('label.admin-superuser')); + const listLength = roles.length; const hasMore = listLength > LIST_CAP; if (isLoading) { return ; } - if (isUndefined(record.roles) || isEmpty(record.roles)) { + if (isEmpty(roles)) { return <>{t('label.no-entity', { entity: t('label.role') })}; } else { return ( @@ -182,16 +197,7 @@ export const commonUserDetailColumns = ( gap={1} itemClassName="layout-space-item" wrap="wrap"> - {record.roles.slice(0, LIST_CAP).map((role) => ( - - {getEntityName(role)} - - ))} + {roles.slice(0, LIST_CAP).map(renderRole)} {hasMore && ( - {record.roles.slice(LIST_CAP).map((role) => ( - - {getEntityName(role)} - - ))} + {roles.slice(LIST_CAP).map(renderRole)} diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts index ccd0e61d0efe..2b3c3692efb6 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts +++ b/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts @@ -14,9 +14,13 @@ import type { AxiosError } from 'axios'; import moment from 'moment'; import { HTTP_STATUS_CODE } from '../constants/Auth.constants'; -import { ERROR_MESSAGE, NO_DATA_PLACEHOLDER } from '../constants/constants'; +import { + ERROR_MESSAGE, + NO_DATA_PLACEHOLDER, + TERM_ADMIN, +} from '../constants/constants'; import { MASKED_EMAIL } from '../constants/User.constants'; -import type { User } from '../generated/entity/teams/user'; +import type { EntityReference, User } from '../generated/entity/teams/user'; import { getIsErrorMatch } from './APIUtils'; import { t } from './i18next/LocalUtil'; @@ -114,3 +118,22 @@ export const getUserFirstName = (user: { name: string; displayName?: string; }): string => (user.displayName?.trim() || user.name).split(/\s+/)[0]; + +// Admin is stored as `isAdmin`, not as a role entity, so it is surfaced as a +// synthetic role (id TERM_ADMIN) — first, so a list cap never hides it. +export const getUserRoleRefs = ( + user: Pick, + adminLabel: string +): EntityReference[] => [ + ...(user.isAdmin + ? [ + { + id: TERM_ADMIN, + type: 'role', + name: adminLabel, + displayName: adminLabel, + }, + ] + : []), + ...(user.roles ?? []), +]; From 93abd621dfe13c0a04523e9606c7ad2f79ddb6f0 Mon Sep 17 00:00:00 2001 From: Rohit0301 Date: Fri, 4 Dec 2026 14:32:41 +0530 Subject: [PATCH 2/3] Show Admin in the user hover card and the CSV bulk-edit user picker The hover card hid its Roles section when an admin had no role entities, and the bulk-edit user picker described admins by their first role or team. Both now read the role list from getUserRoleRefs, and formatUsersResponse keeps isAdmin from the search document. --- .../common/PopOverCard/UserRoles.component.tsx | 11 +++-------- .../components/common/PopOverCard/UserRoles.test.tsx | 9 +++++++++ .../src/main/resources/ui/src/utils/APIUtils.ts | 1 + .../resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx | 5 ++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx index 810a4560e414..f0bbcc6c8b99 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx @@ -15,14 +15,14 @@ import { User01 } from '@openmetadata/ui-core-components/icons'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { getEntityName } from '../../../utils/EntityNameUtils'; +import { getUserRoleRefs } from '../../../utils/UsersPureUtils'; import { UserRolesProps } from './UserPopOverCard.interface'; export const UserRoles = React.memo(({ user }: UserRolesProps) => { - const roles = user?.roles; - const isAdmin = user?.isAdmin; const { t } = useTranslation(); + const roles = getUserRoleRefs(user ?? {}, t('label.admin-superuser')); - return roles?.length ? ( + return roles.length ? (

@@ -32,11 +32,6 @@ export const UserRoles = React.memo(({ user }: UserRolesProps) => {

- {isAdmin && ( - - {t('label.admin-superuser')} - - )} {roles.map((role) => ( { expect(container).toBeEmptyDOMElement(); }); + it('should render the admin badge for an admin with no role entities', () => { + render( + + ); + + expect(screen.getByText('label.role-plural')).toBeInTheDocument(); + expect(screen.getByText('label.admin-superuser')).toBeInTheDocument(); + }); + it('should not render admin badge when isAdmin is false', () => { const userWithoutAdmin = { ...mockUser, isAdmin: false } as unknown as User; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/APIUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/APIUtils.ts index 17497d86fe61..ba94f67debd6 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/APIUtils.ts +++ b/openmetadata-ui/src/main/resources/ui/src/utils/APIUtils.ts @@ -33,6 +33,7 @@ export const formatUsersResponse = ( id: d._source.id, teams: d._source.teams, roles: d._source.roles, + isAdmin: d._source.isAdmin, href: d._source.href, isBot: d._source.isBot, }; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx index a49ef1ef4562..20c9feb4a457 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx @@ -128,6 +128,7 @@ import { getEncodedFqn, removeOuterEscapes, } from '../StringUtils'; +import { getUserRoleRefs } from '../UsersPureUtils'; import { isSystemClassificationTagFqn } from './CSV.utils'; import { convertCustomPropertyStringToEntityExtension, @@ -710,7 +711,9 @@ const getFirstEntityName = ( const getBulkEditUserDescription = ( user: ReturnType[number] ) => { - const role = getFirstEntityName(user.roles); + const role = getFirstEntityName( + getUserRoleRefs(user, t('label.admin-superuser')) + ); const team = getFirstEntityName(user.teams); if (role && team) { From 0c7718fd2de05717b0efa7515cf58eb37d9914fc Mon Sep 17 00:00:00 2001 From: Rohit0301 Date: Fri, 4 Dec 2026 14:44:44 +0530 Subject: [PATCH 3/3] Move getUserRoleRefs into its own module to keep routes under budget UsersPureUtils imports moment and the API helpers, so importing the role helper from it put them on every route that renders the user hover card, taking ServiceDetailsPage over its bundle budget. UserRoleUtils imports only TERM_ADMIN and types. --- .../PopOverCard/UserRoles.component.tsx | 2 +- .../Profile/components/RolesRow.tsx | 2 +- .../tabs/members/MembersOnlineUsersPanel.tsx | 6 +-- .../tabs/members/MembersTeamDetail.utils.tsx | 6 +-- .../tabs/members/MembersUsersPanel.tsx | 6 +-- .../Profile/tabs/personas/PersonaUsersTab.tsx | 6 +-- .../ui/src/utils/CSV/CSVUtilsClassBase.tsx | 2 +- .../ui/src/utils/UserRoleUtils.test.ts | 38 +++++++++++++++++++ .../resources/ui/src/utils/UserRoleUtils.ts | 36 ++++++++++++++++++ .../ui/src/utils/Users.util.test.tsx | 31 +-------------- .../resources/ui/src/utils/Users.util.tsx | 3 +- .../resources/ui/src/utils/UsersPureUtils.ts | 27 +------------ 12 files changed, 90 insertions(+), 75 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.test.ts create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.ts diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx index f0bbcc6c8b99..68218db07745 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/PopOverCard/UserRoles.component.tsx @@ -15,7 +15,7 @@ import { User01 } from '@openmetadata/ui-core-components/icons'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { getEntityName } from '../../../utils/EntityNameUtils'; -import { getUserRoleRefs } from '../../../utils/UsersPureUtils'; +import { getUserRoleRefs } from '../../../utils/UserRoleUtils'; import { UserRolesProps } from './UserPopOverCard.interface'; export const UserRoles = React.memo(({ user }: UserRolesProps) => { diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx index 631abc4654a4..c4a0f22a8d4d 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/components/RolesRow.tsx @@ -25,7 +25,7 @@ import { useProfileCopy } from '../../../../../hooks/discovery/personal-space/us import { searchRoles } from '../../../../../rest/rolesAPIV1'; import { getEntityName } from '../../../../../utils/EntityNameUtils'; import { showErrorToast } from '../../../../../utils/ToastUtils'; -import { getUserRoleRefs } from '../../../../../utils/UsersPureUtils'; +import { getUserRoleRefs } from '../../../../../utils/UserRoleUtils'; import ChipBadgeList from './ChipBadgeList'; import InlineEditCard from './InlineEditCard'; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersOnlineUsersPanel.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersOnlineUsersPanel.tsx index 34663f7f1b94..453852231691 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersOnlineUsersPanel.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersOnlineUsersPanel.tsx @@ -52,10 +52,8 @@ import { useCursorPageJump, } from '../../../../../../hooks/paging/useCursorPageJump'; import { shouldShowPager } from '../../../../../../utils/PaginationUtils'; -import { - getUserIdentifier, - getUserRoleRefs, -} from '../../../../../../utils/UsersPureUtils'; +import { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; +import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import { DEFAULT_TIME_WINDOW, TIME_WINDOW_OPTIONS } from './Members.constants'; import type { MembersSubPanelProps } from './Members.types'; import { formatOnlineStatus } from './Members.utils'; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx index 8c258199f131..b977892edb98 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersTeamDetail.utils.tsx @@ -25,10 +25,8 @@ import { Team, TeamType } from '../../../../../../generated/entity/teams/team'; import { User } from '../../../../../../generated/entity/teams/user'; import { EntityReference } from '../../../../../../generated/entity/type'; import { getEntityName } from '../../../../../../utils/EntityNameUtils'; -import { - getUserIdentifier, - getUserRoleRefs, -} from '../../../../../../utils/UsersPureUtils'; +import { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; +import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import RichTextEditorPreviewerV1 from '../../../../../common/RichTextEditor/RichTextEditorPreviewerV1'; import type { ColumnsType } from '../../../../../common/Table/Table.interface'; import type { MembersView } from './Members.types'; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx index b0da85665ec7..174dbad0206e 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/members/MembersUsersPanel.tsx @@ -77,10 +77,8 @@ import { useCursorPageJump, } from '../../../../../../hooks/paging/useCursorPageJump'; import { shouldShowPager } from '../../../../../../utils/PaginationUtils'; -import { - getUserIdentifier, - getUserRoleRefs, -} from '../../../../../../utils/UsersPureUtils'; +import { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; +import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import type { MembersUsersPanelProps } from './Members.types'; import { EntityLinksCell, UserNameCell } from './MembersUserColumns'; import { profileHash } from './profileHash.utils'; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx index dac977439cf8..c446e4cea338 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/discovery/personal-space/Profile/tabs/personas/PersonaUsersTab.tsx @@ -33,10 +33,8 @@ import { searchQuery } from '../../../../../../rest/searchAPI'; import { getEntityName } from '../../../../../../utils/EntityNameUtils'; import { getTermQuery } from '../../../../../../utils/SearchPureUtils'; import { showErrorToast } from '../../../../../../utils/ToastUtils'; -import { - getUserIdentifier, - getUserRoleRefs, -} from '../../../../../../utils/UsersPureUtils'; +import { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; +import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import NoDataPlaceholder from '../../../../../common/EmptyPlaceholder/NoDataPlaceholder'; import UserPopOverCard from '../../../../../common/PopOverCard/UserPopOverCard'; import { UserTeamSelectableList } from '../../../../../common/UserTeamSelectableList/UserTeamSelectableList.component'; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx index 20c9feb4a457..701ca7d896ab 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx @@ -128,7 +128,7 @@ import { getEncodedFqn, removeOuterEscapes, } from '../StringUtils'; -import { getUserRoleRefs } from '../UsersPureUtils'; +import { getUserRoleRefs } from '../UserRoleUtils'; import { isSystemClassificationTagFqn } from './CSV.utils'; import { convertCustomPropertyStringToEntityExtension, diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.test.ts b/openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.test.ts new file mode 100644 index 000000000000..0ae2dc773a90 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.test.ts @@ -0,0 +1,38 @@ +/* + * Copyright 2025 Collate. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { TERM_ADMIN } from '../constants/constants'; +import { getUserRoleRefs } from './UserRoleUtils'; + +describe('getUserRoleRefs', () => { + const role = { id: 'r1', type: 'role', name: 'DataSteward' }; + + it('returns the role entities of a non-admin', () => { + expect(getUserRoleRefs({ roles: [role] }, 'Admin')).toEqual([role]); + expect(getUserRoleRefs({}, 'Admin')).toEqual([]); + }); + + it('adds Admin first for an admin, with or without role entities', () => { + const admin = { + id: TERM_ADMIN, + type: 'role', + name: 'Admin', + displayName: 'Admin', + }; + + expect(getUserRoleRefs({ isAdmin: true }, 'Admin')).toEqual([admin]); + expect(getUserRoleRefs({ isAdmin: true, roles: [role] }, 'Admin')).toEqual([ + admin, + role, + ]); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.ts new file mode 100644 index 000000000000..f5aaac4c07e2 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/utils/UserRoleUtils.ts @@ -0,0 +1,36 @@ +/* + * Copyright 2025 Collate. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TERM_ADMIN } from '../constants/constants'; +import type { EntityReference, User } from '../generated/entity/teams/user'; + +// Admin is stored as `isAdmin`, not as a role entity, so it is surfaced as a +// synthetic role (id TERM_ADMIN) — first, so a list cap never hides it. +// Kept apart from UsersPureUtils so the user hover card and tables don't pull +// moment and the API helpers into every route that renders them. +export const getUserRoleRefs = ( + user: Pick, + adminLabel: string +): EntityReference[] => [ + ...(user.isAdmin + ? [ + { + id: TERM_ADMIN, + type: 'role', + name: adminLabel, + displayName: adminLabel, + }, + ] + : []), + ...(user.roles ?? []), +]; diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.test.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.test.tsx index 26a890f63d00..4f167204f0d1 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.test.tsx @@ -12,17 +12,12 @@ */ import { render, screen } from '@testing-library/react'; import { MemoryRouter } from 'react-router-dom'; -import { TERM_ADMIN } from '../constants/constants'; import { MASKED_EMAIL } from '../constants/User.constants'; import { User } from '../generated/entity/teams/user'; import { useApplicationStore } from '../hooks/useApplicationStore'; import { getUserByName } from '../rest/userAPI'; import { userCellRenderer } from './Users.util'; -import { - getUserIdentifier, - getUserRoleRefs, - isMaskedEmail, -} from './UsersPureUtils'; +import { getUserIdentifier, isMaskedEmail } from './UsersPureUtils'; jest.mock('../rest/userAPI', () => ({ getUserByName: jest.fn(), @@ -98,27 +93,3 @@ describe('User Utils -- isMaskedEmail', () => { expect(result).toBe(false); }); }); - -describe('User Utils -- getUserRoleRefs', () => { - const role = { id: 'r1', type: 'role', name: 'DataSteward' }; - - it('returns the role entities of a non-admin', () => { - expect(getUserRoleRefs({ roles: [role] }, 'Admin')).toEqual([role]); - expect(getUserRoleRefs({}, 'Admin')).toEqual([]); - }); - - it('adds Admin first for an admin, with or without role entities', () => { - const admin = { - id: TERM_ADMIN, - type: 'role', - name: 'Admin', - displayName: 'Admin', - }; - - expect(getUserRoleRefs({ isAdmin: true }, 'Admin')).toEqual([admin]); - expect(getUserRoleRefs({ isAdmin: true, roles: [role] }, 'Admin')).toEqual([ - admin, - role, - ]); - }); -}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx index 21be1cac9b4e..830214b0af45 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx @@ -32,7 +32,8 @@ import { t } from './i18next/LocalUtil'; import { LIST_CAP } from './PermissionsUtils'; import { getRoleWithFqnPath, getTeamsWithFqnPath } from './RouterUtils'; import { getSettingsLink } from './SettingsModalLinkUtils'; -import { getUserIdentifier, getUserRoleRefs } from './UsersPureUtils'; +import { getUserRoleRefs } from './UserRoleUtils'; +import { getUserIdentifier } from './UsersPureUtils'; // The synthetic Admin role has no role page to link to. const renderRole = (role: EntityReference) => diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts b/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts index 2b3c3692efb6..ccd0e61d0efe 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts +++ b/openmetadata-ui/src/main/resources/ui/src/utils/UsersPureUtils.ts @@ -14,13 +14,9 @@ import type { AxiosError } from 'axios'; import moment from 'moment'; import { HTTP_STATUS_CODE } from '../constants/Auth.constants'; -import { - ERROR_MESSAGE, - NO_DATA_PLACEHOLDER, - TERM_ADMIN, -} from '../constants/constants'; +import { ERROR_MESSAGE, NO_DATA_PLACEHOLDER } from '../constants/constants'; import { MASKED_EMAIL } from '../constants/User.constants'; -import type { EntityReference, User } from '../generated/entity/teams/user'; +import type { User } from '../generated/entity/teams/user'; import { getIsErrorMatch } from './APIUtils'; import { t } from './i18next/LocalUtil'; @@ -118,22 +114,3 @@ export const getUserFirstName = (user: { name: string; displayName?: string; }): string => (user.displayName?.trim() || user.name).split(/\s+/)[0]; - -// Admin is stored as `isAdmin`, not as a role entity, so it is surfaced as a -// synthetic role (id TERM_ADMIN) — first, so a list cap never hides it. -export const getUserRoleRefs = ( - user: Pick, - adminLabel: string -): EntityReference[] => [ - ...(user.isAdmin - ? [ - { - id: TERM_ADMIN, - type: 'role', - name: adminLabel, - displayName: adminLabel, - }, - ] - : []), - ...(user.roles ?? []), -];