|
|
|
@ -6,7 +6,7 @@ import { getClient } from '../api';
|
|
|
|
|
|
|
|
|
|
import { deleteFromTimelines } from './timelines';
|
|
|
|
|
|
|
|
|
|
import type { Account, AdminGetAccountsParams, AdminGetReportsParams, PleromaConfig, Status } from 'pl-api';
|
|
|
|
|
import type { Account, AdminAccount, AdminGetAccountsParams, AdminGetReportsParams, AdminReport, PaginatedResponse, PleromaConfig, Status } from 'pl-api';
|
|
|
|
|
import type { AppDispatch, RootState } from 'pl-fe/store';
|
|
|
|
|
|
|
|
|
|
const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST' as const;
|
|
|
|
@ -106,16 +106,16 @@ const fetchReports = (params?: AdminGetReportsParams) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_REQUEST, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_REPORTS_FETCH_REQUEST, params });
|
|
|
|
|
|
|
|
|
|
return getClient(state).admin.reports.getReports(params)
|
|
|
|
|
.then(({ items }) => {
|
|
|
|
|
items.forEach((report) => {
|
|
|
|
|
dispatch(importEntities({ statuses: report.statuses as Array<Status>, accounts: [report.account?.account, report.target_account?.account] }));
|
|
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports: items, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports: items, params });
|
|
|
|
|
});
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -123,12 +123,12 @@ const closeReport = (reportId: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_REPORT_PATCH_REQUEST, reportId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_REPORT_PATCH_REQUEST, reportId });
|
|
|
|
|
|
|
|
|
|
return getClient(state).admin.reports.resolveReport(reportId).then((report) => {
|
|
|
|
|
dispatch({ type: ADMIN_REPORT_PATCH_SUCCESS, report, reportId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_REPORT_PATCH_SUCCESS, report, reportId });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_REPORT_PATCH_FAIL, error, reportId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_REPORT_PATCH_FAIL, error, reportId });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -136,15 +136,15 @@ const fetchUsers = (params?: AdminGetAccountsParams) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USERS_FETCH_REQUEST, params });
|
|
|
|
|
|
|
|
|
|
return getClient(state).admin.accounts.getAccounts(params).then((res) => {
|
|
|
|
|
dispatch(importEntities({ accounts: res.items.map(({ account }) => account).filter((account): account is Account => account !== null) }));
|
|
|
|
|
dispatch(fetchRelationships(res.items.map((account) => account.id)));
|
|
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users: res.items, params, next: res.next });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USERS_FETCH_SUCCESS, users: res.items, params, next: res.next });
|
|
|
|
|
return res;
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USERS_FETCH_FAIL, error, params });
|
|
|
|
|
throw error;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -153,20 +153,20 @@ const deactivateUser = (accountId: string, report_id?: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USER_DEACTIVATE_REQUEST, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_DEACTIVATE_REQUEST, accountId });
|
|
|
|
|
|
|
|
|
|
return getClient(state).admin.accounts.performAccountAction(accountId, 'suspend', { report_id });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteUser = (accountId: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_DELETE_REQUEST, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_DELETE_REQUEST, accountId });
|
|
|
|
|
|
|
|
|
|
return getClient(getState).admin.accounts.deleteAccount(accountId)
|
|
|
|
|
.then(() => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_DELETE_SUCCESS, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_DELETE_SUCCESS, accountId });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_DELETE_FAIL, error, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_DELETE_FAIL, error, accountId });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -174,57 +174,57 @@ const approveUser = (accountId: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USER_APPROVE_REQUEST, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_APPROVE_REQUEST, accountId });
|
|
|
|
|
|
|
|
|
|
return getClient(state).admin.accounts.approveAccount(accountId)
|
|
|
|
|
.then((user) => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_APPROVE_SUCCESS, user, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_APPROVE_SUCCESS, user, accountId });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_APPROVE_FAIL, error, accountId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_APPROVE_FAIL, error, accountId });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteStatus = (statusId: string) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
dispatch({ type: ADMIN_STATUS_DELETE_REQUEST, statusId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_STATUS_DELETE_REQUEST, statusId });
|
|
|
|
|
return getClient(getState).admin.statuses.deleteStatus(statusId)
|
|
|
|
|
.then(() => {
|
|
|
|
|
dispatch(deleteFromTimelines(statusId));
|
|
|
|
|
return dispatch({ type: ADMIN_STATUS_DELETE_SUCCESS, statusId });
|
|
|
|
|
return dispatch<AdminActions>({ type: ADMIN_STATUS_DELETE_SUCCESS, statusId });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
return dispatch({ type: ADMIN_STATUS_DELETE_FAIL, error, statusId });
|
|
|
|
|
return dispatch<AdminActions>({ type: ADMIN_STATUS_DELETE_FAIL, error, statusId });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toggleStatusSensitivity = (statusId: string, sensitive: boolean) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST, statusId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST, statusId });
|
|
|
|
|
return getClient(getState).admin.statuses.updateStatus(statusId, { sensitive: !sensitive })
|
|
|
|
|
.then((status) => {
|
|
|
|
|
dispatch(importEntities({ statuses: [status] }));
|
|
|
|
|
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS, statusId, status });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS, statusId, status });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL, error, statusId });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL, error, statusId });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const tagUser = (accountId: string, tags: string[]) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_TAG_REQUEST, accountId, tags });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_TAG_REQUEST, accountId, tags });
|
|
|
|
|
return getClient(getState).admin.accounts.tagUser(accountId, tags).then(() => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_TAG_SUCCESS, accountId, tags });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_TAG_SUCCESS, accountId, tags });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_TAG_FAIL, error, accountId, tags });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_TAG_FAIL, error, accountId, tags });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const untagUser = (accountId: string, tags: string[]) =>
|
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_UNTAG_REQUEST, accountId, tags });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_UNTAG_REQUEST, accountId, tags });
|
|
|
|
|
return getClient(getState).admin.accounts.untagUser(accountId, tags).then(() => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_UNTAG_SUCCESS, accountId, tags });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_UNTAG_SUCCESS, accountId, tags });
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_UNTAG_FAIL, error, accountId, tags });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_UNTAG_FAIL, error, accountId, tags });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -278,7 +278,7 @@ const fetchUserIndex = () =>
|
|
|
|
|
|
|
|
|
|
if (isLoading) return;
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_REQUEST });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_FETCH_REQUEST });
|
|
|
|
|
|
|
|
|
|
const params: AdminGetAccountsParams = {
|
|
|
|
|
origin: 'local',
|
|
|
|
@ -289,9 +289,9 @@ const fetchUserIndex = () =>
|
|
|
|
|
dispatch(fetchUsers(params))
|
|
|
|
|
.then((data) => {
|
|
|
|
|
const { items, total, next } = data;
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_SUCCESS, users: items, total, next, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_FETCH_SUCCESS, users: items, total, next, params });
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_FAIL });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_FETCH_FAIL });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -301,14 +301,14 @@ const expandUserIndex = () =>
|
|
|
|
|
|
|
|
|
|
if (!loaded || isLoading || !next) return;
|
|
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_REQUEST });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_EXPAND_REQUEST });
|
|
|
|
|
|
|
|
|
|
next()
|
|
|
|
|
.then((data) => {
|
|
|
|
|
const { items, total, next } = data;
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_SUCCESS, users: items, total, next, params });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_EXPAND_SUCCESS, users: items, total, next, params });
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_FAIL });
|
|
|
|
|
dispatch<AdminActions>({ type: ADMIN_USER_INDEX_EXPAND_FAIL });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -319,6 +319,41 @@ type AdminActions =
|
|
|
|
|
| { type: typeof ADMIN_CONFIG_UPDATE_REQUEST; configs: PleromaConfig['configs'] }
|
|
|
|
|
| { type: typeof ADMIN_CONFIG_UPDATE_SUCCESS; configs: PleromaConfig['configs']; needsReboot: boolean }
|
|
|
|
|
| { type: typeof ADMIN_CONFIG_UPDATE_FAIL; error: unknown; configs: PleromaConfig['configs'] }
|
|
|
|
|
| { type: typeof ADMIN_REPORTS_FETCH_REQUEST; params?: AdminGetReportsParams }
|
|
|
|
|
| { type: typeof ADMIN_REPORTS_FETCH_SUCCESS; reports: Array<AdminReport>; params?: AdminGetReportsParams }
|
|
|
|
|
| { type: typeof ADMIN_REPORTS_FETCH_FAIL; error: unknown; params?: AdminGetReportsParams }
|
|
|
|
|
| { type: typeof ADMIN_REPORT_PATCH_REQUEST; reportId: string }
|
|
|
|
|
| { type: typeof ADMIN_REPORT_PATCH_SUCCESS; report: AdminReport; reportId: string }
|
|
|
|
|
| { type: typeof ADMIN_REPORT_PATCH_FAIL; error: unknown; reportId: string }
|
|
|
|
|
| { type: typeof ADMIN_USERS_FETCH_REQUEST; params?: AdminGetAccountsParams }
|
|
|
|
|
| { type: typeof ADMIN_USERS_FETCH_SUCCESS; users: Array<AdminAccount>; params?: AdminGetAccountsParams; next: (() => Promise<PaginatedResponse<AdminAccount>>) | null }
|
|
|
|
|
| { type: typeof ADMIN_USERS_FETCH_FAIL; error: unknown; params?: AdminGetAccountsParams }
|
|
|
|
|
| { type: typeof ADMIN_USER_DEACTIVATE_REQUEST; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_DELETE_REQUEST; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_DELETE_SUCCESS; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_DELETE_FAIL; error: unknown; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_APPROVE_REQUEST; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_APPROVE_SUCCESS; user: AdminAccount; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_APPROVE_FAIL; error: unknown; accountId: string }
|
|
|
|
|
| { type: typeof ADMIN_STATUS_DELETE_REQUEST; statusId: string }
|
|
|
|
|
| { type: typeof ADMIN_STATUS_DELETE_SUCCESS; statusId: string }
|
|
|
|
|
| { type: typeof ADMIN_STATUS_DELETE_FAIL; error: unknown; statusId: string }
|
|
|
|
|
| { type: typeof ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST; statusId: string }
|
|
|
|
|
| { type: typeof ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS; statusId: string; status: Status }
|
|
|
|
|
| { type: typeof ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL; error: unknown; statusId: string }
|
|
|
|
|
| { type: typeof ADMIN_USER_TAG_REQUEST; accountId: string; tags: Array<string> }
|
|
|
|
|
| { type: typeof ADMIN_USER_TAG_SUCCESS; accountId: string; tags: Array<string> }
|
|
|
|
|
| { type: typeof ADMIN_USER_TAG_FAIL; error: unknown; accountId: string; tags: Array<string> }
|
|
|
|
|
| { type: typeof ADMIN_USER_UNTAG_REQUEST; accountId: string; tags: Array<string> }
|
|
|
|
|
| { type: typeof ADMIN_USER_UNTAG_SUCCESS; accountId: string; tags: Array<string> }
|
|
|
|
|
| { type: typeof ADMIN_USER_UNTAG_FAIL; error: unknown; accountId: string; tags: Array<string> }
|
|
|
|
|
| ReturnType<typeof setUserIndexQuery>
|
|
|
|
|
| { type: typeof ADMIN_USER_INDEX_FETCH_REQUEST }
|
|
|
|
|
| { type: typeof ADMIN_USER_INDEX_FETCH_SUCCESS; users: Array<AdminAccount>; total?: number; next: (() => Promise<PaginatedResponse<AdminAccount>>) | null; params?: AdminGetAccountsParams }
|
|
|
|
|
| { type: typeof ADMIN_USER_INDEX_FETCH_FAIL }
|
|
|
|
|
| { type: typeof ADMIN_USER_INDEX_EXPAND_REQUEST }
|
|
|
|
|
| { type: typeof ADMIN_USER_INDEX_EXPAND_SUCCESS; users: Array<AdminAccount>; total?: number; next: (() => Promise<PaginatedResponse<AdminAccount>>) | null; params: AdminGetAccountsParams | null }
|
|
|
|
|
| { type: typeof ADMIN_USER_INDEX_EXPAND_FAIL };
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
ADMIN_CONFIG_FETCH_REQUEST,
|
|
|
|
|