diff --git a/src/components/LoginPage.js b/src/components/LoginPage.js index ad8cf94..e629e5c 100644 --- a/src/components/LoginPage.js +++ b/src/components/LoginPage.js @@ -169,7 +169,7 @@ const LoginPage = ({ theme }) => { : typeof error === "undefined" || !error.message ? "ra.auth.sign_in_error" : error.message, - "warning" + { type: "warning" } ); }); }; diff --git a/src/components/RoomDirectory.js b/src/components/RoomDirectory.js index de602e9..b33a28b 100644 --- a/src/components/RoomDirectory.js +++ b/src/components/RoomDirectory.js @@ -86,7 +86,9 @@ export const RoomDirectoryBulkSaveButton = ({ selectedIds }) => { refresh(); }, onFailure: error => - notify("resources.room_directory.action.send_failure", "error"), + notify("resources.room_directory.action.send_failure", { + type: "error", + }), } ); }; @@ -118,7 +120,9 @@ export const RoomDirectorySaveButton = ({ record }) => { refresh(); }, onFailure: error => - notify("resources.room_directory.action.send_failure", "error"), + notify("resources.room_directory.action.send_failure", { + type: "error", + }), } ); }; diff --git a/src/components/ServerNotices.js b/src/components/ServerNotices.js index 67d6334..2c10307 100644 --- a/src/components/ServerNotices.js +++ b/src/components/ServerNotices.js @@ -83,7 +83,9 @@ export const ServerNoticeButton = ({ record }) => { handleDialogClose(); }, onFailure: () => - notify("resources.servernotices.action.send_failure", "error"), + notify("resources.servernotices.action.send_failure", { + type: "error", + }), } ); }; @@ -129,7 +131,9 @@ export const ServerNoticeBulkButton = ({ selectedIds }) => { handleDialogClose(); }, onFailure: error => - notify("resources.servernotices.action.send_failure", "error"), + notify("resources.servernotices.action.send_failure", { + type: "error", + }), } ); }; diff --git a/src/components/devices.js b/src/components/devices.js index 41c5918..fcc8684 100644 --- a/src/components/devices.js +++ b/src/components/devices.js @@ -1,11 +1,5 @@ import React, { Fragment, useState } from "react"; -import { - Button, - useMutation, - useNotify, - Confirm, - useRefresh, -} from "react-admin"; +import { Button, useDelete, useNotify, Confirm, useRefresh } from "react-admin"; import ActionDelete from "@mui/icons-material/Delete"; import { makeStyles } from "@material-ui/core/styles"; import { alpha } from "@mui/material/styles"; @@ -34,7 +28,7 @@ export const DeviceRemoveButton = props => { const refresh = useRefresh(); const notify = useNotify(); - const [removeDevice, { loading }] = useMutation(); + const [removeDevice, { isLoading }] = useDelete("devices"); if (!record) return null; @@ -43,21 +37,15 @@ export const DeviceRemoveButton = props => { const handleConfirm = () => { removeDevice( - { - type: "delete", - resource: "devices", - payload: { - id: record.id, - user_id: record.user_id, - }, - }, + { payload: { id: record.id, user_id: record.user_id } }, { onSuccess: () => { notify("resources.devices.action.erase.success"); refresh(); }, - onFailure: () => - notify("resources.devices.action.erase.failure", "error"), + onFailure: () => { + notify("resources.devices.action.erase.failure", { type: "error" }); + }, } ); setOpen(false); @@ -74,7 +62,7 @@ export const DeviceRemoveButton = props => { { handleDialogClose(); }, onFailure: () => - notify("resources.delete_media.action.send_failure", "error"), + notify("resources.delete_media.action.send_failure", { + type: "error", + }), } ); }; @@ -172,7 +174,9 @@ export const ProtectMediaButton = props => { refresh(); }, onFailure: () => - notify("resources.protect_media.action.send_failure", "error"), + notify("resources.protect_media.action.send_failure", { + type: "error", + }), } ); }; @@ -186,7 +190,9 @@ export const ProtectMediaButton = props => { refresh(); }, onFailure: () => - notify("resources.protect_media.action.send_failure", "error"), + notify("resources.protect_media.action.send_failure", { + type: "error", + }), } ); }; @@ -264,7 +270,9 @@ export const QuarantineMediaButton = props => { refresh(); }, onFailure: () => - notify("resources.quarantine_media.action.send_failure", "error"), + notify("resources.quarantine_media.action.send_failure", { + type: "error", + }), } ); }; @@ -278,7 +286,9 @@ export const QuarantineMediaButton = props => { refresh(); }, onFailure: () => - notify("resources.quarantine_media.action.send_failure", "error"), + notify("resources.quarantine_media.action.send_failure", { + type: "error", + }), } ); }; diff --git a/src/synapse/dataProvider.js b/src/synapse/dataProvider.js index 3165f01..27ffc94 100644 --- a/src/synapse/dataProvider.js +++ b/src/synapse/dataProvider.js @@ -41,14 +41,16 @@ const resourceMap = { data: "users", total: json => json.total, create: data => ({ - endpoint: `/_synapse/admin/v2/users/@${data.id}:${localStorage.getItem( - "home_server" - )}`, + endpoint: `/_synapse/admin/v2/users/@${encodeURIComponent( + data.id + )}:${localStorage.getItem("home_server")}`, body: data, method: "PUT", }), delete: params => ({ - endpoint: `/_synapse/admin/v1/deactivate/${params.id}`, + endpoint: `/_synapse/admin/v1/deactivate/${encodeURIComponent( + params.id + )}`, body: { erase: true }, method: "POST", }), @@ -92,10 +94,12 @@ const resourceMap = { return json.total; }, reference: id => ({ - endpoint: `/_synapse/admin/v2/users/${id}/devices`, + endpoint: `/_synapse/admin/v2/users/${encodeURIComponent(id)}/devices`, }), delete: params => ({ - endpoint: `/_synapse/admin/v2/users/${params.user_id}/devices/${params.id}`, + endpoint: `/_synapse/admin/v2/users/${encodeURIComponent( + params.user_id + )}/devices/${params.id}`, }), }, connections: { @@ -137,7 +141,7 @@ const resourceMap = { id: p.pushkey, }), reference: id => ({ - endpoint: `/_synapse/admin/v1/users/${id}/pushers`, + endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(id)}/pushers`, }), data: "pushers", total: json => { @@ -149,7 +153,9 @@ const resourceMap = { id: jr, }), reference: id => ({ - endpoint: `/_synapse/admin/v1/users/${id}/joined_rooms`, + endpoint: `/_synapse/admin/v1/users/${encodeURIComponent( + id + )}/joined_rooms`, }), data: "joined_rooms", total: json => { @@ -162,7 +168,7 @@ const resourceMap = { id: um.media_id, }), reference: id => ({ - endpoint: `/_synapse/admin/v1/users/${id}/media`, + endpoint: `/_synapse/admin/v1/users/${encodeURIComponent(id)}/media`, }), data: "media", total: json => { @@ -355,9 +361,11 @@ const dataProvider = { const res = resourceMap[resource]; const endpoint_url = homeserver + res.path; - return jsonClient(`${endpoint_url}/${params.id}`).then(({ json }) => ({ - data: res.map(json), - })); + return jsonClient(`${endpoint_url}/${encodeURIComponent(params.id)}`).then( + ({ json }) => ({ + data: res.map(json), + }) + ); }, getMany: (resource, params) => { @@ -369,7 +377,9 @@ const dataProvider = { const endpoint_url = homeserver + res.path; return Promise.all( - params.ids.map(id => jsonClient(`${endpoint_url}/${id}`)) + params.ids.map(id => + jsonClient(`${endpoint_url}/${encodeURIComponent(id)}`) + ) ).then(responses => ({ data: responses.map(({ json }) => res.map(json)), total: responses.length, @@ -410,7 +420,7 @@ const dataProvider = { const res = resourceMap[resource]; const endpoint_url = homeserver + res.path; - return jsonClient(`${endpoint_url}/${params.data.id}`, { + return jsonClient(`${endpoint_url}/${encodeURIComponent(params.data.id)}`, { method: "PUT", body: JSON.stringify(params.data, filterNullValues), }).then(({ json }) => ({ @@ -427,10 +437,13 @@ const dataProvider = { const endpoint_url = homeserver + res.path; return Promise.all( - params.ids.map(id => jsonClient(`${endpoint_url}/${id}`), { - method: "PUT", - body: JSON.stringify(params.data, filterNullValues), - }) + params.ids.map( + id => jsonClient(`${endpoint_url}/${encodeURIComponent(id)}`), + { + method: "PUT", + body: JSON.stringify(params.data, filterNullValues), + } + ) ).then(responses => ({ data: responses.map(({ json }) => json), }));