Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<div className="m-t-xs">
<p className="d-flex items-center">
<User01 size={16} />
Expand All @@ -32,11 +32,6 @@ export const UserRoles = React.memo(({ user }: UserRolesProps) => {
</p>

<span className="d-flex flex-wrap m-t-xss">
{isAdmin && (
<span className="bg-grey rounded-4 p-x-xs text-xs m-b-xss">
{t('label.admin-superuser')}
</span>
)}
{roles.map((role) => (
<span
className="bg-grey rounded-4 p-x-xs text-xs m-b-xss"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ describe('UserRoles Component', () => {
expect(container).toBeEmptyDOMElement();
});

it('should render the admin badge for an admin with no role entities', () => {
render(
<UserRoles user={{ isAdmin: true, roles: [] } as unknown as User} />
);

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -126,21 +124,10 @@ const RolesRow: React.FC<RolesRowProps> = ({
);
};

// 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 (
<InlineEditCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
useCursorPageJump,
} from '../../../../../../hooks/paging/useCursorPageJump';
import { shouldShowPager } from '../../../../../../utils/PaginationUtils';
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';
Expand Down Expand Up @@ -326,7 +327,7 @@ const MembersOnlineUsersPanel: FC<MembersSubPanelProps> = () => {
<EntityLinksCell
emptyLabel="-"
goTo={goTo}
items={record.roles}
items={getUserRoleRefs(record, t('label.admin-superuser'))}
targetFn={profileHash.role}
testId="role-link"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -250,7 +251,7 @@ export const getUserColumns = (
<EntityLinksCell
emptyLabel={t('label.no-entity', { entity: t('label.role') })}
goTo={goTo}
items={record.roles}
items={getUserRoleRefs(record, t('label.admin-superuser'))}
targetFn={profileHash.role}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -80,16 +81,22 @@ export const EntityLinksCell: FC<{
return <>{emptyLabel}</>;
}

const renderItem = (item: EntityReference) => (
<ProfileHashLink
className="tw:block tw:max-w-full tw:truncate"
key={item.id}
target={targetFn(item.fullyQualifiedName ?? item.name ?? '')}
title={getEntityName(item)}
onNavigate={goTo}>
{getEntityName(item)}
</ProfileHashLink>
);
// The synthetic Admin role has no role page to link to.
const renderItem = (item: EntityReference) =>
item.id === TERM_ADMIN ? (
<Typography className="tw:block tw:max-w-full tw:truncate" key={item.id}>
{getEntityName(item)}
</Typography>
) : (
<ProfileHashLink
className="tw:block tw:max-w-full tw:truncate"
key={item.id}
target={targetFn(item.fullyQualifiedName ?? item.name ?? '')}
title={getEntityName(item)}
onNavigate={goTo}>
{getEntityName(item)}
</ProfileHashLink>
);

return (
<Box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,21 @@ describe('MembersUsersPanel', () => {
});
});

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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -389,7 +390,7 @@ const MembersUsersPanel: React.FC<MembersUsersPanelProps> = ({
<EntityLinksCell
emptyLabel={t('label.no-entity', { entity: t('label.role') })}
goTo={goTo}
items={record.roles}
items={getUserRoleRefs(record, t('label.admin-superuser'))}
targetFn={profileHash.role}
testId="role-link"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ? (
<ConfirmPopover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
getEncodedFqn,
removeOuterEscapes,
} from '../StringUtils';
import { getUserRoleRefs } from '../UserRoleUtils';
import { isSystemClassificationTagFqn } from './CSV.utils';

Check warning on line 132 in openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

This runtime import participates in a circular dependency. Extract the shared type/constant/utility or invert the dependency
import {
convertCustomPropertyStringToEntityExtension,
convertEntityExtensionToCustomPropertyString,
Expand Down Expand Up @@ -710,7 +711,9 @@
const getBulkEditUserDescription = (
user: ReturnType<typeof formatUsersResponse>[number]
) => {
const role = getFirstEntityName(user.roles);
const role = getFirstEntityName(
getUserRoleRefs(user, t('label.admin-superuser'))
);
const team = getFirstEntityName(user.teams);

if (role && team) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
]);
});
});
Original file line number Diff line number Diff line change
@@ -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<User, 'roles' | 'isAdmin'>,
adminLabel: string
): EntityReference[] => [
...(user.isAdmin
? [
{
id: TERM_ADMIN,
type: 'role',
name: adminLabel,
displayName: adminLabel,
},
]
: []),
...(user.roles ?? []),
];
Loading
Loading