Merge branch 'master' into amp.chat
Change-Id: Iac4e56401aab3f7f39b623b617990ec1952f8cd0
This commit is contained in:
commit
e9c3901b68
@ -6,5 +6,6 @@
|
||||
"singleQuote": false,
|
||||
"trailingComma": "es5",
|
||||
"bracketSpacing": true,
|
||||
"jsxBracketSameLine": false
|
||||
"jsxBracketSameLine": false,
|
||||
"arrowParens": "avoid",
|
||||
}
|
||||
|
18
package.json
18
package.json
@ -10,14 +10,14 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^5.1.1",
|
||||
"@testing-library/react": "^9.4.0",
|
||||
"@testing-library/user-event": "^8.1.0",
|
||||
"@testing-library/react": "^10.0.2",
|
||||
"@testing-library/user-event": "^10.0.1",
|
||||
"enzyme": "^3.11.0",
|
||||
"enzyme-adapter-react-16": "^1.15.2",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.10.0",
|
||||
"eslint-config-prettier": "^6.10.1",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"prettier": "^1.19.1"
|
||||
"prettier": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@progress/kendo-drawing": "^1.6.0",
|
||||
@ -25,10 +25,10 @@
|
||||
"prop-types": "^15.7.2",
|
||||
"qrcode.react": "^1.0.0",
|
||||
"ra-language-german": "^2.1.2",
|
||||
"react": "^16.12.0",
|
||||
"react-admin": "^3.4",
|
||||
"react-dom": "^16.12.0",
|
||||
"react-scripts": "^3.3.0"
|
||||
"react": "^16.13.1",
|
||||
"react-admin": "^3.4.0",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "^3.4.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
@ -36,7 +36,7 @@
|
||||
"fix:other": "yarn prettier --write",
|
||||
"fix:code": "yarn test:lint --fix",
|
||||
"fix": "yarn fix:code && yarn fix:other",
|
||||
"prettier": "prettier \"**/*.{json,md,scss,yaml,yml}\"",
|
||||
"prettier": "prettier \"**/*.{js,jsx,json,md,scss,yaml,yml}\"",
|
||||
"test:code": "react-scripts test",
|
||||
"test:lint": "eslint --ignore-path .gitignore --ext .js,.jsx .",
|
||||
"test:style": "yarn prettier --list-different",
|
||||
|
@ -41,6 +41,7 @@ const App = () => (
|
||||
icon={UserIcon}
|
||||
/>
|
||||
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
||||
<Resource name="connections" />
|
||||
</Admin>
|
||||
);
|
||||
|
||||
|
@ -70,7 +70,7 @@ const LoginPage = ({ theme }) => {
|
||||
var locale = useLocale();
|
||||
const setLocale = useSetLocale();
|
||||
const translate = useTranslate();
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
|
||||
const renderInput = ({
|
||||
meta: { touched, error } = {},
|
||||
|
@ -2,7 +2,7 @@ import React, { useCallback } from "react";
|
||||
import { SaveButton, useCreate, useRedirect, useNotify } from "react-admin";
|
||||
|
||||
const SaveQrButton = props => {
|
||||
const [create] = useCreate('users');
|
||||
const [create] = useCreate("users");
|
||||
const redirectTo = useRedirect();
|
||||
const notify = useNotify();
|
||||
const { basePath } = props;
|
||||
@ -15,10 +15,13 @@ const SaveQrButton = props => {
|
||||
},
|
||||
{
|
||||
onSuccess: ({ data: newRecord }) => {
|
||||
notify('ra.notification.created', 'info', {
|
||||
notify("ra.notification.created", "info", {
|
||||
smart_count: 1,
|
||||
});
|
||||
redirectTo(redirect, basePath, newRecord.id, { password: values.password, ...newRecord });
|
||||
redirectTo(redirect, basePath, newRecord.id, {
|
||||
password: values.password,
|
||||
...newRecord,
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
@ -1,8 +1,12 @@
|
||||
import React from "react";
|
||||
import { Datagrid, List, TextField } from "react-admin";
|
||||
import { Datagrid, List, TextField, Pagination } from "react-admin";
|
||||
|
||||
const RoomPagination = props => (
|
||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||
);
|
||||
|
||||
export const RoomList = props => (
|
||||
<List {...props}>
|
||||
<List {...props} pagination={<RoomPagination />}>
|
||||
<Datagrid>
|
||||
<TextField source="room_id" />
|
||||
<TextField source="name" />
|
||||
|
@ -1,11 +1,20 @@
|
||||
import React from "react";
|
||||
import React, { Fragment } from "react";
|
||||
import PersonPinIcon from "@material-ui/icons/PersonPin";
|
||||
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
||||
import {
|
||||
ArrayInput,
|
||||
ArrayField,
|
||||
Datagrid,
|
||||
DateField,
|
||||
Create,
|
||||
Edit,
|
||||
List,
|
||||
Filter,
|
||||
Toolbar,
|
||||
SimpleForm,
|
||||
SimpleFormIterator,
|
||||
TabbedForm,
|
||||
FormTab,
|
||||
BooleanField,
|
||||
BooleanInput,
|
||||
ImageField,
|
||||
@ -14,12 +23,20 @@ import {
|
||||
TextInput,
|
||||
SearchInput,
|
||||
ReferenceField,
|
||||
SelectInput,
|
||||
BulkDeleteButton,
|
||||
DeleteButton,
|
||||
SaveButton,
|
||||
Toolbar,
|
||||
regex,
|
||||
useTranslate,
|
||||
Pagination,
|
||||
} from "react-admin";
|
||||
import SaveQrButton from "./SaveQrButton";
|
||||
|
||||
const UserPagination = props => (
|
||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||
);
|
||||
|
||||
const UserFilter = props => (
|
||||
<Filter {...props}>
|
||||
<SearchInput source="q" alwaysOn />
|
||||
@ -32,12 +49,26 @@ const UserFilter = props => (
|
||||
</Filter>
|
||||
);
|
||||
|
||||
const UserBulkActionButtons = props => {
|
||||
const translate = useTranslate();
|
||||
return (
|
||||
<Fragment>
|
||||
<BulkDeleteButton
|
||||
{...props}
|
||||
label="resources.users.action.erase"
|
||||
title={translate("resources.users.helper.erase")}
|
||||
/>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
export const UserList = props => (
|
||||
<List
|
||||
{...props}
|
||||
filters={<UserFilter />}
|
||||
filterDefaultValues={{ guests: true, deactivated: false }}
|
||||
bulkActionButtons={false}
|
||||
bulkActionButtons={<UserBulkActionButtons />}
|
||||
pagination={<UserPagination />}
|
||||
>
|
||||
<Datagrid rowClick="edit">
|
||||
<ReferenceField
|
||||
@ -140,6 +171,29 @@ const validateUser = regex(
|
||||
"synapseadmin.users.invalid_user_id"
|
||||
);
|
||||
|
||||
const UserEditToolbar = props => {
|
||||
const translate = useTranslate();
|
||||
return (
|
||||
<Toolbar {...props}>
|
||||
<SaveQrButton
|
||||
label="synapseadmin.action.save_and_show"
|
||||
redirect={redirect}
|
||||
submitOnEnter={true}
|
||||
/>
|
||||
<SaveButton
|
||||
label="synapseadmin.action.save_only"
|
||||
redirect="list"
|
||||
submitOnEnter={false}
|
||||
variant="text"
|
||||
/>
|
||||
<DeleteButton
|
||||
label="resources.users.action.erase"
|
||||
title={translate("resources.users.helper.erase")}
|
||||
/>
|
||||
</Toolbar>
|
||||
);
|
||||
};
|
||||
|
||||
export const UserCreate = props => (
|
||||
<Create record={generateRandomUser()} {...props}>
|
||||
<SimpleForm toolbar={<UserCreateToolbar />}>
|
||||
@ -147,18 +201,80 @@ export const UserCreate = props => (
|
||||
<TextInput source="displayname" />
|
||||
<PasswordInput source="password" autoComplete="new-password" />
|
||||
<BooleanInput source="admin" />
|
||||
<ArrayInput source="threepids">
|
||||
<SimpleFormIterator>
|
||||
<SelectInput
|
||||
source="medium"
|
||||
choices={[
|
||||
{ id: "email", name: "resources.users.email" },
|
||||
{ id: "msisdn", name: "resources.users.msisdn" },
|
||||
]}
|
||||
/>
|
||||
<TextInput source="address" />
|
||||
</SimpleFormIterator>
|
||||
</ArrayInput>
|
||||
</SimpleForm>
|
||||
</Create>
|
||||
);
|
||||
|
||||
export const UserEdit = props => (
|
||||
<Edit {...props}>
|
||||
<SimpleForm toolbar={<UserCreateToolbar />}>
|
||||
<TabbedForm toolbar={<UserEditToolbar />}>
|
||||
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
|
||||
<TextInput source="id" disabled />
|
||||
<TextInput source="displayname" />
|
||||
<PasswordInput source="password" autoComplete="new-password" />
|
||||
<BooleanInput source="admin" />
|
||||
<BooleanInput source="deactivated" />
|
||||
</SimpleForm>
|
||||
<BooleanInput
|
||||
source="deactivated"
|
||||
helperText="resources.users.helper.deactivate"
|
||||
/>
|
||||
<ArrayInput source="threepids">
|
||||
<SimpleFormIterator>
|
||||
<SelectInput
|
||||
source="medium"
|
||||
choices={[
|
||||
{ id: "email", name: "resources.users.email" },
|
||||
{ id: "msisdn", name: "resources.users.msisdn" },
|
||||
]}
|
||||
/>
|
||||
<TextInput source="address" />
|
||||
</SimpleFormIterator>
|
||||
</ArrayInput>
|
||||
</FormTab>
|
||||
<FormTab
|
||||
label="resources.connections.name"
|
||||
icon={<SettingsInputComponentIcon />}
|
||||
>
|
||||
<ReferenceField reference="connections" source="id" addLabel={false}>
|
||||
<ArrayField
|
||||
source="devices[].sessions[0].connections"
|
||||
label="resources.connections.name"
|
||||
>
|
||||
<Datagrid style={{ width: "100%" }}>
|
||||
<TextField source="ip" sortable={false} />
|
||||
<DateField
|
||||
source="last_seen"
|
||||
showTime
|
||||
options={{
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
}}
|
||||
sortable={false}
|
||||
/>
|
||||
<TextField
|
||||
source="user_agent"
|
||||
sortable={false}
|
||||
style={{ width: "100%" }}
|
||||
/>
|
||||
</Datagrid>
|
||||
</ArrayField>
|
||||
</ReferenceField>
|
||||
</FormTab>
|
||||
</TabbedForm>
|
||||
</Edit>
|
||||
);
|
||||
|
@ -19,7 +19,10 @@ export default {
|
||||
},
|
||||
resources: {
|
||||
users: {
|
||||
backtolist: "Zurück zur Liste",
|
||||
name: "Benutzer",
|
||||
email: "E-Mail",
|
||||
msisdn: "Telefon",
|
||||
fields: {
|
||||
avatar: "Avatar",
|
||||
id: "Benutzer-ID",
|
||||
@ -32,6 +35,17 @@ export default {
|
||||
user_id: "Suche Benutzer",
|
||||
displayname: "Anzeigename",
|
||||
password: "Passwort",
|
||||
avatar_url: "Avatar URL",
|
||||
medium: "Medium",
|
||||
threepids: "3PIDs",
|
||||
address: "Adresse",
|
||||
},
|
||||
helper: {
|
||||
deactivate: "Deaktivierte Nutzer können nicht wieder aktiviert werden.",
|
||||
erase: "DSGVO konformes Löschen der Benutzerdaten",
|
||||
},
|
||||
action: {
|
||||
erase: "Lösche Benutzerdaten",
|
||||
},
|
||||
},
|
||||
rooms: {
|
||||
@ -43,6 +57,14 @@ export default {
|
||||
joined_members: "Mitglieder",
|
||||
},
|
||||
},
|
||||
connections: {
|
||||
name: "Verbindungen",
|
||||
fields: {
|
||||
last_seen: "Datum",
|
||||
ip: "IP-Adresse",
|
||||
user_agent: "User Agent",
|
||||
},
|
||||
},
|
||||
},
|
||||
ra: {
|
||||
...germanMessages.ra,
|
||||
@ -52,7 +74,7 @@ export default {
|
||||
...germanMessages.ra.input.password,
|
||||
toggle_hidden: "Anzeigen",
|
||||
toggle_visible: "Verstecken",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -19,7 +19,10 @@ export default {
|
||||
},
|
||||
resources: {
|
||||
users: {
|
||||
backtolist: "Back to list",
|
||||
name: "User |||| Users",
|
||||
email: "Email",
|
||||
msisdn: "Phone",
|
||||
fields: {
|
||||
avatar: "Avatar",
|
||||
id: "User-ID",
|
||||
@ -32,6 +35,17 @@ export default {
|
||||
user_id: "Search user",
|
||||
displayname: "Displayname",
|
||||
password: "Password",
|
||||
avatar_url: "Avatar URL",
|
||||
medium: "Medium",
|
||||
threepids: "3PIDs",
|
||||
address: "Address",
|
||||
},
|
||||
helper: {
|
||||
deactivate: "Deactivated users cannot be reactivated",
|
||||
erase: "Mark the user as GDPR-erased",
|
||||
},
|
||||
action: {
|
||||
erase: "Erase user data",
|
||||
},
|
||||
},
|
||||
rooms: {
|
||||
@ -43,5 +57,13 @@ export default {
|
||||
joined_members: "Members",
|
||||
},
|
||||
},
|
||||
connections: {
|
||||
name: "Connections",
|
||||
fields: {
|
||||
last_seen: "Date",
|
||||
ip: "IP address",
|
||||
user_agent: "User agent",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -1,5 +1,20 @@
|
||||
import { fetchUtils } from "react-admin";
|
||||
|
||||
const ensureHttpsForUrl = url => {
|
||||
if (/^https:\/\//i.test(url)) {
|
||||
return url;
|
||||
}
|
||||
const domain = url.replace(/http.?:\/\//g, "");
|
||||
return "https://" + domain;
|
||||
};
|
||||
|
||||
const stripTrailingSlash = str => {
|
||||
if (!str) {
|
||||
return;
|
||||
}
|
||||
return str.endsWith("/") ? str.slice(0, -1) : str;
|
||||
};
|
||||
|
||||
const authProvider = {
|
||||
// called when the user attempts to log in
|
||||
login: ({ homeserver, username, password }) => {
|
||||
@ -13,16 +28,17 @@ const authProvider = {
|
||||
}),
|
||||
};
|
||||
|
||||
// add 'https://' to homeserver url if its missing
|
||||
let newUrl = window.decodeURIComponent(homeserver);
|
||||
newUrl = newUrl.trim().replace(/\s/g, "");
|
||||
if (!/^https?:\/\//i.test(newUrl)) {
|
||||
homeserver = `https://${newUrl}`;
|
||||
}
|
||||
const url = window.decodeURIComponent(homeserver);
|
||||
const trimmed_url = url.trim().replace(/\s/g, "");
|
||||
const login_api_url =
|
||||
ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login";
|
||||
|
||||
const url = homeserver + "/_matrix/client/r0/login";
|
||||
return fetchUtils.fetchJson(url, options).then(({ json }) => {
|
||||
localStorage.setItem("home_server", json.home_server);
|
||||
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
|
||||
const normalized_base_url = stripTrailingSlash(
|
||||
json.well_known["m.homeserver"].base_url
|
||||
);
|
||||
localStorage.setItem("base_url", normalized_base_url);
|
||||
localStorage.setItem("home_server_url", json.home_server);
|
||||
localStorage.setItem("user_id", json.user_id);
|
||||
localStorage.setItem("access_token", json.access_token);
|
||||
localStorage.setItem("device_id", json.device_id);
|
||||
|
@ -25,9 +25,16 @@ const resourceMap = {
|
||||
deactivated: !!u.deactivated,
|
||||
}),
|
||||
data: "users",
|
||||
total: (json, perPage) => {
|
||||
return parseInt(json.next_token, 10) + perPage;
|
||||
total: (json, from, perPage) => {
|
||||
return json.next_token
|
||||
? parseInt(json.next_token, 10) + perPage
|
||||
: from + json.users.length;
|
||||
},
|
||||
delete: id => ({
|
||||
endpoint: `/_synapse/admin/v1/deactivate/${id}`,
|
||||
body: { erase: true },
|
||||
method: "POST",
|
||||
}),
|
||||
},
|
||||
rooms: {
|
||||
path: "/_synapse/admin/v1/rooms",
|
||||
@ -42,6 +49,14 @@ const resourceMap = {
|
||||
return json.total_rooms;
|
||||
},
|
||||
},
|
||||
connections: {
|
||||
path: "/_synapse/admin/v1/whois",
|
||||
map: c => ({
|
||||
...c,
|
||||
id: c.user_id,
|
||||
}),
|
||||
data: "connections",
|
||||
},
|
||||
};
|
||||
|
||||
function filterNullValues(key, value) {
|
||||
@ -55,19 +70,22 @@ function filterNullValues(key, value) {
|
||||
const dataProvider = {
|
||||
getList: (resource, params) => {
|
||||
console.log("getList " + resource);
|
||||
const { user_id, guests } = params.filter;
|
||||
const { user_id, guests, deactivated } = params.filter;
|
||||
const { page, perPage } = params.pagination;
|
||||
const from = (page - 1) * perPage;
|
||||
const query = {
|
||||
from: (page - 1) * perPage,
|
||||
from: from,
|
||||
limit: perPage,
|
||||
user_id: user_id,
|
||||
guests: guests,
|
||||
deactivated: deactivated,
|
||||
};
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
const url = `${homeserver_url}?${stringify(query)}`;
|
||||
|
||||
// searching for users is not implemented in admin api
|
||||
@ -91,17 +109,18 @@ const dataProvider = {
|
||||
|
||||
return jsonClient(url).then(({ json }) => ({
|
||||
data: json[res.data].map(res.map),
|
||||
total: res.total(json, perPage),
|
||||
total: res.total(json, from, perPage),
|
||||
}));
|
||||
},
|
||||
|
||||
getOne: (resource, params) => {
|
||||
console.log("getOne " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return jsonClient(`${homeserver_url}/${params.id}`).then(({ json }) => ({
|
||||
data: res.map(json),
|
||||
}));
|
||||
@ -109,11 +128,12 @@ const dataProvider = {
|
||||
|
||||
getMany: (resource, params) => {
|
||||
console.log("getMany " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return Promise.all(
|
||||
params.ids.map(id => jsonClient(`${homeserver_url}/${id}`))
|
||||
).then(responses => ({
|
||||
@ -135,32 +155,28 @@ const dataProvider = {
|
||||
}),
|
||||
};
|
||||
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
const url = `${homeserver_url}?${stringify(query)}`;
|
||||
|
||||
return jsonClient(url).then(({ headers, json }) => ({
|
||||
data: json,
|
||||
total: parseInt(
|
||||
headers
|
||||
.get("content-range")
|
||||
.split("/")
|
||||
.pop(),
|
||||
10
|
||||
),
|
||||
total: parseInt(headers.get("content-range").split("/").pop(), 10),
|
||||
}));
|
||||
},
|
||||
|
||||
update: (resource, params) => {
|
||||
console.log("update " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return jsonClient(`${homeserver_url}/${params.data.id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(params.data, filterNullValues),
|
||||
@ -171,11 +187,12 @@ const dataProvider = {
|
||||
|
||||
updateMany: (resource, params) => {
|
||||
console.log("updateMany " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return Promise.all(
|
||||
params.ids.map(id => jsonClient(`${homeserver_url}/${id}`), {
|
||||
method: "PUT",
|
||||
@ -188,11 +205,12 @@ const dataProvider = {
|
||||
|
||||
create: (resource, params) => {
|
||||
console.log("create " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return jsonClient(`${homeserver_url}/${params.data.id}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(params.data, filterNullValues),
|
||||
@ -203,35 +221,64 @@ const dataProvider = {
|
||||
|
||||
delete: (resource, params) => {
|
||||
console.log("delete " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
return jsonClient(`${homeserver_url}/${params.id}`, {
|
||||
method: "DELETE",
|
||||
|
||||
if ("delete" in res) {
|
||||
const del = res["delete"](params.id);
|
||||
const homeserver_url = homeserver + del.endpoint;
|
||||
return jsonClient(homeserver_url, {
|
||||
method: del.method,
|
||||
body: JSON.stringify(del.body),
|
||||
}).then(({ json }) => ({
|
||||
data: json,
|
||||
}));
|
||||
} else {
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return jsonClient(`${homeserver_url}/${params.id}`, {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify(params.data, filterNullValues),
|
||||
}).then(({ json }) => ({
|
||||
data: json,
|
||||
}));
|
||||
}
|
||||
},
|
||||
|
||||
deleteMany: (resource, params) => {
|
||||
console.log("deleteMany " + resource);
|
||||
const homeserver = localStorage.getItem("home_server");
|
||||
const homeserver = localStorage.getItem("base_url");
|
||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||
|
||||
const res = resourceMap[resource];
|
||||
const homeserver_url = "https://" + homeserver + res.path;
|
||||
|
||||
if ("delete" in res) {
|
||||
return Promise.all(
|
||||
params.ids.map(id => {
|
||||
const del = res["delete"](id);
|
||||
const homeserver_url = homeserver + del.endpoint;
|
||||
return jsonClient(homeserver_url, {
|
||||
method: del.method,
|
||||
body: JSON.stringify(del.body),
|
||||
});
|
||||
})
|
||||
).then(responses => ({
|
||||
data: responses.map(({ json }) => json),
|
||||
}));
|
||||
} else {
|
||||
const homeserver_url = homeserver + res.path;
|
||||
return Promise.all(
|
||||
params.ids.map(id =>
|
||||
jsonClient(`${homeserver_url}/${id}`, {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify(params.data, filterNullValues),
|
||||
}).then(responses => ({
|
||||
data: responses.map(({ json }) => json),
|
||||
}))
|
||||
})
|
||||
)
|
||||
);
|
||||
).then(responses => ({
|
||||
data: responses.map(({ json }) => json),
|
||||
}));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user