Use correct API to suspend/unsuspend user (#607)
* Use correct API to suspend/unsuspend user * bring back suspend toggle * make linter happy
This commit is contained in:
committed by
GitHub
parent
5165625cd0
commit
ab247891dc
@@ -348,6 +348,10 @@ export interface SynapseDataProvider extends DataProvider {
|
||||
getAccountData: (id: Identifier) => Promise<AccountDataModel>;
|
||||
checkUsernameAvailability: (username: string) => Promise<UsernameAvailabilityResult>;
|
||||
makeRoomAdmin: (room_id: string, user_id: string) => Promise<{ success: boolean; error?: string; errcode?: string }>;
|
||||
suspendUser: (
|
||||
id: Identifier,
|
||||
suspendValue: boolean
|
||||
) => Promise<{ success: boolean; error?: string; errcode?: string }>;
|
||||
getServerRunningProcess: (etkeAdminUrl: string) => Promise<ServerProcessResponse>;
|
||||
getServerStatus: (etkeAdminUrl: string) => Promise<ServerStatusResponse>;
|
||||
getServerNotifications: (etkeAdminUrl: string) => Promise<ServerNotificationsResponse>;
|
||||
@@ -782,6 +786,7 @@ const baseDataProvider: SynapseDataProvider = {
|
||||
const res = resourceMap[resource];
|
||||
|
||||
const endpoint_url = homeserver + res.path;
|
||||
|
||||
const { json } = await jsonClient(`${endpoint_url}/${encodeURIComponent(params.id)}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(params.data, filterNullValues),
|
||||
@@ -1026,6 +1031,22 @@ const baseDataProvider: SynapseDataProvider = {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
suspendUser: async (id: Identifier, suspendValue: boolean) => {
|
||||
const base_url = localStorage.getItem("base_url");
|
||||
const endpoint_url = `${base_url}/_synapse/admin/v1/suspend/${encodeURIComponent(returnMXID(id))}`;
|
||||
try {
|
||||
const { json } = await jsonClient(endpoint_url, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ suspend: suspendValue }),
|
||||
});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
if (error instanceof HttpError) {
|
||||
return { success: false, error: error.body.error, errcode: error.body.errcode };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
getServerRunningProcess: async (etkeAdminUrl: string, burstCache = false): Promise<ServerProcessResponse> => {
|
||||
const locked_at = "";
|
||||
const command = "";
|
||||
@@ -1427,12 +1448,18 @@ const dataProvider = withLifecycleCallbacks(baseDataProvider, [
|
||||
const avatarFile = params.data.avatar_file?.rawFile;
|
||||
const avatarErase = params.data.avatar_erase;
|
||||
const rates = params.data.rates;
|
||||
const suspended = params.data.suspended;
|
||||
|
||||
if (rates) {
|
||||
await dataProvider.setRateLimits(params.id, rates);
|
||||
delete params.data.rates;
|
||||
}
|
||||
|
||||
if (suspended !== undefined) {
|
||||
await (dataProvider as SynapseDataProvider).suspendUser(params.id, suspended);
|
||||
delete params.data.suspended;
|
||||
}
|
||||
|
||||
if (avatarErase) {
|
||||
params.data.avatar_url = "";
|
||||
return params;
|
||||
|
||||
Reference in New Issue
Block a user