Move Impersonate from User to Workspace (#2630)

* Fix impersonate

* align core typeorm config with metadata config + add allowImpersonation to workspace

* move allowImpersonation to workspace

* remove allowImpersonation from workspaceMember workspace table
This commit is contained in:
Weiko
2023-11-22 14:12:39 +01:00
committed by GitHub
parent 680e9b6aa5
commit a6abe09163
33 changed files with 199 additions and 119 deletions

View File

@ -1,10 +1,10 @@
import { atom } from 'recoil';
import { Workspace } from '~/generated-metadata/graphql';
import { Workspace } from '~/generated/graphql';
export type CurrentWorkspace = Pick<
Workspace,
'id' | 'inviteHash' | 'logo' | 'displayName'
'id' | 'inviteHash' | 'logo' | 'displayName' | 'allowImpersonation'
>;
export const currentWorkspaceState = atom<CurrentWorkspace | null>({

View File

@ -0,0 +1,46 @@
import { useRecoilState } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { Toggle } from '@/ui/input/components/Toggle';
import { useUpdateWorkspaceMutation } from '~/generated/graphql';
export const ToggleImpersonate = () => {
const { enqueueSnackBar } = useSnackBar();
const [currentWorkspace, setCurrentWorkspace] = useRecoilState(
currentWorkspaceState,
);
const [updateWorkspace] = useUpdateWorkspaceMutation();
const handleChange = async (value: boolean) => {
try {
if (!currentWorkspace?.id) {
throw new Error('User is not logged in');
}
await updateWorkspace({
variables: {
input: {
allowImpersonation: value,
},
},
});
setCurrentWorkspace({
...currentWorkspace,
allowImpersonation: value,
});
} catch (err: any) {
enqueueSnackBar(err?.message, {
variant: 'error',
});
}
};
return (
<Toggle
value={currentWorkspace?.allowImpersonation}
onChange={handleChange}
/>
);
};

View File

@ -25,6 +25,7 @@ export const USER_QUERY_FRAGMENT = gql`
logo
domainName
inviteHash
allowImpersonation
}
}
`;

View File

@ -26,6 +26,7 @@ export const GET_CURRENT_USER = gql`
logo
domainName
inviteHash
allowImpersonation
}
}
}

View File

@ -7,6 +7,7 @@ export const UPDATE_WORKSPACE = gql`
domainName
displayName
logo
allowImpersonation
}
}
`;

View File

@ -6,6 +6,7 @@ export const GET_WORKSPACE_FROM_INVITE_HASH = gql`
id
displayName
logo
allowImpersonation
}
}
`;