Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e6e526e3c | ||
|
|
d812cff5fc | ||
|
|
a39033e25b | ||
|
|
b7f009e559 | ||
|
|
2240559f74 | ||
|
|
445c7fc327 | ||
|
|
965645874c | ||
|
|
185d71e5fc | ||
|
|
7ef6bc05c6 | ||
|
|
dfc643a10f | ||
|
|
fccf23c64c | ||
|
|
e4dd013c19 | ||
|
|
7eeb60539f | ||
|
|
d099e582e0 | ||
|
|
0a241539f2 | ||
|
|
316d674060 | ||
|
|
40b5031550 | ||
|
|
475aa11f06 |
@@ -6,5 +6,6 @@
|
|||||||
"singleQuote": false,
|
"singleQuote": false,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false
|
"jsxBracketSameLine": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
}
|
}
|
||||||
|
|||||||
18
package.json
18
package.json
@@ -10,22 +10,22 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/jest-dom": "^5.1.1",
|
"@testing-library/jest-dom": "^5.1.1",
|
||||||
"@testing-library/react": "^9.4.0",
|
"@testing-library/react": "^10.0.2",
|
||||||
"@testing-library/user-event": "^8.1.0",
|
"@testing-library/user-event": "^10.0.1",
|
||||||
"enzyme": "^3.11.0",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.2",
|
"enzyme-adapter-react-16": "^1.15.2",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"eslint-config-prettier": "^6.10.0",
|
"eslint-config-prettier": "^6.10.1",
|
||||||
"eslint-plugin-prettier": "^3.1.2",
|
"eslint-plugin-prettier": "^3.1.2",
|
||||||
"prettier": "^1.19.1"
|
"prettier": "^2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"ra-language-german": "^2.1.2",
|
"ra-language-german": "^2.1.2",
|
||||||
"react": "^16.12.0",
|
"react": "^16.13.1",
|
||||||
"react-admin": "^3.1.3",
|
"react-admin": "^3.4.0",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.13.1",
|
||||||
"react-scripts": "^3.3.0"
|
"react-scripts": "^3.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"fix:other": "yarn prettier --write",
|
"fix:other": "yarn prettier --write",
|
||||||
"fix:code": "yarn test:lint --fix",
|
"fix:code": "yarn test:lint --fix",
|
||||||
"fix": "yarn fix:code && yarn fix:other",
|
"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:code": "react-scripts test",
|
||||||
"test:lint": "eslint --ignore-path .gitignore --ext .js,.jsx .",
|
"test:lint": "eslint --ignore-path .gitignore --ext .js,.jsx .",
|
||||||
"test:style": "yarn prettier --list-different",
|
"test:style": "yarn prettier --list-different",
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const App = () => (
|
|||||||
icon={UserIcon}
|
icon={UserIcon}
|
||||||
/>
|
/>
|
||||||
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
||||||
|
<Resource name="connections" />
|
||||||
</Admin>
|
</Admin>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const LoginPage = ({ theme }) => {
|
|||||||
var locale = useLocale();
|
var locale = useLocale();
|
||||||
const setLocale = useSetLocale();
|
const setLocale = useSetLocale();
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
|
|
||||||
const renderInput = ({
|
const renderInput = ({
|
||||||
meta: { touched, error } = {},
|
meta: { touched, error } = {},
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import React from "react";
|
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 => (
|
export const RoomList = props => (
|
||||||
<List {...props}>
|
<List {...props} pagination={<RoomPagination />}>
|
||||||
<Datagrid>
|
<Datagrid>
|
||||||
<TextField source="room_id" />
|
<TextField source="room_id" />
|
||||||
<TextField source="name" />
|
<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 {
|
import {
|
||||||
|
ArrayInput,
|
||||||
|
ArrayField,
|
||||||
Datagrid,
|
Datagrid,
|
||||||
|
DateField,
|
||||||
Create,
|
Create,
|
||||||
Edit,
|
Edit,
|
||||||
List,
|
List,
|
||||||
Filter,
|
Filter,
|
||||||
|
Toolbar,
|
||||||
SimpleForm,
|
SimpleForm,
|
||||||
|
SimpleFormIterator,
|
||||||
|
TabbedForm,
|
||||||
|
FormTab,
|
||||||
BooleanField,
|
BooleanField,
|
||||||
BooleanInput,
|
BooleanInput,
|
||||||
ImageField,
|
ImageField,
|
||||||
@@ -13,9 +22,19 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
TextInput,
|
TextInput,
|
||||||
ReferenceField,
|
ReferenceField,
|
||||||
|
SelectInput,
|
||||||
|
BulkDeleteButton,
|
||||||
|
DeleteButton,
|
||||||
|
SaveButton,
|
||||||
regex,
|
regex,
|
||||||
|
useTranslate,
|
||||||
|
Pagination,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
|
|
||||||
|
const UserPagination = props => (
|
||||||
|
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||||
|
);
|
||||||
|
|
||||||
const UserFilter = props => (
|
const UserFilter = props => (
|
||||||
<Filter {...props}>
|
<Filter {...props}>
|
||||||
<BooleanInput source="guests" alwaysOn />
|
<BooleanInput source="guests" alwaysOn />
|
||||||
@@ -27,12 +46,26 @@ const UserFilter = props => (
|
|||||||
</Filter>
|
</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 => (
|
export const UserList = props => (
|
||||||
<List
|
<List
|
||||||
{...props}
|
{...props}
|
||||||
filters={<UserFilter />}
|
filters={<UserFilter />}
|
||||||
filterDefaultValues={{ guests: true, deactivated: false }}
|
filterDefaultValues={{ guests: true, deactivated: false }}
|
||||||
bulkActionButtons={false}
|
bulkActionButtons={<UserBulkActionButtons />}
|
||||||
|
pagination={<UserPagination />}
|
||||||
>
|
>
|
||||||
<Datagrid rowClick="edit">
|
<Datagrid rowClick="edit">
|
||||||
<ReferenceField
|
<ReferenceField
|
||||||
@@ -66,6 +99,19 @@ const validateUser = regex(
|
|||||||
"synapseadmin.users.invalid_user_id"
|
"synapseadmin.users.invalid_user_id"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const UserEditToolbar = props => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<Toolbar {...props}>
|
||||||
|
<SaveButton submitOnEnter={true} />
|
||||||
|
<DeleteButton
|
||||||
|
label="resources.users.action.erase"
|
||||||
|
title={translate("resources.users.helper.erase")}
|
||||||
|
/>
|
||||||
|
</Toolbar>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const UserCreate = props => (
|
export const UserCreate = props => (
|
||||||
<Create {...props}>
|
<Create {...props}>
|
||||||
<SimpleForm>
|
<SimpleForm>
|
||||||
@@ -73,18 +119,89 @@ export const UserCreate = props => (
|
|||||||
<TextInput source="displayname" />
|
<TextInput source="displayname" />
|
||||||
<PasswordInput source="password" autoComplete="new-password" />
|
<PasswordInput source="password" autoComplete="new-password" />
|
||||||
<BooleanInput source="admin" />
|
<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>
|
</SimpleForm>
|
||||||
</Create>
|
</Create>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const UserTitle = ({ record }) => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{translate("resources.users.name")}{" "}
|
||||||
|
{record ? `"${record.displayname}"` : ""}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
export const UserEdit = props => (
|
export const UserEdit = props => (
|
||||||
<Edit {...props}>
|
<Edit {...props} title={<UserTitle />}>
|
||||||
<SimpleForm>
|
<TabbedForm toolbar={<UserEditToolbar />}>
|
||||||
<TextInput source="id" disabled />
|
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
|
||||||
<TextInput source="displayname" />
|
<TextInput source="id" disabled />
|
||||||
<PasswordInput source="password" autoComplete="new-password" />
|
<TextInput source="displayname" />
|
||||||
<BooleanInput source="admin" />
|
<PasswordInput source="password" autoComplete="new-password" />
|
||||||
<BooleanInput source="deactivated" />
|
<BooleanInput source="admin" />
|
||||||
</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>
|
</Edit>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ export default {
|
|||||||
},
|
},
|
||||||
resources: {
|
resources: {
|
||||||
users: {
|
users: {
|
||||||
|
backtolist: "Zurück zur Liste",
|
||||||
name: "Benutzer",
|
name: "Benutzer",
|
||||||
|
email: "E-Mail",
|
||||||
|
msisdn: "Telefon",
|
||||||
fields: {
|
fields: {
|
||||||
avatar: "Avatar",
|
avatar: "Avatar",
|
||||||
id: "Benutzer-ID",
|
id: "Benutzer-ID",
|
||||||
@@ -27,6 +30,17 @@ export default {
|
|||||||
user_id: "Suche Benutzer",
|
user_id: "Suche Benutzer",
|
||||||
displayname: "Anzeigename",
|
displayname: "Anzeigename",
|
||||||
password: "Passwort",
|
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: {
|
rooms: {
|
||||||
@@ -38,5 +52,13 @@ export default {
|
|||||||
joined_members: "Mitglieder",
|
joined_members: "Mitglieder",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
connections: {
|
||||||
|
name: "Verbindungen",
|
||||||
|
fields: {
|
||||||
|
last_seen: "Datum",
|
||||||
|
ip: "IP-Adresse",
|
||||||
|
user_agent: "User Agent",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,10 @@ export default {
|
|||||||
},
|
},
|
||||||
resources: {
|
resources: {
|
||||||
users: {
|
users: {
|
||||||
|
backtolist: "Back to list",
|
||||||
name: "User |||| Users",
|
name: "User |||| Users",
|
||||||
|
email: "Email",
|
||||||
|
msisdn: "Phone",
|
||||||
fields: {
|
fields: {
|
||||||
avatar: "Avatar",
|
avatar: "Avatar",
|
||||||
id: "User-ID",
|
id: "User-ID",
|
||||||
@@ -27,6 +30,17 @@ export default {
|
|||||||
user_id: "Search user",
|
user_id: "Search user",
|
||||||
displayname: "Displayname",
|
displayname: "Displayname",
|
||||||
password: "Password",
|
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: {
|
rooms: {
|
||||||
@@ -38,5 +52,13 @@ export default {
|
|||||||
joined_members: "Members",
|
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";
|
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 = {
|
const authProvider = {
|
||||||
// called when the user attempts to log in
|
// called when the user attempts to log in
|
||||||
login: ({ homeserver, username, password }) => {
|
login: ({ homeserver, username, password }) => {
|
||||||
@@ -13,16 +28,17 @@ const authProvider = {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
// add 'https://' to homeserver url if its missing
|
const url = window.decodeURIComponent(homeserver);
|
||||||
let newUrl = window.decodeURIComponent(homeserver);
|
const trimmed_url = url.trim().replace(/\s/g, "");
|
||||||
newUrl = newUrl.trim().replace(/\s/g, "");
|
const login_api_url =
|
||||||
if (!/^https?:\/\//i.test(newUrl)) {
|
ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login";
|
||||||
homeserver = `https://${newUrl}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = homeserver + "/_matrix/client/r0/login";
|
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
|
||||||
return fetchUtils.fetchJson(url, options).then(({ json }) => {
|
const normalized_base_url = stripTrailingSlash(
|
||||||
localStorage.setItem("home_server", json.home_server);
|
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("user_id", json.user_id);
|
||||||
localStorage.setItem("access_token", json.access_token);
|
localStorage.setItem("access_token", json.access_token);
|
||||||
localStorage.setItem("device_id", json.device_id);
|
localStorage.setItem("device_id", json.device_id);
|
||||||
|
|||||||
@@ -25,9 +25,16 @@ const resourceMap = {
|
|||||||
deactivated: !!u.deactivated,
|
deactivated: !!u.deactivated,
|
||||||
}),
|
}),
|
||||||
data: "users",
|
data: "users",
|
||||||
total: (json, perPage) => {
|
total: (json, from, perPage) => {
|
||||||
return parseInt(json.next_token, 10) + 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: {
|
rooms: {
|
||||||
path: "/_synapse/admin/v1/rooms",
|
path: "/_synapse/admin/v1/rooms",
|
||||||
@@ -42,6 +49,14 @@ const resourceMap = {
|
|||||||
return json.total_rooms;
|
return json.total_rooms;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
connections: {
|
||||||
|
path: "/_synapse/admin/v1/whois",
|
||||||
|
map: c => ({
|
||||||
|
...c,
|
||||||
|
id: c.user_id,
|
||||||
|
}),
|
||||||
|
data: "connections",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function filterNullValues(key, value) {
|
function filterNullValues(key, value) {
|
||||||
@@ -55,48 +70,53 @@ function filterNullValues(key, value) {
|
|||||||
const dataProvider = {
|
const dataProvider = {
|
||||||
getList: (resource, params) => {
|
getList: (resource, params) => {
|
||||||
console.log("getList " + resource);
|
console.log("getList " + resource);
|
||||||
const { user_id, guests } = params.filter;
|
const { user_id, guests, deactivated } = params.filter;
|
||||||
const { page, perPage } = params.pagination;
|
const { page, perPage } = params.pagination;
|
||||||
|
const from = (page - 1) * perPage;
|
||||||
const query = {
|
const query = {
|
||||||
from: (page - 1) * perPage,
|
from: from,
|
||||||
limit: perPage,
|
limit: perPage,
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
guests: guests,
|
guests: guests,
|
||||||
|
deactivated: deactivated,
|
||||||
};
|
};
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
const url = `${homeserver_url}?${stringify(query)}`;
|
const endpoint_url = homeserver + res.path;
|
||||||
|
const url = `${endpoint_url}?${stringify(query)}`;
|
||||||
|
|
||||||
return jsonClient(url).then(({ json }) => ({
|
return jsonClient(url).then(({ json }) => ({
|
||||||
data: json[res.data].map(res.map),
|
data: json[res.data].map(res.map),
|
||||||
total: res.total(json, perPage),
|
total: res.total(json, from, perPage),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
getOne: (resource, params) => {
|
getOne: (resource, params) => {
|
||||||
console.log("getOne " + resource);
|
console.log("getOne " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
return jsonClient(`${homeserver_url}/${params.id}`).then(({ json }) => ({
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return jsonClient(`${endpoint_url}/${params.id}`).then(({ json }) => ({
|
||||||
data: res.map(json),
|
data: res.map(json),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
getMany: (resource, params) => {
|
getMany: (resource, params) => {
|
||||||
console.log("getMany " + resource);
|
console.log("getMany " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
params.ids.map(id => jsonClient(`${homeserver_url}/${id}`))
|
params.ids.map(id => jsonClient(`${endpoint_url}/${id}`))
|
||||||
).then(responses => ({
|
).then(responses => ({
|
||||||
data: responses.map(({ json }) => res.map(json)),
|
data: responses.map(({ json }) => res.map(json)),
|
||||||
}));
|
}));
|
||||||
@@ -116,33 +136,29 @@ const dataProvider = {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
const url = `${homeserver_url}?${stringify(query)}`;
|
const endpoint_url = homeserver + res.path;
|
||||||
|
const url = `${endpoint_url}?${stringify(query)}`;
|
||||||
|
|
||||||
return jsonClient(url).then(({ headers, json }) => ({
|
return jsonClient(url).then(({ headers, json }) => ({
|
||||||
data: json,
|
data: json,
|
||||||
total: parseInt(
|
total: parseInt(headers.get("content-range").split("/").pop(), 10),
|
||||||
headers
|
|
||||||
.get("content-range")
|
|
||||||
.split("/")
|
|
||||||
.pop(),
|
|
||||||
10
|
|
||||||
),
|
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
update: (resource, params) => {
|
update: (resource, params) => {
|
||||||
console.log("update " + resource);
|
console.log("update " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
return jsonClient(`${homeserver_url}/${params.data.id}`, {
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return jsonClient(`${endpoint_url}/${params.data.id}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
}).then(({ json }) => ({
|
}).then(({ json }) => ({
|
||||||
@@ -152,13 +168,14 @@ const dataProvider = {
|
|||||||
|
|
||||||
updateMany: (resource, params) => {
|
updateMany: (resource, params) => {
|
||||||
console.log("updateMany " + resource);
|
console.log("updateMany " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
params.ids.map(id => jsonClient(`${homeserver_url}/${id}`), {
|
params.ids.map(id => jsonClient(`${endpoint_url}/${id}`), {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
})
|
})
|
||||||
@@ -169,12 +186,13 @@ const dataProvider = {
|
|||||||
|
|
||||||
create: (resource, params) => {
|
create: (resource, params) => {
|
||||||
console.log("create " + resource);
|
console.log("create " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
return jsonClient(`${homeserver_url}/${params.data.id}`, {
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return jsonClient(`${endpoint_url}/${params.data.id}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
}).then(({ json }) => ({
|
}).then(({ json }) => ({
|
||||||
@@ -184,35 +202,64 @@ const dataProvider = {
|
|||||||
|
|
||||||
delete: (resource, params) => {
|
delete: (resource, params) => {
|
||||||
console.log("delete " + resource);
|
console.log("delete " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
return jsonClient(`${homeserver_url}/${params.id}`, {
|
if ("delete" in res) {
|
||||||
method: "DELETE",
|
const del = res["delete"](params.id);
|
||||||
}).then(({ json }) => ({
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
data: json,
|
return jsonClient(endpoint_url, {
|
||||||
}));
|
method: del.method,
|
||||||
|
body: JSON.stringify(del.body),
|
||||||
|
}).then(({ json }) => ({
|
||||||
|
data: json,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return jsonClient(`${endpoint_url}/${params.id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
|
}).then(({ json }) => ({
|
||||||
|
data: json,
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteMany: (resource, params) => {
|
deleteMany: (resource, params) => {
|
||||||
console.log("deleteMany " + resource);
|
console.log("deleteMany " + resource);
|
||||||
const homeserver = localStorage.getItem("home_server");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
const homeserver_url = "https://" + homeserver + res.path;
|
|
||||||
return Promise.all(
|
if ("delete" in res) {
|
||||||
params.ids.map(id =>
|
return Promise.all(
|
||||||
jsonClient(`${homeserver_url}/${id}`, {
|
params.ids.map(id => {
|
||||||
method: "DELETE",
|
const del = res["delete"](id);
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
}).then(responses => ({
|
return jsonClient(endpoint_url, {
|
||||||
data: responses.map(({ json }) => json),
|
method: del.method,
|
||||||
}))
|
body: JSON.stringify(del.body),
|
||||||
)
|
});
|
||||||
);
|
})
|
||||||
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return Promise.all(
|
||||||
|
params.ids.map(id =>
|
||||||
|
jsonClient(`${endpoint_url}/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user