2023-02-07 13:22:23 -08:00
|
|
|
import { defineMessages } from 'react-intl';
|
|
|
|
|
2021-07-13 13:16:31 -07:00
|
|
|
import { fetchRelationships } from 'soapbox/actions/accounts';
|
2022-05-15 06:11:59 -07:00
|
|
|
import { importFetchedAccount, importFetchedAccounts, importFetchedStatuses } from 'soapbox/actions/importer';
|
2023-02-07 13:22:23 -08:00
|
|
|
import toast from 'soapbox/toast';
|
2022-09-11 18:04:41 -07:00
|
|
|
import { filterBadges, getTagDiff } from 'soapbox/utils/badges';
|
2022-05-15 06:11:59 -07:00
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-05-15 06:11:59 -07:00
|
|
|
import api, { getLinks } from '../api';
|
2020-08-23 10:48:45 -07:00
|
|
|
|
2023-02-07 13:22:23 -08:00
|
|
|
import { openModal } from './modals';
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
import type { AxiosResponse } from 'axios';
|
|
|
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
2023-02-07 13:22:23 -08:00
|
|
|
import type { APIEntity, Announcement } from 'soapbox/types/entities';
|
2020-12-29 20:17:03 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_CONFIG_FETCH_REQUEST = 'ADMIN_CONFIG_FETCH_REQUEST';
|
|
|
|
const ADMIN_CONFIG_FETCH_SUCCESS = 'ADMIN_CONFIG_FETCH_SUCCESS';
|
|
|
|
const ADMIN_CONFIG_FETCH_FAIL = 'ADMIN_CONFIG_FETCH_FAIL';
|
2020-08-23 10:48:45 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_CONFIG_UPDATE_REQUEST = 'ADMIN_CONFIG_UPDATE_REQUEST';
|
|
|
|
const ADMIN_CONFIG_UPDATE_SUCCESS = 'ADMIN_CONFIG_UPDATE_SUCCESS';
|
|
|
|
const ADMIN_CONFIG_UPDATE_FAIL = 'ADMIN_CONFIG_UPDATE_FAIL';
|
2020-08-24 15:18:53 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_REPORTS_FETCH_REQUEST = 'ADMIN_REPORTS_FETCH_REQUEST';
|
|
|
|
const ADMIN_REPORTS_FETCH_SUCCESS = 'ADMIN_REPORTS_FETCH_SUCCESS';
|
|
|
|
const ADMIN_REPORTS_FETCH_FAIL = 'ADMIN_REPORTS_FETCH_FAIL';
|
2020-12-31 16:24:52 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_REPORTS_PATCH_REQUEST = 'ADMIN_REPORTS_PATCH_REQUEST';
|
|
|
|
const ADMIN_REPORTS_PATCH_SUCCESS = 'ADMIN_REPORTS_PATCH_SUCCESS';
|
|
|
|
const ADMIN_REPORTS_PATCH_FAIL = 'ADMIN_REPORTS_PATCH_FAIL';
|
2020-12-29 13:55:04 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_FETCH_REQUEST = 'ADMIN_USERS_FETCH_REQUEST';
|
|
|
|
const ADMIN_USERS_FETCH_SUCCESS = 'ADMIN_USERS_FETCH_SUCCESS';
|
|
|
|
const ADMIN_USERS_FETCH_FAIL = 'ADMIN_USERS_FETCH_FAIL';
|
2020-12-29 16:22:31 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_DELETE_REQUEST = 'ADMIN_USERS_DELETE_REQUEST';
|
|
|
|
const ADMIN_USERS_DELETE_SUCCESS = 'ADMIN_USERS_DELETE_SUCCESS';
|
|
|
|
const ADMIN_USERS_DELETE_FAIL = 'ADMIN_USERS_DELETE_FAIL';
|
2020-12-29 16:22:31 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_APPROVE_REQUEST = 'ADMIN_USERS_APPROVE_REQUEST';
|
|
|
|
const ADMIN_USERS_APPROVE_SUCCESS = 'ADMIN_USERS_APPROVE_SUCCESS';
|
|
|
|
const ADMIN_USERS_APPROVE_FAIL = 'ADMIN_USERS_APPROVE_FAIL';
|
2020-12-31 15:54:08 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_DEACTIVATE_REQUEST = 'ADMIN_USERS_DEACTIVATE_REQUEST';
|
|
|
|
const ADMIN_USERS_DEACTIVATE_SUCCESS = 'ADMIN_USERS_DEACTIVATE_SUCCESS';
|
|
|
|
const ADMIN_USERS_DEACTIVATE_FAIL = 'ADMIN_USERS_DEACTIVATE_FAIL';
|
2020-12-31 20:20:31 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_STATUS_DELETE_REQUEST = 'ADMIN_STATUS_DELETE_REQUEST';
|
|
|
|
const ADMIN_STATUS_DELETE_SUCCESS = 'ADMIN_STATUS_DELETE_SUCCESS';
|
|
|
|
const ADMIN_STATUS_DELETE_FAIL = 'ADMIN_STATUS_DELETE_FAIL';
|
2021-01-18 18:59:07 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST = 'ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST';
|
|
|
|
const ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS = 'ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS';
|
|
|
|
const ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL = 'ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL';
|
2021-01-01 10:50:13 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_LOG_FETCH_REQUEST = 'ADMIN_LOG_FETCH_REQUEST';
|
|
|
|
const ADMIN_LOG_FETCH_SUCCESS = 'ADMIN_LOG_FETCH_SUCCESS';
|
|
|
|
const ADMIN_LOG_FETCH_FAIL = 'ADMIN_LOG_FETCH_FAIL';
|
2021-03-15 19:50:16 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_TAG_REQUEST = 'ADMIN_USERS_TAG_REQUEST';
|
|
|
|
const ADMIN_USERS_TAG_SUCCESS = 'ADMIN_USERS_TAG_SUCCESS';
|
|
|
|
const ADMIN_USERS_TAG_FAIL = 'ADMIN_USERS_TAG_FAIL';
|
2021-03-15 19:50:16 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_UNTAG_REQUEST = 'ADMIN_USERS_UNTAG_REQUEST';
|
|
|
|
const ADMIN_USERS_UNTAG_SUCCESS = 'ADMIN_USERS_UNTAG_SUCCESS';
|
|
|
|
const ADMIN_USERS_UNTAG_FAIL = 'ADMIN_USERS_UNTAG_FAIL';
|
2021-07-13 10:21:12 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_ADD_PERMISSION_GROUP_REQUEST = 'ADMIN_ADD_PERMISSION_GROUP_REQUEST';
|
|
|
|
const ADMIN_ADD_PERMISSION_GROUP_SUCCESS = 'ADMIN_ADD_PERMISSION_GROUP_SUCCESS';
|
|
|
|
const ADMIN_ADD_PERMISSION_GROUP_FAIL = 'ADMIN_ADD_PERMISSION_GROUP_FAIL';
|
2021-07-13 10:21:12 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_REMOVE_PERMISSION_GROUP_REQUEST = 'ADMIN_REMOVE_PERMISSION_GROUP_REQUEST';
|
|
|
|
const ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS = 'ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS';
|
|
|
|
const ADMIN_REMOVE_PERMISSION_GROUP_FAIL = 'ADMIN_REMOVE_PERMISSION_GROUP_FAIL';
|
2021-11-26 21:36:17 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_SUGGEST_REQUEST = 'ADMIN_USERS_SUGGEST_REQUEST';
|
|
|
|
const ADMIN_USERS_SUGGEST_SUCCESS = 'ADMIN_USERS_SUGGEST_SUCCESS';
|
|
|
|
const ADMIN_USERS_SUGGEST_FAIL = 'ADMIN_USERS_SUGGEST_FAIL';
|
2021-11-26 21:36:17 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const ADMIN_USERS_UNSUGGEST_REQUEST = 'ADMIN_USERS_UNSUGGEST_REQUEST';
|
|
|
|
const ADMIN_USERS_UNSUGGEST_SUCCESS = 'ADMIN_USERS_UNSUGGEST_SUCCESS';
|
|
|
|
const ADMIN_USERS_UNSUGGEST_FAIL = 'ADMIN_USERS_UNSUGGEST_FAIL';
|
2021-07-13 10:21:12 -07:00
|
|
|
|
2023-02-07 13:22:23 -08:00
|
|
|
const ADMIN_USER_INDEX_EXPAND_FAIL = 'ADMIN_USER_INDEX_EXPAND_FAIL';
|
2022-12-25 15:31:07 -08:00
|
|
|
const ADMIN_USER_INDEX_EXPAND_REQUEST = 'ADMIN_USER_INDEX_EXPAND_REQUEST';
|
|
|
|
const ADMIN_USER_INDEX_EXPAND_SUCCESS = 'ADMIN_USER_INDEX_EXPAND_SUCCESS';
|
|
|
|
|
2023-02-07 13:22:23 -08:00
|
|
|
const ADMIN_USER_INDEX_FETCH_FAIL = 'ADMIN_USER_INDEX_FETCH_FAIL';
|
2022-12-25 15:31:07 -08:00
|
|
|
const ADMIN_USER_INDEX_FETCH_REQUEST = 'ADMIN_USER_INDEX_FETCH_REQUEST';
|
|
|
|
const ADMIN_USER_INDEX_FETCH_SUCCESS = 'ADMIN_USER_INDEX_FETCH_SUCCESS';
|
|
|
|
|
|
|
|
const ADMIN_USER_INDEX_QUERY_SET = 'ADMIN_USER_INDEX_QUERY_SET';
|
|
|
|
|
2023-02-07 13:22:23 -08:00
|
|
|
const ADMIN_ANNOUNCEMENTS_FETCH_FAIL = 'ADMIN_ANNOUNCEMENTS_FETCH_FAILS';
|
|
|
|
const ADMIN_ANNOUNCEMENTS_FETCH_REQUEST = 'ADMIN_ANNOUNCEMENTS_FETCH_REQUEST';
|
|
|
|
const ADMIN_ANNOUNCEMENTS_FETCH_SUCCESS = 'ADMIN_ANNOUNCEMENTS_FETCH_SUCCESS';
|
|
|
|
|
|
|
|
const ADMIN_ANNOUNCEMENTS_EXPAND_FAIL = 'ADMIN_ANNOUNCEMENTS_EXPAND_FAILS';
|
|
|
|
const ADMIN_ANNOUNCEMENTS_EXPAND_REQUEST = 'ADMIN_ANNOUNCEMENTS_EXPAND_REQUEST';
|
|
|
|
const ADMIN_ANNOUNCEMENTS_EXPAND_SUCCESS = 'ADMIN_ANNOUNCEMENTS_EXPAND_SUCCESS';
|
|
|
|
|
|
|
|
const ADMIN_ANNOUNCEMENT_CHANGE_CONTENT = 'ADMIN_ANNOUNCEMENT_CHANGE_CONTENT';
|
|
|
|
const ADMIN_ANNOUNCEMENT_CHANGE_START_TIME = 'ADMIN_ANNOUNCEMENT_CHANGE_START_TIME';
|
|
|
|
const ADMIN_ANNOUNCEMENT_CHANGE_END_TIME = 'ADMIN_ANNOUNCEMENT_CHANGE_END_TIME';
|
|
|
|
const ADMIN_ANNOUNCEMENT_CHANGE_ALL_DAY = 'ADMIN_ANNOUNCEMENT_CHANGE_ALL_DAY';
|
|
|
|
|
|
|
|
const ADMIN_ANNOUNCEMENT_CREATE_REQUEST = 'ADMIN_ANNOUNCEMENT_CREATE_REQUEST';
|
|
|
|
const ADMIN_ANNOUNCEMENT_CREATE_SUCCESS = 'ADMIN_ANNOUNCEMENT_CREATE_REQUEST';
|
|
|
|
const ADMIN_ANNOUNCEMENT_CREATE_FAIL = 'ADMIN_ANNOUNCEMENT_CREATE_FAIL';
|
|
|
|
|
|
|
|
const ADMIN_ANNOUNCEMENT_DELETE_REQUEST = 'ADMIN_ANNOUNCEMENT_DELETE_REQUEST';
|
|
|
|
const ADMIN_ANNOUNCEMENT_DELETE_SUCCESS = 'ADMIN_ANNOUNCEMENT_DELETE_REQUEST';
|
|
|
|
const ADMIN_ANNOUNCEMENT_DELETE_FAIL = 'ADMIN_ANNOUNCEMENT_DELETE_FAIL';
|
|
|
|
|
|
|
|
const ADMIN_ANNOUNCEMENT_MODAL_INIT = 'ADMIN_ANNOUNCEMENT_MODAL_INIT';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
announcementCreateSuccess: { id: 'admin.edit_announcement.created', defaultMessage: 'Announcement created' },
|
|
|
|
announcementDeleteSuccess: { id: 'admin.edit_announcement.deleted', defaultMessage: 'Announcement deleted' },
|
|
|
|
announcementUpdateSuccess: { id: 'admin.edit_announcement.updated', defaultMessage: 'Announcement edited' },
|
|
|
|
});
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const nicknamesFromIds = (getState: () => RootState, ids: string[]) => ids.map(id => getState().accounts.get(id)!.acct);
|
|
|
|
|
|
|
|
const fetchConfig = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2020-12-29 20:17:03 -08:00
|
|
|
dispatch({ type: ADMIN_CONFIG_FETCH_REQUEST });
|
|
|
|
return api(getState)
|
|
|
|
.get('/api/pleroma/admin/config')
|
|
|
|
.then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_CONFIG_FETCH_SUCCESS, configs: data.configs, needsReboot: data.need_reboot });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_CONFIG_FETCH_FAIL, error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const updateConfig = (configs: Record<string, any>[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2020-12-29 21:25:07 -08:00
|
|
|
dispatch({ type: ADMIN_CONFIG_UPDATE_REQUEST, configs });
|
2020-08-23 10:48:45 -07:00
|
|
|
return api(getState)
|
2020-12-29 21:25:07 -08:00
|
|
|
.post('/api/pleroma/admin/config', { configs })
|
2021-07-28 15:06:21 -07:00
|
|
|
.then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_CONFIG_UPDATE_SUCCESS, configs: data.configs, needsReboot: data.need_reboot });
|
2020-08-23 10:48:45 -07:00
|
|
|
}).catch(error => {
|
2021-07-28 15:06:21 -07:00
|
|
|
dispatch({ type: ADMIN_CONFIG_UPDATE_FAIL, error, configs });
|
2020-08-23 10:48:45 -07:00
|
|
|
});
|
|
|
|
};
|
2020-08-24 15:18:53 -07:00
|
|
|
|
2022-12-17 11:05:50 -08:00
|
|
|
const updateSoapboxConfig = (data: Record<string, any>) =>
|
|
|
|
(dispatch: AppDispatch, _getState: () => RootState) => {
|
|
|
|
const params = [{
|
|
|
|
group: ':pleroma',
|
|
|
|
key: ':frontend_configurations',
|
|
|
|
value: [{
|
|
|
|
tuple: [':soapbox_fe', data],
|
|
|
|
}],
|
|
|
|
}];
|
|
|
|
|
|
|
|
return dispatch(updateConfig(params));
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const fetchMastodonReports = (params: Record<string, any>) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) =>
|
|
|
|
api(getState)
|
2022-05-20 23:35:33 -07:00
|
|
|
.get('/api/v1/admin/reports', { params })
|
|
|
|
.then(({ data: reports }) => {
|
2022-06-20 06:46:43 -07:00
|
|
|
reports.forEach((report: APIEntity) => {
|
2022-05-20 23:35:33 -07:00
|
|
|
dispatch(importFetchedAccount(report.account?.account));
|
|
|
|
dispatch(importFetchedAccount(report.target_account?.account));
|
|
|
|
dispatch(importFetchedStatuses(report.statuses));
|
2022-05-15 06:11:59 -07:00
|
|
|
});
|
2022-05-20 23:35:33 -07:00
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
|
|
|
});
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const fetchPleromaReports = (params: Record<string, any>) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) =>
|
|
|
|
api(getState)
|
2022-05-20 23:35:33 -07:00
|
|
|
.get('/api/pleroma/admin/reports', { params })
|
2020-12-31 12:29:31 -08:00
|
|
|
.then(({ data: { reports } }) => {
|
2022-06-20 06:46:43 -07:00
|
|
|
reports.forEach((report: APIEntity) => {
|
2021-01-18 12:58:30 -08:00
|
|
|
dispatch(importFetchedAccount(report.account));
|
|
|
|
dispatch(importFetchedAccount(report.actor));
|
|
|
|
dispatch(importFetchedStatuses(report.statuses));
|
|
|
|
});
|
2020-12-31 12:29:31 -08:00
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_SUCCESS, reports, params });
|
2020-08-24 15:18:53 -07:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_FAIL, error, params });
|
|
|
|
});
|
2020-12-29 13:55:04 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const fetchReports = (params: Record<string, any> = {}) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const state = getState();
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const instance = state.instance;
|
2022-05-15 06:11:59 -07:00
|
|
|
const features = getFeatures(instance);
|
|
|
|
|
2022-05-20 23:35:33 -07:00
|
|
|
dispatch({ type: ADMIN_REPORTS_FETCH_REQUEST, params });
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
if (features.mastodonAdmin) {
|
2022-05-20 23:35:33 -07:00
|
|
|
return dispatch(fetchMastodonReports(params));
|
|
|
|
} else {
|
|
|
|
const { resolved } = params;
|
|
|
|
|
|
|
|
return dispatch(fetchPleromaReports({
|
|
|
|
state: resolved === false ? 'open' : (resolved ? 'resolved' : null),
|
|
|
|
}));
|
2022-05-15 06:11:59 -07:00
|
|
|
}
|
2022-05-20 23:35:33 -07:00
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const patchMastodonReports = (reports: { id: string, state: string }[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) =>
|
|
|
|
Promise.all(reports.map(({ id, state }) => api(getState)
|
2022-05-20 23:35:33 -07:00
|
|
|
.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 });
|
|
|
|
}),
|
|
|
|
));
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const patchPleromaReports = (reports: { id: string, state: string }[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) =>
|
|
|
|
api(getState)
|
2020-12-31 16:24:52 -08:00
|
|
|
.patch('/api/pleroma/admin/reports', { reports })
|
|
|
|
.then(() => {
|
|
|
|
dispatch({ type: ADMIN_REPORTS_PATCH_SUCCESS, reports });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_REPORTS_PATCH_FAIL, error, reports });
|
|
|
|
});
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const patchReports = (ids: string[], reportState: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const state = getState();
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const instance = state.instance;
|
2022-05-15 06:11:59 -07:00
|
|
|
const features = getFeatures(instance);
|
|
|
|
|
2022-05-20 23:35:33 -07:00
|
|
|
const reports = ids.map(id => ({ id, state: reportState }));
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_REPORTS_PATCH_REQUEST, reports });
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-04 23:45:51 -07:00
|
|
|
if (features.mastodonAdmin) {
|
2022-05-20 23:35:33 -07:00
|
|
|
return dispatch(patchMastodonReports(reports));
|
|
|
|
} else {
|
|
|
|
return dispatch(patchPleromaReports(reports));
|
2022-05-15 06:11:59 -07:00
|
|
|
}
|
2022-05-20 23:35:33 -07:00
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const closeReports = (ids: string[]) =>
|
|
|
|
patchReports(ids, 'closed');
|
2022-05-20 23:35:33 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const fetchMastodonUsers = (filters: string[], page: number, query: string | null | undefined, pageSize: number, next?: string | null) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
const params: Record<string, any> = {
|
2022-05-20 23:35:33 -07:00
|
|
|
username: query,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (filters.includes('local')) params.local = true;
|
|
|
|
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 }) => {
|
2022-06-20 06:46:43 -07:00
|
|
|
const next = getLinks(response as AxiosResponse<any, any>).refs.find(link => link.rel === 'next');
|
2022-05-20 23:35:33 -07:00
|
|
|
|
|
|
|
const count = next
|
|
|
|
? page * pageSize + 1
|
|
|
|
: (page - 1) * pageSize + accounts.length;
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
dispatch(importFetchedAccounts(accounts.map(({ account }: APIEntity) => account)));
|
|
|
|
dispatch(fetchRelationships(accounts.map((account: APIEntity) => account.id)));
|
2022-05-20 23:35:33 -07:00
|
|
|
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 };
|
2022-06-20 06:46:43 -07:00
|
|
|
}).catch(error =>
|
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize }),
|
|
|
|
);
|
2022-05-20 23:35:33 -07:00
|
|
|
};
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
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 };
|
2021-07-13 18:14:15 -07:00
|
|
|
if (query) params.query = query;
|
2021-07-13 15:27:11 -07:00
|
|
|
|
2020-12-29 13:55:04 -08:00
|
|
|
return api(getState)
|
|
|
|
.get('/api/pleroma/admin/users', { params })
|
2021-07-13 13:16:31 -07:00
|
|
|
.then(({ data: { users, count, page_size: pageSize } }) => {
|
2022-06-20 06:46:43 -07:00
|
|
|
dispatch(fetchRelationships(users.map((user: APIEntity) => user.id)));
|
2021-07-13 15:27:11 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users, count, pageSize, filters, page });
|
2021-07-13 15:01:31 -07:00
|
|
|
return { users, count, pageSize };
|
2022-06-20 06:46:43 -07:00
|
|
|
}).catch(error =>
|
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize }),
|
|
|
|
);
|
2020-12-29 13:55:04 -08:00
|
|
|
};
|
2020-12-29 16:22:31 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const fetchUsers = (filters: string[] = [], page = 1, query?: string | null, pageSize = 50, next?: string | null) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const state = getState();
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const instance = state.instance;
|
2022-05-15 06:11:59 -07:00
|
|
|
const features = getFeatures(instance);
|
|
|
|
|
2022-05-20 23:35:33 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
if (features.mastodonAdmin) {
|
2022-05-20 23:35:33 -07:00
|
|
|
return dispatch(fetchMastodonUsers(filters, page, query, pageSize, next));
|
|
|
|
} else {
|
|
|
|
return dispatch(fetchPleromaUsers(filters, page, query, pageSize));
|
2022-05-15 06:11:59 -07:00
|
|
|
}
|
2022-05-20 23:35:33 -07:00
|
|
|
};
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const deactivateMastodonUsers = (accountIds: string[], reportId?: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) =>
|
|
|
|
Promise.all(accountIds.map(accountId => {
|
2022-05-20 23:35:33 -07:00
|
|
|
api(getState)
|
|
|
|
.post(`/api/v1/admin/accounts/${accountId}/action`, {
|
|
|
|
type: 'disable',
|
|
|
|
report_id: reportId,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
dispatch({ type: ADMIN_USERS_DEACTIVATE_SUCCESS, accountIds: [accountId] });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_DEACTIVATE_FAIL, error, accountIds: [accountId] });
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const deactivatePleromaUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
2020-12-31 15:54:08 -08:00
|
|
|
return api(getState)
|
|
|
|
.patch('/api/pleroma/admin/users/deactivate', { nicknames })
|
|
|
|
.then(({ data: { users } }) => {
|
2021-07-13 16:11:11 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_DEACTIVATE_SUCCESS, users, accountIds });
|
2020-12-31 15:54:08 -08:00
|
|
|
}).catch(error => {
|
2021-07-13 16:11:11 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_DEACTIVATE_FAIL, error, accountIds });
|
2020-12-31 15:54:08 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const deactivateUsers = (accountIds: string[], reportId?: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-20 23:35:33 -07:00
|
|
|
const state = getState();
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const instance = state.instance;
|
2022-05-20 23:35:33 -07:00
|
|
|
const features = getFeatures(instance);
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USERS_DEACTIVATE_REQUEST, accountIds });
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
if (features.mastodonAdmin) {
|
2022-05-20 23:35:33 -07:00
|
|
|
return dispatch(deactivateMastodonUsers(accountIds, reportId));
|
|
|
|
} else {
|
|
|
|
return dispatch(deactivatePleromaUsers(accountIds));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const deleteUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-07-13 16:11:11 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
|
|
|
dispatch({ type: ADMIN_USERS_DELETE_REQUEST, accountIds });
|
2020-12-29 16:22:31 -08:00
|
|
|
return api(getState)
|
|
|
|
.delete('/api/pleroma/admin/users', { data: { nicknames } })
|
|
|
|
.then(({ data: nicknames }) => {
|
2021-07-13 16:11:11 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_DELETE_SUCCESS, nicknames, accountIds });
|
2020-12-29 16:22:31 -08:00
|
|
|
}).catch(error => {
|
2021-07-13 16:11:11 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_DELETE_FAIL, error, accountIds });
|
2020-12-29 16:22:31 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const approveMastodonUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) =>
|
|
|
|
Promise.all(accountIds.map(accountId => {
|
2022-05-20 23:35:33 -07:00
|
|
|
api(getState)
|
|
|
|
.post(`/api/v1/admin/accounts/${accountId}/approve`)
|
|
|
|
.then(({ data: user }) => {
|
|
|
|
dispatch({ type: ADMIN_USERS_APPROVE_SUCCESS, users: [user], accountIds: [accountId] });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_APPROVE_FAIL, error, accountIds: [accountId] });
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const approvePleromaUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-20 23:35:33 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
|
|
|
return api(getState)
|
|
|
|
.patch('/api/pleroma/admin/users/approve', { nicknames })
|
|
|
|
.then(({ data: { users } }) => {
|
|
|
|
dispatch({ type: ADMIN_USERS_APPROVE_SUCCESS, users, accountIds });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_APPROVE_FAIL, error, accountIds });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const approveUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2022-05-15 06:11:59 -07:00
|
|
|
const state = getState();
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const instance = state.instance;
|
2022-05-15 06:11:59 -07:00
|
|
|
const features = getFeatures(instance);
|
|
|
|
|
2021-07-13 16:11:11 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_APPROVE_REQUEST, accountIds });
|
2022-05-15 06:11:59 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
if (features.mastodonAdmin) {
|
2022-05-20 23:35:33 -07:00
|
|
|
return dispatch(approveMastodonUsers(accountIds));
|
|
|
|
} else {
|
|
|
|
return dispatch(approvePleromaUsers(accountIds));
|
2022-05-15 06:11:59 -07:00
|
|
|
}
|
2020-12-29 16:22:31 -08:00
|
|
|
};
|
2020-12-31 20:20:31 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const deleteStatus = (id: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2020-12-31 20:20:31 -08:00
|
|
|
dispatch({ type: ADMIN_STATUS_DELETE_REQUEST, id });
|
|
|
|
return api(getState)
|
|
|
|
.delete(`/api/pleroma/admin/statuses/${id}`)
|
|
|
|
.then(() => {
|
|
|
|
dispatch({ type: ADMIN_STATUS_DELETE_SUCCESS, id });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_STATUS_DELETE_FAIL, error, id });
|
|
|
|
});
|
|
|
|
};
|
2021-01-01 10:50:13 -08:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const toggleStatusSensitivity = (id: string, sensitive: boolean) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-01-18 18:59:07 -08:00
|
|
|
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST, id });
|
|
|
|
return api(getState)
|
|
|
|
.put(`/api/pleroma/admin/statuses/${id}`, { sensitive: !sensitive })
|
|
|
|
.then(() => {
|
|
|
|
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS, id });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL, error, id });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const fetchModerationLog = (params?: Record<string, any>) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-01-01 10:50:13 -08:00
|
|
|
dispatch({ type: ADMIN_LOG_FETCH_REQUEST });
|
|
|
|
return api(getState)
|
|
|
|
.get('/api/pleroma/admin/moderation_log', { params })
|
|
|
|
.then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_LOG_FETCH_SUCCESS, items: data.items, total: data.total });
|
|
|
|
return data;
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_LOG_FETCH_FAIL, error });
|
|
|
|
});
|
|
|
|
};
|
2021-03-15 19:50:16 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const tagUsers = (accountIds: string[], tags: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-07-13 10:21:12 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
2021-03-15 19:50:16 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_TAG_REQUEST, accountIds, tags });
|
|
|
|
return api(getState)
|
|
|
|
.put('/api/v1/pleroma/admin/users/tag', { nicknames, tags })
|
|
|
|
.then(() => {
|
|
|
|
dispatch({ type: ADMIN_USERS_TAG_SUCCESS, accountIds, tags });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_TAG_FAIL, error, accountIds, tags });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const untagUsers = (accountIds: string[], tags: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-07-13 10:21:12 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
2022-09-11 18:47:53 -07:00
|
|
|
|
|
|
|
// Legacy: allow removing legacy 'donor' tags.
|
|
|
|
if (tags.includes('badge:donor')) {
|
|
|
|
tags = [...tags, 'donor'];
|
|
|
|
}
|
|
|
|
|
2021-03-15 19:50:16 -07:00
|
|
|
dispatch({ type: ADMIN_USERS_UNTAG_REQUEST, accountIds, tags });
|
|
|
|
return api(getState)
|
|
|
|
.delete('/api/v1/pleroma/admin/users/tag', { data: { nicknames, tags } })
|
|
|
|
.then(() => {
|
|
|
|
dispatch({ type: ADMIN_USERS_UNTAG_SUCCESS, accountIds, tags });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_UNTAG_FAIL, error, accountIds, tags });
|
|
|
|
});
|
|
|
|
};
|
2021-07-13 10:21:12 -07:00
|
|
|
|
2022-09-11 18:04:41 -07:00
|
|
|
/** Synchronizes user tags to the backend. */
|
|
|
|
const setTags = (accountId: string, oldTags: string[], newTags: string[]) =>
|
2022-09-11 19:59:16 -07:00
|
|
|
async(dispatch: AppDispatch) => {
|
2022-09-11 18:04:41 -07:00
|
|
|
const diff = getTagDiff(oldTags, newTags);
|
|
|
|
|
2022-09-11 19:59:16 -07:00
|
|
|
await dispatch(tagUsers([accountId], diff.added));
|
|
|
|
await dispatch(untagUsers([accountId], diff.removed));
|
2022-09-11 18:04:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Synchronizes badges to the backend. */
|
|
|
|
const setBadges = (accountId: string, oldTags: string[], newTags: string[]) =>
|
|
|
|
(dispatch: AppDispatch) => {
|
|
|
|
const oldBadges = filterBadges(oldTags);
|
|
|
|
const newBadges = filterBadges(newTags);
|
|
|
|
|
|
|
|
return dispatch(setTags(accountId, oldBadges, newBadges));
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const verifyUser = (accountId: string) =>
|
|
|
|
(dispatch: AppDispatch) =>
|
|
|
|
dispatch(tagUsers([accountId], ['verified']));
|
2021-07-13 10:26:56 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const unverifyUser = (accountId: string) =>
|
|
|
|
(dispatch: AppDispatch) =>
|
|
|
|
dispatch(untagUsers([accountId], ['verified']));
|
2021-07-13 10:26:56 -07:00
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const addPermission = (accountIds: string[], permissionGroup: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-07-13 10:21:12 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
2021-07-13 10:34:58 -07:00
|
|
|
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_REQUEST, accountIds, permissionGroup });
|
2021-07-13 10:21:12 -07:00
|
|
|
return api(getState)
|
|
|
|
.post(`/api/v1/pleroma/admin/users/permission_group/${permissionGroup}`, { nicknames })
|
|
|
|
.then(({ data }) => {
|
2021-07-13 10:34:58 -07:00
|
|
|
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_SUCCESS, accountIds, permissionGroup, data });
|
2021-07-13 10:21:12 -07:00
|
|
|
}).catch(error => {
|
2021-07-13 10:34:58 -07:00
|
|
|
dispatch({ type: ADMIN_ADD_PERMISSION_GROUP_FAIL, error, accountIds, permissionGroup });
|
2021-07-13 10:21:12 -07:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const removePermission = (accountIds: string[], permissionGroup: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-07-13 10:21:12 -07:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
2021-07-13 10:34:58 -07:00
|
|
|
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_REQUEST, accountIds, permissionGroup });
|
2021-07-13 10:21:12 -07:00
|
|
|
return api(getState)
|
|
|
|
.delete(`/api/v1/pleroma/admin/users/permission_group/${permissionGroup}`, { data: { nicknames } })
|
|
|
|
.then(({ data }) => {
|
2021-07-13 10:34:58 -07:00
|
|
|
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS, accountIds, permissionGroup, data });
|
2021-07-13 10:21:12 -07:00
|
|
|
}).catch(error => {
|
2021-07-13 10:34:58 -07:00
|
|
|
dispatch({ type: ADMIN_REMOVE_PERMISSION_GROUP_FAIL, error, accountIds, permissionGroup });
|
2021-07-13 10:21:12 -07:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const promoteToAdmin = (accountId: string) =>
|
|
|
|
(dispatch: AppDispatch) =>
|
|
|
|
Promise.all([
|
2021-07-13 10:21:12 -07:00
|
|
|
dispatch(addPermission([accountId], 'admin')),
|
|
|
|
dispatch(removePermission([accountId], 'moderator')),
|
|
|
|
]);
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const promoteToModerator = (accountId: string) =>
|
|
|
|
(dispatch: AppDispatch) =>
|
|
|
|
Promise.all([
|
2021-07-13 10:21:12 -07:00
|
|
|
dispatch(removePermission([accountId], 'admin')),
|
|
|
|
dispatch(addPermission([accountId], 'moderator')),
|
|
|
|
]);
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const demoteToUser = (accountId: string) =>
|
|
|
|
(dispatch: AppDispatch) =>
|
|
|
|
Promise.all([
|
2021-07-13 10:21:12 -07:00
|
|
|
dispatch(removePermission([accountId], 'admin')),
|
|
|
|
dispatch(removePermission([accountId], 'moderator')),
|
|
|
|
]);
|
2021-11-26 21:36:17 -08:00
|
|
|
|
2022-09-11 11:19:08 -07:00
|
|
|
const setRole = (accountId: string, role: 'user' | 'moderator' | 'admin') =>
|
|
|
|
(dispatch: AppDispatch) => {
|
|
|
|
switch (role) {
|
|
|
|
case 'user':
|
|
|
|
return dispatch(demoteToUser(accountId));
|
|
|
|
case 'moderator':
|
|
|
|
return dispatch(promoteToModerator(accountId));
|
|
|
|
case 'admin':
|
|
|
|
return dispatch(promoteToAdmin(accountId));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const suggestUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-11-26 21:36:17 -08:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
|
|
|
dispatch({ type: ADMIN_USERS_SUGGEST_REQUEST, accountIds });
|
|
|
|
return api(getState)
|
|
|
|
.patch('/api/pleroma/admin/users/suggest', { nicknames })
|
|
|
|
.then(({ data: { users } }) => {
|
|
|
|
dispatch({ type: ADMIN_USERS_SUGGEST_SUCCESS, users, accountIds });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_SUGGEST_FAIL, error, accountIds });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
const unsuggestUsers = (accountIds: string[]) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
2021-11-26 21:36:17 -08:00
|
|
|
const nicknames = nicknamesFromIds(getState, accountIds);
|
|
|
|
dispatch({ type: ADMIN_USERS_UNSUGGEST_REQUEST, accountIds });
|
|
|
|
return api(getState)
|
|
|
|
.patch('/api/pleroma/admin/users/unsuggest', { nicknames })
|
|
|
|
.then(({ data: { users } }) => {
|
|
|
|
dispatch({ type: ADMIN_USERS_UNSUGGEST_SUCCESS, users, accountIds });
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_USERS_UNSUGGEST_FAIL, error, accountIds });
|
|
|
|
});
|
|
|
|
};
|
2022-06-20 06:46:43 -07:00
|
|
|
|
2022-12-25 15:31:07 -08:00
|
|
|
const setUserIndexQuery = (query: string) => ({ type: ADMIN_USER_INDEX_QUERY_SET, query });
|
|
|
|
|
|
|
|
const fetchUserIndex = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
const { filters, page, query, pageSize, isLoading } = getState().admin_user_index;
|
|
|
|
|
|
|
|
if (isLoading) return;
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_REQUEST });
|
|
|
|
|
|
|
|
dispatch(fetchUsers(filters.toJS() as string[], page + 1, query, pageSize))
|
|
|
|
.then((data: any) => {
|
|
|
|
if (data.error) {
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_FAIL });
|
|
|
|
} else {
|
|
|
|
const { users, count, next } = (data);
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_SUCCESS, users, count, next });
|
|
|
|
}
|
|
|
|
}).catch(() => {
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_FETCH_FAIL });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expandUserIndex = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
const { filters, page, query, pageSize, isLoading, next, loaded } = getState().admin_user_index;
|
|
|
|
|
|
|
|
if (!loaded || isLoading) return;
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_REQUEST });
|
|
|
|
|
|
|
|
dispatch(fetchUsers(filters.toJS() as string[], page + 1, query, pageSize, next))
|
|
|
|
.then((data: any) => {
|
|
|
|
if (data.error) {
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_FAIL });
|
|
|
|
} else {
|
|
|
|
const { users, count, next } = (data);
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_SUCCESS, users, count, next });
|
|
|
|
}
|
|
|
|
}).catch(() => {
|
|
|
|
dispatch({ type: ADMIN_USER_INDEX_EXPAND_FAIL });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-02-07 13:22:23 -08:00
|
|
|
const fetchAdminAnnouncements = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENTS_FETCH_REQUEST });
|
|
|
|
return api(getState)
|
|
|
|
.get('/api/pleroma/admin/announcements', { params: { limit: 50 } })
|
|
|
|
.then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENTS_FETCH_SUCCESS, announcements: data });
|
|
|
|
return data;
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENTS_FETCH_FAIL, error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const expandAdminAnnouncements = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
const page = getState().admin_announcements.page;
|
|
|
|
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENTS_EXPAND_REQUEST });
|
|
|
|
return api(getState)
|
|
|
|
.get('/api/pleroma/admin/announcements', { params: { limit: 50, offset: page * 50 } })
|
|
|
|
.then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENTS_EXPAND_SUCCESS, announcements: data });
|
|
|
|
return data;
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENTS_EXPAND_FAIL, error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const changeAnnouncementContent = (content: string) => ({
|
|
|
|
type: ADMIN_ANNOUNCEMENT_CHANGE_CONTENT,
|
|
|
|
value: content,
|
|
|
|
});
|
|
|
|
|
|
|
|
const changeAnnouncementStartTime = (time: Date | null) => ({
|
|
|
|
type: ADMIN_ANNOUNCEMENT_CHANGE_START_TIME,
|
|
|
|
value: time,
|
|
|
|
});
|
|
|
|
|
|
|
|
const changeAnnouncementEndTime = (time: Date | null) => ({
|
|
|
|
type: ADMIN_ANNOUNCEMENT_CHANGE_END_TIME,
|
|
|
|
value: time,
|
|
|
|
});
|
|
|
|
|
|
|
|
const changeAnnouncementAllDay = (allDay: boolean) => ({
|
|
|
|
type: ADMIN_ANNOUNCEMENT_CHANGE_ALL_DAY,
|
|
|
|
value: allDay,
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleCreateAnnouncement = () =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_CREATE_REQUEST });
|
|
|
|
|
|
|
|
const { id, content, starts_at, ends_at, all_day } = getState().admin_announcements.form;
|
|
|
|
|
|
|
|
return api(getState)[id ? 'patch' : 'post'](
|
|
|
|
id ? `/api/pleroma/admin/announcements/${id}` : '/api/pleroma/admin/announcements',
|
|
|
|
{ content, starts_at, ends_at, all_day },
|
|
|
|
).then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_CREATE_SUCCESS, announcement: data });
|
|
|
|
toast.success(id ? messages.announcementUpdateSuccess : messages.announcementCreateSuccess);
|
|
|
|
dispatch(fetchAdminAnnouncements());
|
|
|
|
return data;
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_CREATE_FAIL, error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const deleteAnnouncement = (id: string) =>
|
|
|
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_DELETE_REQUEST, id });
|
|
|
|
|
|
|
|
return api(getState).delete(`/api/pleroma/admin/announcements/${id}`).then(({ data }) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_DELETE_SUCCESS, id });
|
|
|
|
toast.success(messages.announcementDeleteSuccess);
|
|
|
|
dispatch(fetchAdminAnnouncements());
|
|
|
|
return data;
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_DELETE_FAIL, id, error });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const initAnnouncementModal = (announcement?: Announcement) =>
|
|
|
|
(dispatch: AppDispatch) => {
|
|
|
|
dispatch({ type: ADMIN_ANNOUNCEMENT_MODAL_INIT, announcement });
|
|
|
|
dispatch(openModal('EDIT_ANNOUNCEMENT'));
|
|
|
|
};
|
|
|
|
|
2022-06-20 06:46:43 -07:00
|
|
|
export {
|
|
|
|
ADMIN_CONFIG_FETCH_REQUEST,
|
|
|
|
ADMIN_CONFIG_FETCH_SUCCESS,
|
|
|
|
ADMIN_CONFIG_FETCH_FAIL,
|
|
|
|
ADMIN_CONFIG_UPDATE_REQUEST,
|
|
|
|
ADMIN_CONFIG_UPDATE_SUCCESS,
|
|
|
|
ADMIN_CONFIG_UPDATE_FAIL,
|
|
|
|
ADMIN_REPORTS_FETCH_REQUEST,
|
|
|
|
ADMIN_REPORTS_FETCH_SUCCESS,
|
|
|
|
ADMIN_REPORTS_FETCH_FAIL,
|
|
|
|
ADMIN_REPORTS_PATCH_REQUEST,
|
|
|
|
ADMIN_REPORTS_PATCH_SUCCESS,
|
|
|
|
ADMIN_REPORTS_PATCH_FAIL,
|
|
|
|
ADMIN_USERS_FETCH_REQUEST,
|
|
|
|
ADMIN_USERS_FETCH_SUCCESS,
|
|
|
|
ADMIN_USERS_FETCH_FAIL,
|
|
|
|
ADMIN_USERS_DELETE_REQUEST,
|
|
|
|
ADMIN_USERS_DELETE_SUCCESS,
|
|
|
|
ADMIN_USERS_DELETE_FAIL,
|
|
|
|
ADMIN_USERS_APPROVE_REQUEST,
|
|
|
|
ADMIN_USERS_APPROVE_SUCCESS,
|
|
|
|
ADMIN_USERS_APPROVE_FAIL,
|
|
|
|
ADMIN_USERS_DEACTIVATE_REQUEST,
|
|
|
|
ADMIN_USERS_DEACTIVATE_SUCCESS,
|
|
|
|
ADMIN_USERS_DEACTIVATE_FAIL,
|
|
|
|
ADMIN_STATUS_DELETE_REQUEST,
|
|
|
|
ADMIN_STATUS_DELETE_SUCCESS,
|
|
|
|
ADMIN_STATUS_DELETE_FAIL,
|
|
|
|
ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST,
|
|
|
|
ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS,
|
|
|
|
ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL,
|
|
|
|
ADMIN_LOG_FETCH_REQUEST,
|
|
|
|
ADMIN_LOG_FETCH_SUCCESS,
|
|
|
|
ADMIN_LOG_FETCH_FAIL,
|
|
|
|
ADMIN_USERS_TAG_REQUEST,
|
|
|
|
ADMIN_USERS_TAG_SUCCESS,
|
|
|
|
ADMIN_USERS_TAG_FAIL,
|
|
|
|
ADMIN_USERS_UNTAG_REQUEST,
|
|
|
|
ADMIN_USERS_UNTAG_SUCCESS,
|
|
|
|
ADMIN_USERS_UNTAG_FAIL,
|
|
|
|
ADMIN_ADD_PERMISSION_GROUP_REQUEST,
|
|
|
|
ADMIN_ADD_PERMISSION_GROUP_SUCCESS,
|
|
|
|
ADMIN_ADD_PERMISSION_GROUP_FAIL,
|
|
|
|
ADMIN_REMOVE_PERMISSION_GROUP_REQUEST,
|
|
|
|
ADMIN_REMOVE_PERMISSION_GROUP_SUCCESS,
|
|
|
|
ADMIN_REMOVE_PERMISSION_GROUP_FAIL,
|
|
|
|
ADMIN_USERS_SUGGEST_REQUEST,
|
|
|
|
ADMIN_USERS_SUGGEST_SUCCESS,
|
|
|
|
ADMIN_USERS_SUGGEST_FAIL,
|
|
|
|
ADMIN_USERS_UNSUGGEST_REQUEST,
|
|
|
|
ADMIN_USERS_UNSUGGEST_SUCCESS,
|
|
|
|
ADMIN_USERS_UNSUGGEST_FAIL,
|
2022-12-25 15:31:07 -08:00
|
|
|
ADMIN_USER_INDEX_EXPAND_FAIL,
|
|
|
|
ADMIN_USER_INDEX_EXPAND_REQUEST,
|
|
|
|
ADMIN_USER_INDEX_EXPAND_SUCCESS,
|
|
|
|
ADMIN_USER_INDEX_FETCH_FAIL,
|
|
|
|
ADMIN_USER_INDEX_FETCH_REQUEST,
|
|
|
|
ADMIN_USER_INDEX_FETCH_SUCCESS,
|
|
|
|
ADMIN_USER_INDEX_QUERY_SET,
|
2023-02-07 13:22:23 -08:00
|
|
|
ADMIN_ANNOUNCEMENTS_FETCH_FAIL,
|
|
|
|
ADMIN_ANNOUNCEMENTS_FETCH_REQUEST,
|
|
|
|
ADMIN_ANNOUNCEMENTS_FETCH_SUCCESS,
|
|
|
|
ADMIN_ANNOUNCEMENTS_EXPAND_FAIL,
|
|
|
|
ADMIN_ANNOUNCEMENTS_EXPAND_REQUEST,
|
|
|
|
ADMIN_ANNOUNCEMENTS_EXPAND_SUCCESS,
|
|
|
|
ADMIN_ANNOUNCEMENT_CHANGE_CONTENT,
|
|
|
|
ADMIN_ANNOUNCEMENT_CHANGE_START_TIME,
|
|
|
|
ADMIN_ANNOUNCEMENT_CHANGE_END_TIME,
|
|
|
|
ADMIN_ANNOUNCEMENT_CHANGE_ALL_DAY,
|
|
|
|
ADMIN_ANNOUNCEMENT_CREATE_FAIL,
|
|
|
|
ADMIN_ANNOUNCEMENT_CREATE_REQUEST,
|
|
|
|
ADMIN_ANNOUNCEMENT_CREATE_SUCCESS,
|
|
|
|
ADMIN_ANNOUNCEMENT_DELETE_FAIL,
|
|
|
|
ADMIN_ANNOUNCEMENT_DELETE_REQUEST,
|
|
|
|
ADMIN_ANNOUNCEMENT_DELETE_SUCCESS,
|
|
|
|
ADMIN_ANNOUNCEMENT_MODAL_INIT,
|
2022-06-20 06:46:43 -07:00
|
|
|
fetchConfig,
|
|
|
|
updateConfig,
|
2022-12-17 11:05:50 -08:00
|
|
|
updateSoapboxConfig,
|
2022-06-20 06:46:43 -07:00
|
|
|
fetchReports,
|
|
|
|
closeReports,
|
|
|
|
fetchUsers,
|
|
|
|
deactivateUsers,
|
|
|
|
deleteUsers,
|
|
|
|
approveUsers,
|
|
|
|
deleteStatus,
|
|
|
|
toggleStatusSensitivity,
|
|
|
|
fetchModerationLog,
|
|
|
|
tagUsers,
|
|
|
|
untagUsers,
|
2022-09-11 18:04:41 -07:00
|
|
|
setTags,
|
|
|
|
setBadges,
|
2022-06-20 06:46:43 -07:00
|
|
|
verifyUser,
|
|
|
|
unverifyUser,
|
|
|
|
addPermission,
|
|
|
|
removePermission,
|
|
|
|
promoteToAdmin,
|
|
|
|
promoteToModerator,
|
|
|
|
demoteToUser,
|
2022-09-11 11:19:08 -07:00
|
|
|
setRole,
|
2022-06-20 06:46:43 -07:00
|
|
|
suggestUsers,
|
|
|
|
unsuggestUsers,
|
2022-12-25 15:31:07 -08:00
|
|
|
setUserIndexQuery,
|
|
|
|
fetchUserIndex,
|
|
|
|
expandUserIndex,
|
2023-02-07 13:22:23 -08:00
|
|
|
fetchAdminAnnouncements,
|
|
|
|
expandAdminAnnouncements,
|
|
|
|
changeAnnouncementContent,
|
|
|
|
changeAnnouncementStartTime,
|
|
|
|
changeAnnouncementEndTime,
|
|
|
|
changeAnnouncementAllDay,
|
|
|
|
handleCreateAnnouncement,
|
|
|
|
deleteAnnouncement,
|
|
|
|
initAnnouncementModal,
|
2022-06-20 06:46:43 -07:00
|
|
|
};
|