mirror of
https://github.com/etkecc/synapse-admin.git
synced 2025-02-16 11:29:48 +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 },
|
{ ids: recordIds, meta: values },
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
notify("ra.notification.deleted", {
|
||||||
|
messageArgs: {
|
||||||
|
smart_count: recordIds.length,
|
||||||
|
},
|
||||||
|
type: 'info' as NotificationType,
|
||||||
|
});
|
||||||
handleDialogClose();
|
handleDialogClose();
|
||||||
unselectAll();
|
unselectAll();
|
||||||
redirect("/users");
|
redirect("/users");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
DataProvider,
|
DataProvider,
|
||||||
DeleteParams,
|
DeleteParams,
|
||||||
|
DeleteManyParams,
|
||||||
HttpError,
|
HttpError,
|
||||||
Identifier,
|
Identifier,
|
||||||
Options,
|
Options,
|
||||||
|
@ -288,24 +289,6 @@ const resourceMap = {
|
||||||
body: { erase: true },
|
body: { erase: true },
|
||||||
method: "POST",
|
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: {
|
rooms: {
|
||||||
path: "/_synapse/admin/v1/rooms",
|
path: "/_synapse/admin/v1/rooms",
|
||||||
|
@ -726,17 +709,6 @@ const baseDataProvider: SynapseDataProvider = {
|
||||||
method: "method" in del ? del.method : "DELETE",
|
method: "method" in del ? del.method : "DELETE",
|
||||||
body: "body" in del ? JSON.stringify(del.body) : null,
|
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 };
|
return { data: json };
|
||||||
} else {
|
} else {
|
||||||
const endpoint_url = homeserver + res.path;
|
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 {
|
return {
|
||||||
data: responses.map(({ json }) => json),
|
data: responses.map(({ json }) => json),
|
||||||
};
|
};
|
||||||
|
@ -859,6 +816,39 @@ const dataProvider = withLifecycleCallbacks(baseDataProvider, [
|
||||||
}
|
}
|
||||||
return params;
|
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…
Add table
Reference in a new issue