Remove Pleroma moderation API where an equivalent Mastodon endpoint exists

environments/review-rm-pl-admi-mja3h5/deployments/4925
Alex Gleason 2024-10-19 12:13:08 -05:00
rodzic cf56918f66
commit dde5e9154b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 88 dodań i 228 usunięć

Wyświetl plik

@ -3,7 +3,6 @@ import { fetchRelationships } from 'soapbox/actions/accounts';
import { importFetchedAccount, importFetchedAccounts, importFetchedStatuses } from 'soapbox/actions/importer';
import { accountIdsToAccts } from 'soapbox/selectors';
import { filterBadges, getTagDiff } from 'soapbox/utils/badges';
import { getFeatures } from 'soapbox/utils/features';
import api, { getLinks } from '../api';
@ -118,100 +117,52 @@ const updateSoapboxConfig = (data: Record<string, any>) =>
return dispatch(updateConfig(params));
};
const fetchMastodonReports = (params: Record<string, any>) =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
.get('/api/v1/admin/reports', { params })
.then(({ data: reports }) => {
reports.forEach((report: APIEntity) => {
dispatch(importFetchedAccount(report.account?.account));
dispatch(importFetchedAccount(report.target_account?.account));
dispatch(importFetchedStatuses(report.statuses));
});
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
}).catch(error => {
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
});
const fetchPleromaReports = (params: Record<string, any>) =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
.get('/api/v1/pleroma/admin/reports', { params })
.then(({ data: { reports } }) => {
reports.forEach((report: APIEntity) => {
dispatch(importFetchedAccount(report.account));
dispatch(importFetchedAccount(report.actor));
dispatch(importFetchedStatuses(report.statuses));
});
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
}).catch(error => {
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
});
const fetchReports = (params: Record<string, any> = {}) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const instance = state.instance;
const features = getFeatures(instance);
function fetchReports(params: Record<string, any> = {}) {
return async (dispatch: AppDispatch, getState: () => RootState): Promise<void> => {
dispatch({ type: ADMIN_REPORTS_FETCH_REQUEST, params });
if (features.mastodonAdmin) {
return dispatch(fetchMastodonReports(params));
} else {
const { resolved } = params;
return dispatch(fetchPleromaReports({
state: resolved === false ? 'open' : (resolved ? 'resolved' : null),
}));
try {
const { data: reports } = await api(getState).get('/api/v1/admin/reports', { params });
reports.forEach((report: APIEntity) => {
dispatch(importFetchedAccount(report.account?.account));
dispatch(importFetchedAccount(report.target_account?.account));
dispatch(importFetchedStatuses(report.statuses));
});
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
} catch (error) {
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
}
};
}
const patchMastodonReports = (reports: { id: string; state: string }[]) =>
(dispatch: AppDispatch, getState: () => RootState) =>
Promise.all(reports.map(({ id, state }) => api(getState)
.post(`/api/v1/admin/reports/${id}/${state === 'resolved' ? 'reopen' : 'resolve'}`)
.then(() => {
dispatch({ type: ADMIN_REPORTS_PATCH_SUCCESS, reports });
}).catch(error => {
dispatch({ type: ADMIN_REPORTS_PATCH_FAIL, error, reports });
}),
));
const patchPleromaReports = (reports: { id: string; state: string }[]) =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
.patch('/api/v1/pleroma/admin/reports', { reports })
.then(() => {
dispatch({ type: ADMIN_REPORTS_PATCH_SUCCESS, reports });
}).catch(error => {
dispatch({ type: ADMIN_REPORTS_PATCH_FAIL, error, reports });
});
const patchReports = (ids: string[], reportState: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const instance = state.instance;
const features = getFeatures(instance);
function patchReports(ids: string[], reportState: string) {
return (dispatch: AppDispatch, getState: () => RootState) => {
const reports = ids.map(id => ({ id, state: reportState }));
dispatch({ type: ADMIN_REPORTS_PATCH_REQUEST, reports });
if (features.mastodonAdmin) {
return dispatch(patchMastodonReports(reports));
} else {
return dispatch(patchPleromaReports(reports));
}
return Promise.all(
reports.map(async ({ id, state }) => {
try {
await api(getState).post(`/api/v1/admin/reports/${id}/${state === 'resolved' ? 'reopen' : 'resolve'}`);
dispatch({ type: ADMIN_REPORTS_PATCH_SUCCESS, reports });
} catch (error) {
dispatch({ type: ADMIN_REPORTS_PATCH_FAIL, error, reports });
}
},
),
);
};
}
const closeReports = (ids: string[]) =>
patchReports(ids, 'closed');
function closeReports(ids: string[]) {
return patchReports(ids, 'closed');
}
function fetchUsers(filters: string[] = [], page = 1, query?: string | null, pageSize = 50, url?: string | null) {
return async (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
const fetchMastodonUsers = (filters: string[], page: number, query: string | null | undefined, pageSize: number, next?: string | null) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const params: Record<string, any> = {
username: query,
};
@ -220,106 +171,53 @@ const fetchMastodonUsers = (filters: string[], page: number, query: string | nul
if (filters.includes('active')) params.active = true;
if (filters.includes('need_approval')) params.pending = true;
return api(getState)
.get(next || '/api/v1/admin/accounts', { params })
.then(({ data: accounts, ...response }) => {
const next = getLinks(response as AxiosResponse<any, any>).refs.find(link => link.rel === 'next');
try {
const { data: accounts, ...response } = await api(getState).get(url || '/api/v1/admin/accounts', { params });
const next = getLinks(response as AxiosResponse<any, any>).refs.find(link => link.rel === 'next');
const count = next
? page * pageSize + 1
: (page - 1) * pageSize + accounts.length;
const count = next
? page * pageSize + 1
: (page - 1) * pageSize + accounts.length;
dispatch(importFetchedAccounts(accounts.map(({ account }: APIEntity) => account)));
dispatch(fetchRelationships(accounts.map((account: APIEntity) => account.id)));
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users: accounts, count, pageSize, filters, page, next: next?.uri || false });
return { users: accounts, count, pageSize, next: next?.uri || false };
}).catch(error =>
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize }),
);
};
const fetchPleromaUsers = (filters: string[], page: number, query?: string | null, pageSize?: number) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const params: Record<string, any> = { filters: filters.join(), page, page_size: pageSize };
if (query) params.query = query;
return api(getState)
.get('/api/v1/pleroma/admin/users', { params })
.then(({ data: { users, count, page_size: pageSize } }) => {
dispatch(fetchRelationships(users.map((user: APIEntity) => user.id)));
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users, count, pageSize, filters, page });
return { users, count, pageSize };
}).catch(error =>
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize }),
);
};
const fetchUsers = (filters: string[] = [], page = 1, query?: string | null, pageSize = 50, next?: string | null) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const instance = state.instance;
const features = getFeatures(instance);
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
if (features.mastodonAdmin) {
return dispatch(fetchMastodonUsers(filters, page, query, pageSize, next));
} else {
return dispatch(fetchPleromaUsers(filters, page, query, pageSize));
dispatch(importFetchedAccounts(accounts.map(({ account }: APIEntity) => account)));
dispatch(fetchRelationships(accounts.map((account_1: APIEntity) => account_1.id)));
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users: accounts, count, pageSize, filters, page, next: next?.uri || false });
return { users: accounts, count, pageSize, next: next?.uri || false };
} catch (error) {
return dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize });
}
};
}
const revokeName = (accountId: string, reportId?: string) =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
.post(`/api/v1/admin/accounts/${accountId}/action`, {
type: 'revoke_name',
report_id: reportId,
});
function revokeName(accountId: string, reportId?: string) {
return (_dispatch: AppDispatch, getState: () => RootState) => {
const params = {
type: 'revoke_name',
report_id: reportId,
};
const deactivateMastodonUsers = (accountIds: string[], reportId?: string) =>
(dispatch: AppDispatch, getState: () => RootState) =>
Promise.all(accountIds.map(accountId => {
api(getState)
.post(`/api/v1/admin/accounts/${accountId}/action`, {
return api(getState).post(`/api/v1/admin/accounts/${accountId}/action`, params);
};
}
function deactivateUsers(accountIds: string[], reportId?: string) {
return (dispatch: AppDispatch, getState: () => RootState) => {
return Promise.all(
accountIds.map(async (accountId) => {
const params = {
type: 'disable',
report_id: reportId,
})
.then(() => {
};
try {
await api(getState).post(`/api/v1/admin/accounts/${accountId}/action`, params);
dispatch({ type: ADMIN_USERS_DEACTIVATE_SUCCESS, accountIds: [accountId] });
}).catch(error => {
} catch (error) {
dispatch({ type: ADMIN_USERS_DEACTIVATE_FAIL, error, accountIds: [accountId] });
});
}));
const deactivatePleromaUsers = (accountIds: string[]) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const nicknames = accountIdsToAccts(getState(), accountIds);
return api(getState)
.patch('/api/v1/pleroma/admin/users/deactivate', { nicknames })
.then(({ data: { users } }) => {
dispatch({ type: ADMIN_USERS_DEACTIVATE_SUCCESS, users, accountIds });
}).catch(error => {
dispatch({ type: ADMIN_USERS_DEACTIVATE_FAIL, error, accountIds });
});
};
const deactivateUsers = (accountIds: string[], reportId?: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const instance = state.instance;
const features = getFeatures(instance);
dispatch({ type: ADMIN_USERS_DEACTIVATE_REQUEST, accountIds });
if (features.mastodonAdmin) {
return dispatch(deactivateMastodonUsers(accountIds, reportId));
} else {
return dispatch(deactivatePleromaUsers(accountIds));
}
}
}),
);
};
}
const deleteUser = (accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
@ -334,69 +232,31 @@ const deleteUser = (accountId: string) =>
});
};
const approveMastodonUser = (accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
.post(`/api/v1/admin/accounts/${accountId}/approve`)
.then(({ data: user }) => {
dispatch({ type: ADMIN_USERS_APPROVE_SUCCESS, user, accountId });
}).catch(error => {
dispatch({ type: ADMIN_USERS_APPROVE_FAIL, error, accountId });
});
const approvePleromaUser = (accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const nicknames = accountIdsToAccts(getState(), [accountId]);
return api(getState)
.patch('/api/v1/pleroma/admin/users/approve', { nicknames })
.then(({ data: { users } }) => {
dispatch({ type: ADMIN_USERS_APPROVE_SUCCESS, user: users[0], accountId });
}).catch(error => {
dispatch({ type: ADMIN_USERS_APPROVE_FAIL, error, accountId });
});
};
const rejectMastodonUser = (accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
.post(`/api/v1/admin/accounts/${accountId}/reject`)
.then(({ data: user }) => {
dispatch({ type: ADMIN_USERS_REJECT_SUCCESS, user, accountId });
}).catch(error => {
dispatch({ type: ADMIN_USERS_REJECT_FAIL, error, accountId });
});
const approveUser = (accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const instance = state.instance;
const features = getFeatures(instance);
function approveUser(accountId: string) {
return async (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: ADMIN_USERS_APPROVE_REQUEST, accountId });
if (features.mastodonAdmin) {
return dispatch(approveMastodonUser(accountId));
} else {
return dispatch(approvePleromaUser(accountId));
try {
const { data: user } = await api(getState)
.post(`/api/v1/admin/accounts/${accountId}/approve`);
dispatch({ type: ADMIN_USERS_APPROVE_SUCCESS, user, accountId });
} catch (error) {
dispatch({ type: ADMIN_USERS_APPROVE_FAIL, error, accountId });
}
};
}
const rejectUser = (accountId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const instance = state.instance;
const features = getFeatures(instance);
function rejectUser(accountId: string) {
return async (dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: ADMIN_USERS_REJECT_REQUEST, accountId });
if (features.mastodonAdmin) {
return dispatch(rejectMastodonUser(accountId));
} else {
return dispatch(deleteUser(accountId));
try {
const { data: user } = await api(getState)
.post(`/api/v1/admin/accounts/${accountId}/reject`);
dispatch({ type: ADMIN_USERS_REJECT_SUCCESS, user, accountId });
} catch (error) {
dispatch({ type: ADMIN_USERS_REJECT_FAIL, error, accountId });
}
};
}
const deleteStatus = (id: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {