disable editing my own user

This commit is contained in:
Nate Kelley 2025-01-23 11:05:07 -07:00
parent b658eb2728
commit aa190a73de
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 32 additions and 17 deletions

View File

@ -1,16 +1,20 @@
import { OrganizationUser, useUpdateUser } from '@/api'; import { type BusterUser, type OrganizationUser, useUpdateUser } from '@/api';
import React from 'react'; import React from 'react';
import { Text, Title } from '@/components/text'; import { Text, Title } from '@/components/text';
import { Card, Select } from 'antd'; import { Card, Select } from 'antd';
import { useMemoizedFn } from 'ahooks'; import { useMemoizedFn } from 'ahooks';
import { AppTooltip } from '@/components';
export const UserDefaultAccess: React.FC<{ export const UserDefaultAccess: React.FC<{
user: OrganizationUser; user: OrganizationUser;
isAdmin: boolean; isAdmin: boolean;
myUser: BusterUser;
refetchUser: () => void; refetchUser: () => void;
}> = ({ user, isAdmin, refetchUser }) => { }> = ({ user, isAdmin, myUser, refetchUser }) => {
const { mutateAsync, isPending } = useUpdateUser(); const { mutateAsync, isPending } = useUpdateUser();
const userIsMe = user.id === myUser.id;
const onChange = useMemoizedFn(async (value: string) => { const onChange = useMemoizedFn(async (value: string) => {
await mutateAsync({ userId: user.id, role: value as OrganizationUser['role'] }); await mutateAsync({ userId: user.id, role: value as OrganizationUser['role'] });
refetchUser(); refetchUser();
@ -25,6 +29,7 @@ export const UserDefaultAccess: React.FC<{
onChange={onChange} onChange={onChange}
isLoading={isPending} isLoading={isPending}
isAdmin={isAdmin} isAdmin={isAdmin}
userIsMe={userIsMe}
/> />
</div> </div>
); );
@ -42,25 +47,38 @@ const DefaultAccessCard = React.memo(
role, role,
onChange, onChange,
isLoading, isLoading,
isAdmin isAdmin,
userIsMe
}: { }: {
role: OrganizationUser['role']; role: OrganizationUser['role'];
onChange: (role: OrganizationUser['role']) => void; onChange: (role: OrganizationUser['role']) => void;
isLoading: boolean; isLoading: boolean;
isAdmin: boolean; isAdmin: boolean;
userIsMe: boolean;
}) => { }) => {
const isDisabled = !isAdmin || userIsMe;
return ( return (
<Card size="small"> <Card size="small">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<Text>Default Access</Text> <Text>Default Access</Text>
<Select <AppTooltip
options={accessOptions} title={
value={role} isDisabled
onChange={onChange} ? userIsMe
loading={isLoading} ? 'You cannot change your own access'
disabled={!isAdmin} : 'Only admins can change access'
/> : undefined
}>
<Select
options={accessOptions}
value={role}
onChange={onChange}
loading={isLoading}
disabled={isDisabled}
/>
</AppTooltip>
</div> </div>
</Card> </Card>
); );

View File

@ -10,12 +10,13 @@ import { UserDatasetSearch } from './UserDatasetSearch';
export const UserOverviewController = React.memo(({ userId }: { userId: string }) => { export const UserOverviewController = React.memo(({ userId }: { userId: string }) => {
const { data: user, refetch: refetchUser } = useGetUser({ userId }); const { data: user, refetch: refetchUser } = useGetUser({ userId });
const isAdmin = useUserConfigContextSelector((x) => x.isAdmin); const isAdmin = useUserConfigContextSelector((x) => x.isAdmin);
const myUser = useUserConfigContextSelector((x) => x.user);
if (!user) return null; if (!user || !myUser) return null;
return ( return (
<> <>
<UserDefaultAccess user={user} isAdmin={isAdmin} refetchUser={refetchUser} /> <UserDefaultAccess user={user} myUser={myUser} isAdmin={isAdmin} refetchUser={refetchUser} />
<UserLineageHeader className="!mt-[48px]" user={user} /> <UserLineageHeader className="!mt-[48px]" user={user} />
<UserDatasetSearch user={user} /> <UserDatasetSearch user={user} />
</> </>

View File

@ -1,8 +1,4 @@
import { import { useUpdateUserPermissionGroups, type BusterUserPermissionGroup } from '@/api/buster_rest';
useUpdateUserPermissionGroups,
useUpdateUserTeams,
type BusterUserPermissionGroup
} from '@/api/buster_rest';
import { PermissionAssignedCell } from '@/app/app/_components/PermissionComponents'; import { PermissionAssignedCell } from '@/app/app/_components/PermissionComponents';
import { import {
BusterInfiniteList, BusterInfiniteList,