mirror of https://github.com/buster-so/buster.git
disable editing my own user
This commit is contained in:
parent
b658eb2728
commit
aa190a73de
|
@ -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>
|
||||||
|
|
||||||
|
<AppTooltip
|
||||||
|
title={
|
||||||
|
isDisabled
|
||||||
|
? userIsMe
|
||||||
|
? 'You cannot change your own access'
|
||||||
|
: 'Only admins can change access'
|
||||||
|
: undefined
|
||||||
|
}>
|
||||||
<Select
|
<Select
|
||||||
options={accessOptions}
|
options={accessOptions}
|
||||||
value={role}
|
value={role}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
disabled={!isAdmin}
|
disabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
|
</AppTooltip>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|
|
@ -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} />
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue