Refactor user details and edit permissions (#23441)

This commit is contained in:
Laura Bergenthal-Grotlüschen
2025-08-20 15:23:19 +02:00
committed by GitHub
parent 7e883e4b05
commit c8e2ba35e0
6 changed files with 37 additions and 19 deletions

View File

@@ -126,7 +126,7 @@ describe('UserDetails', () => {
it('should display info if license is not present', async () => {
render(<UserDetails user={user} />);
await screen.findByText(/Enterprise Feature/);
await screen.findAllByText(/Enterprise Feature/);
});
});
});

View File

@@ -69,11 +69,9 @@ const UserDetails = ({ user }: Props) => {
<TelemetrySettingsDetails />
</IfPermitted>
)}
{(currentUser.id === user.id || isLocalAdmin) && (
<IfPermitted permissions={`users:edit:${user.username}`}>
<CollectionsSection user={user} />
</IfPermitted>
)}
<IfPermitted permissions={`users:edit:${user.username}`}>
<CollectionsSection user={user} />
</IfPermitted>
{currentUser.id === user.id && isLocalAdmin && (
<IfPermitted permissions={`users:edit:${user.username}`}>
<TelemetrySettingsConfig />

View File

@@ -16,6 +16,7 @@
*/
import * as React from 'react';
import { IfPermitted } from 'components/common';
import { LinkContainer } from 'components/common/router';
import type User from 'logic/users/User';
import Routes from 'routing/Routes';
@@ -24,21 +25,28 @@ import { ButtonToolbar, Button } from 'components/bootstrap';
type Props = {
userId: User['id'];
userIsReadOnly: boolean;
username: User['username'];
};
const UserActionLinks = ({ userId, userIsReadOnly }: Props) => (
const UserActionLinks = ({ userId, userIsReadOnly, username }: Props) => (
<ButtonToolbar>
<LinkContainer to={Routes.SYSTEM.USERS.show(userId)}>
<Button bsStyle="success">View Details</Button>
</LinkContainer>
{!userIsReadOnly && (
<LinkContainer to={Routes.SYSTEM.USERS.edit(userId)}>
<Button bsStyle="success">Edit User</Button>
<IfPermitted permissions={`users:edit:${username}`}>
<LinkContainer to={Routes.SYSTEM.USERS.show(userId)}>
<Button bsStyle="success">View Details</Button>
</LinkContainer>
</IfPermitted>
{!userIsReadOnly && (
<IfPermitted permissions={`users:edit:${username}`}>
<LinkContainer to={Routes.SYSTEM.USERS.edit(userId)}>
<Button bsStyle="success">Edit User</Button>
</LinkContainer>
</IfPermitted>
)}
<LinkContainer to={Routes.SYSTEM.USERS.TOKENS.edit(userId)}>
<Button bsStyle="success">Edit Tokens</Button>
</LinkContainer>
<IfPermitted permissions={[`users:tokenlist:${username}`]}>
<LinkContainer to={Routes.SYSTEM.USERS.TOKENS.edit(userId)}>
<Button bsStyle="success">Edit Tokens</Button>
</LinkContainer>
</IfPermitted>
</ButtonToolbar>
);

View File

@@ -56,7 +56,13 @@ const UserDetailsPage = ({ params }: Props) => {
<UsersPageNavigation />
<PageHeader
title={<PageTitle fullName={loadedUser?.fullName} />}
actions={<UserActionLinks userId={userId} userIsReadOnly={loadedUser?.readOnly ?? false} />}
actions={
<UserActionLinks
userId={userId}
username={loadedUser?.username ?? ''}
userIsReadOnly={loadedUser?.readOnly ?? false}
/>
}
documentationLink={{
title: 'Permissions documentation',
path: DocsHelper.PAGES.USERS_ROLES,

View File

@@ -67,7 +67,7 @@ const UserEditPage = ({ params }: Props) => {
<UsersPageNavigation />
<PageHeader
title={<PageTitle fullName={fullName} />}
actions={<UserActionLinks userId={userId} userIsReadOnly={readOnly} />}
actions={<UserActionLinks userId={userId} username={loadedUser?.username ?? ''} userIsReadOnly={readOnly} />}
documentationLink={{
title: 'Permissions documentation',
path: DocsHelper.PAGES.USERS_ROLES,

View File

@@ -96,7 +96,13 @@ const UserEditPage = ({ params }: Props) => {
<UsersPageNavigation />
<PageHeader
title={<PageTitle fullName={loadedUser?.fullName} />}
actions={<UserActionLinks userId={userId} userIsReadOnly={loadedUser?.readOnly ?? false} />}
actions={
<UserActionLinks
userId={userId}
username={loadedUser?.username ?? ''}
userIsReadOnly={loadedUser?.readOnly ?? false}
/>
}
documentationLink={{
title: 'Permissions documentation',
path: DocsHelper.PAGES.USERS_ROLES,