1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +02:00

fix: disallow deletion of single login history entries (#4149)

https://linear.app/unleash/issue/2-1185/disallow-deletion-of-single-login-entries-in-history-ui

Disallows deletion of single login history entries on the UI.


![image](https://github.com/Unleash/unleash/assets/14320932/380f7e11-8151-49b1-bfd1-0042d87854b7)
This commit is contained in:
Nuno Góis 2023-07-06 08:36:26 +01:00 committed by GitHub
parent 6d591fcd17
commit dd32e8ae0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 81 deletions

View File

@ -1,29 +0,0 @@
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { ILoginEvent } from 'interfaces/loginEvent';
interface ILoginHistoryDeleteDialogProps {
event?: ILoginEvent;
open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
onConfirm: (event: ILoginEvent) => void;
}
export const LoginHistoryDeleteDialog = ({
event,
open,
setOpen,
onConfirm,
}: ILoginHistoryDeleteDialogProps) => (
<Dialogue
title="Delete event?"
open={open}
primaryButtonText="Delete event"
secondaryButtonText="Cancel"
onClick={() => onConfirm(event!)}
onClose={() => {
setOpen(false);
}}
>
You are about to delete event: <strong>#{event?.id}</strong>
</Dialogue>
);

View File

@ -19,8 +19,6 @@ import { TimeAgoCell } from 'component/common/Table/cells/TimeAgoCell/TimeAgoCel
import { useLoginHistory } from 'hooks/api/getters/useLoginHistory/useLoginHistory';
import { LoginHistorySuccessfulCell } from './LoginHistorySuccessfulCell/LoginHistorySuccessfulCell';
import { ILoginEvent } from 'interfaces/loginEvent';
import { LoginHistoryActionsCell } from './LoginHistoryActionsCell/LoginHistoryActionsCell';
import { LoginHistoryDeleteDialog } from './LoginHistoryDeleteDialog/LoginHistoryDeleteDialog';
import { useLoginHistoryApi } from 'hooks/api/actions/useLoginHistoryApi/useLoginHistoryApi';
import { formatDateYMDHMS } from 'utils/formatDate';
import { useSearchParams } from 'react-router-dom';
@ -50,7 +48,7 @@ export const LoginHistoryTable = () => {
const { setToastData, setToastApiError } = useToast();
const { events, loading, refetch } = useLoginHistory();
const { removeEvent, removeAllEvents, downloadCSV } = useLoginHistoryApi();
const { removeAllEvents, downloadCSV } = useLoginHistoryApi();
const [searchParams, setSearchParams] = useSearchParams();
const [initialState] = useState(() => ({
@ -67,24 +65,8 @@ export const LoginHistoryTable = () => {
}));
const [searchValue, setSearchValue] = useState(initialState.globalFilter);
const [selectedEvent, setSelectedEvent] = useState<ILoginEvent>();
const [deleteOpen, setDeleteOpen] = useState(false);
const [deleteAllOpen, setDeleteAllOpen] = useState(false);
const onDeleteConfirm = async (event: ILoginEvent) => {
try {
await removeEvent(event.id);
setToastData({
title: `Event has been deleted`,
type: 'success',
});
refetch();
setDeleteOpen(false);
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
}
};
const onDeleteAllConfirm = async () => {
try {
await removeAllEvents();
@ -144,21 +126,6 @@ export const LoginHistoryTable = () => {
filterName: 'success',
filterParsing: (value: boolean) => value.toString(),
},
{
Header: 'Actions',
id: 'Actions',
align: 'center',
Cell: ({ row: { original: event } }: any) => (
<LoginHistoryActionsCell
onDelete={() => {
setSelectedEvent(event);
setDeleteOpen(true);
}}
/>
),
width: 150,
disableSortBy: true,
},
// Always hidden -- for search
{
accessor: 'failure_reason',
@ -327,12 +294,6 @@ export const LoginHistoryTable = () => {
/>
}
/>
<LoginHistoryDeleteDialog
event={selectedEvent}
open={deleteOpen}
setOpen={setDeleteOpen}
onConfirm={onDeleteConfirm}
/>
<LoginHistoryDeleteAllDialog
open={deleteAllOpen}
setOpen={setDeleteAllOpen}

View File

@ -22,17 +22,6 @@ export const useLoginHistoryApi = () => {
window.location.assign(url);
};
const removeEvent = async (eventId: number) => {
const requestId = 'removeEvent';
const req = createRequest(
`api/admin/logins/${eventId}`,
{ method: 'DELETE' },
requestId
);
await makeRequest(req.caller, req.id);
};
const removeAllEvents = async () => {
const requestId = 'removeAllEvents';
const req = createRequest(
@ -46,7 +35,6 @@ export const useLoginHistoryApi = () => {
return {
downloadCSV,
removeEvent,
removeAllEvents,
errors,
loading,