mirror of
https://github.com/etkecc/synapse-admin.git
synced 2024-11-21 15:25:22 +03:00
refactor users' after delete to react-admin lifecycle hooks, fixes #50
This commit is contained in:
parent
f3080e9468
commit
46cc0e2fda
2 changed files with 40 additions and 44 deletions
|
@ -35,6 +35,12 @@ const DeleteUserButton: React.FC<DeleteUserButtonProps> = (props) => {
|
|||
{ ids: recordIds, meta: values },
|
||||
{
|
||||
onSuccess: () => {
|
||||
notify("ra.notification.deleted", {
|
||||
messageArgs: {
|
||||
smart_count: recordIds.length,
|
||||
},
|
||||
type: 'info' as NotificationType,
|
||||
});
|
||||
handleDialogClose();
|
||||
unselectAll();
|
||||
redirect("/users");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
DataProvider,
|
||||
DeleteParams,
|
||||
DeleteManyParams,
|
||||
HttpError,
|
||||
Identifier,
|
||||
Options,
|
||||
|
@ -288,24 +289,6 @@ const resourceMap = {
|
|||
body: { erase: true },
|
||||
method: "POST",
|
||||
}),
|
||||
afterDelete: (params: DeleteParams) => {
|
||||
let actions : Action[] = [];
|
||||
if (params.meta?.deleteMedia) {
|
||||
actions.push({
|
||||
endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(returnMXID(params.id))}/media`,
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
if (params.meta?.redactEvents) {
|
||||
actions.push({
|
||||
endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(returnMXID(params.id))}/redact`,
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
return actions;
|
||||
},
|
||||
},
|
||||
rooms: {
|
||||
path: "/_synapse/admin/v1/rooms",
|
||||
|
@ -726,17 +709,6 @@ const baseDataProvider: SynapseDataProvider = {
|
|||
method: "method" in del ? del.method : "DELETE",
|
||||
body: "body" in del ? JSON.stringify(del.body) : null,
|
||||
});
|
||||
|
||||
if ("afterDelete" in res) {
|
||||
const del = res.afterDelete(params);
|
||||
del.map(async action => {
|
||||
const endpoint_url = homeserver + action.endpoint;
|
||||
return jsonClient(endpoint_url, {
|
||||
method: "method" in action ? action.method : "DELETE",
|
||||
body: "body" in action ? JSON.stringify(action.body) : null,
|
||||
});
|
||||
});
|
||||
}
|
||||
return { data: json };
|
||||
} else {
|
||||
const endpoint_url = homeserver + res.path;
|
||||
|
@ -767,21 +739,6 @@ const baseDataProvider: SynapseDataProvider = {
|
|||
})
|
||||
);
|
||||
|
||||
if ("afterDelete" in res) {
|
||||
await Promise.all(
|
||||
params.ids.map(id => {
|
||||
const del = res.afterDelete({ ...params, id: id });
|
||||
del.map(async action => {
|
||||
const endpoint_url = homeserver + action.endpoint;
|
||||
return jsonClient(endpoint_url, {
|
||||
method: "method" in action ? action.method : "DELETE",
|
||||
body: "body" in action ? JSON.stringify(action.body) : null,
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
data: responses.map(({ json }) => json),
|
||||
};
|
||||
|
@ -859,6 +816,39 @@ const dataProvider = withLifecycleCallbacks(baseDataProvider, [
|
|||
}
|
||||
return params;
|
||||
},
|
||||
beforeDelete: async (params: DeleteParams<any>, dataProvider: DataProvider) => {
|
||||
if (params.meta?.deleteMedia) {
|
||||
const base_url = storage.getItem("base_url");
|
||||
const endpoint_url = `${base_url}/_synapse/admin/v1/users/${encodeURIComponent(returnMXID(params.id))}/media`;
|
||||
await jsonClient(endpoint_url, { method: "DELETE" });
|
||||
}
|
||||
|
||||
if (params.meta?.redactEvents) {
|
||||
const base_url = storage.getItem("base_url");
|
||||
const endpoint_url = `${base_url}/_synapse/admin/v1/users/${encodeURIComponent(returnMXID(params.id))}/redact`;
|
||||
await jsonClient(endpoint_url, { method: "POST" });
|
||||
}
|
||||
|
||||
return params;
|
||||
},
|
||||
beforeDeleteMany: async (params: DeleteManyParams<any>, dataProvider: DataProvider) => {
|
||||
await Promise.all(
|
||||
params.ids.map(async id => {
|
||||
if (params.meta?.deleteMedia) {
|
||||
const base_url = storage.getItem("base_url");
|
||||
const endpoint_url = `${base_url}/_synapse/admin/v1/users/${encodeURIComponent(returnMXID(id))}/media`;
|
||||
await jsonClient(endpoint_url, { method: "DELETE" });
|
||||
}
|
||||
|
||||
if (params.meta?.redactEvents) {
|
||||
const base_url = storage.getItem("base_url");
|
||||
const endpoint_url = `${base_url}/_synapse/admin/v1/users/${encodeURIComponent(returnMXID(id))}/redact`;
|
||||
await jsonClient(endpoint_url, { method: "POST" });
|
||||
}
|
||||
})
|
||||
);
|
||||
return params;
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue