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..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,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/UserRoleUtils'; 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/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..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 @@ -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/UserRoleUtils'; 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..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,6 +25,7 @@ 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 { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import RichTextEditorPreviewerV1 from '../../../../../common/RichTextEditor/RichTextEditorPreviewerV1'; import type { ColumnsType } from '../../../../../common/Table/Table.interface'; @@ -250,7 +251,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..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,6 +77,7 @@ import { useCursorPageJump, } from '../../../../../../hooks/paging/useCursorPageJump'; import { shouldShowPager } from '../../../../../../utils/PaginationUtils'; +import { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import type { MembersUsersPanelProps } from './Members.types'; import { EntityLinksCell, UserNameCell } from './MembersUserColumns'; @@ -389,7 +390,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..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,6 +33,7 @@ import { searchQuery } from '../../../../../../rest/searchAPI'; import { getEntityName } from '../../../../../../utils/EntityNameUtils'; import { getTermQuery } from '../../../../../../utils/SearchPureUtils'; import { showErrorToast } from '../../../../../../utils/ToastUtils'; +import { getUserRoleRefs } from '../../../../../../utils/UserRoleUtils'; import { getUserIdentifier } from '../../../../../../utils/UsersPureUtils'; import NoDataPlaceholder from '../../../../../common/EmptyPlaceholder/NoDataPlaceholder'; import UserPopOverCard from '../../../../../common/PopOverCard/UserPopOverCard'; @@ -162,7 +163,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 ? ( [number] ) => { - const role = getFirstEntityName(user.roles); + const role = getFirstEntityName( + getUserRoleRefs(user, t('label.admin-superuser')) + ); const team = getFirstEntityName(user.teams); if (role && team) { 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.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/Users.util.tsx index 684befe4ce40..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 @@ -25,14 +25,29 @@ 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 { getUserRoleRefs } from './UserRoleUtils'; import { getUserIdentifier } 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 +178,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 +198,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)}