Compare commits
22 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2915fd3e5b | ||
![]() |
a4662c2557 | ||
![]() |
f6ca169fbc | ||
![]() |
07862591fd | ||
![]() |
ab649fbf70 | ||
![]() |
880223e5de | ||
![]() |
76fdc80e3e | ||
![]() |
375649756f | ||
![]() |
662735a91f | ||
![]() |
0823976edd | ||
![]() |
d3cd2e9e33 | ||
![]() |
24abcd4e4a | ||
![]() |
c1c32e3268 | ||
![]() |
ca15435625 | ||
![]() |
e9c3901b68 | ||
![]() |
7aec6f9369 | ||
![]() |
d2a3f07a59 | ||
![]() |
bf7867f106 | ||
![]() |
f0e32abc4f | ||
![]() |
61b1580735 | ||
![]() |
0f7e4c1909 | ||
![]() |
c9bce409d2 |
16 changed files with 506 additions and 312 deletions
|
@ -1,4 +1,5 @@
|
||||||
# Exclude a bunch of stuff which can make the build context a larger than it needs to be
|
# Exclude a bunch of stuff which can make the build context a larger than it needs to be
|
||||||
|
.git/
|
||||||
tests/
|
tests/
|
||||||
build/
|
build/
|
||||||
lib/
|
lib/
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
This project is built using [react-admin](https://marmelab.com/react-admin/).
|
This project is built using [react-admin](https://marmelab.com/react-admin/).
|
||||||
|
|
||||||
It needs at least Synapse v1.15.0 for all functions to work as expected!
|
It needs at least Synapse v1.14.0 for all functions to work as expected!
|
||||||
|
|
||||||
## Step-By-Step install:
|
## Step-By-Step install:
|
||||||
|
|
||||||
|
@ -29,8 +29,3 @@ Steps for 2):
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
- Use `yarn test` to run all style, lint and unit tests
|
|
||||||
- Use `yarn fix` to fix the coding style
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "synapse-admin",
|
"name": "synapse-admin",
|
||||||
"version": "0.2.1",
|
"version": "AMP/2020.07",
|
||||||
"description": "Admin GUI for the Matrix.org server Synapse",
|
"description": "Admin GUI for the Matrix.org server Synapse",
|
||||||
"author": "Awesome Technologies Innovationslabor GmbH",
|
"author": "Awesome Technologies Innovationslabor GmbH",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
@ -18,11 +18,14 @@
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"eslint-config-prettier": "^6.10.1",
|
"eslint-config-prettier": "^6.10.1",
|
||||||
"eslint-plugin-prettier": "^3.1.2",
|
"eslint-plugin-prettier": "^3.1.2",
|
||||||
"jest-fetch-mock": "^3.0.3",
|
|
||||||
"prettier": "^2.0.0"
|
"prettier": "^2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@progress/kendo-drawing": "^1.6.0",
|
||||||
|
"@progress/kendo-react-pdf": "^3.10.1",
|
||||||
|
"babel-preset-jest": "^24.9.0",
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
|
"qrcode.react": "^1.0.0",
|
||||||
"ra-language-german": "^2.1.2",
|
"ra-language-german": "^2.1.2",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-admin": "^3.7.0",
|
"react-admin": "^3.7.0",
|
||||||
|
|
BIN
public/images/logo.png
Normal file
BIN
public/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 358 KiB |
16
src/App.js
16
src/App.js
|
@ -4,12 +4,14 @@ import polyglotI18nProvider from "ra-i18n-polyglot";
|
||||||
import authProvider from "./synapse/authProvider";
|
import authProvider from "./synapse/authProvider";
|
||||||
import dataProvider from "./synapse/dataProvider";
|
import dataProvider from "./synapse/dataProvider";
|
||||||
import { UserList, UserCreate, UserEdit } from "./components/users";
|
import { UserList, UserCreate, UserEdit } from "./components/users";
|
||||||
import { RoomList, RoomShow } from "./components/rooms";
|
import { RoomList, RoomCreate, RoomShow } from "./components/rooms";
|
||||||
import LoginPage from "./components/LoginPage";
|
import LoginPage from "./components/LoginPage";
|
||||||
import UserIcon from "@material-ui/icons/Group";
|
import UserIcon from "@material-ui/icons/Group";
|
||||||
import { ViewListIcon as RoomIcon } from "@material-ui/icons/ViewList";
|
import { ViewListIcon as RoomIcon } from "@material-ui/icons/ViewList";
|
||||||
import germanMessages from "./i18n/de";
|
import germanMessages from "./i18n/de";
|
||||||
import englishMessages from "./i18n/en";
|
import englishMessages from "./i18n/en";
|
||||||
|
import ShowUserPdf from "./components/ShowUserPdf";
|
||||||
|
import { Route } from "react-router-dom";
|
||||||
|
|
||||||
// TODO: Can we use lazy loading together with browser locale?
|
// TODO: Can we use lazy loading together with browser locale?
|
||||||
const messages = {
|
const messages = {
|
||||||
|
@ -27,6 +29,9 @@ const App = () => (
|
||||||
authProvider={authProvider}
|
authProvider={authProvider}
|
||||||
dataProvider={dataProvider}
|
dataProvider={dataProvider}
|
||||||
i18nProvider={i18nProvider}
|
i18nProvider={i18nProvider}
|
||||||
|
customRoutes={[
|
||||||
|
<Route key="showpdf" path="/showpdf" component={ShowUserPdf} />,
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<Resource
|
<Resource
|
||||||
name="users"
|
name="users"
|
||||||
|
@ -35,9 +40,14 @@ const App = () => (
|
||||||
edit={UserEdit}
|
edit={UserEdit}
|
||||||
icon={UserIcon}
|
icon={UserIcon}
|
||||||
/>
|
/>
|
||||||
<Resource name="rooms" list={RoomList} show={RoomShow} icon={RoomIcon} />
|
<Resource
|
||||||
|
name="rooms"
|
||||||
|
list={RoomList}
|
||||||
|
create={RoomCreate}
|
||||||
|
show={RoomShow}
|
||||||
|
icon={RoomIcon}
|
||||||
|
/>
|
||||||
<Resource name="connections" />
|
<Resource name="connections" />
|
||||||
<Resource name="devices" />
|
|
||||||
<Resource name="servernotices" />
|
<Resource name="servernotices" />
|
||||||
</Admin>
|
</Admin>
|
||||||
);
|
);
|
||||||
|
|
35
src/components/SaveQrButton.js
Normal file
35
src/components/SaveQrButton.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import React, { useCallback } from "react";
|
||||||
|
import { SaveButton, useCreate, useRedirect, useNotify } from "react-admin";
|
||||||
|
|
||||||
|
const SaveQrButton = props => {
|
||||||
|
const [create] = useCreate("users");
|
||||||
|
const redirectTo = useRedirect();
|
||||||
|
const notify = useNotify();
|
||||||
|
const { basePath } = props;
|
||||||
|
|
||||||
|
const handleSave = useCallback(
|
||||||
|
(values, redirect) => {
|
||||||
|
create(
|
||||||
|
{
|
||||||
|
payload: { data: { ...values } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: ({ data: newRecord }) => {
|
||||||
|
notify("ra.notification.created", "info", {
|
||||||
|
smart_count: 1,
|
||||||
|
});
|
||||||
|
redirectTo(redirect, basePath, newRecord.id, {
|
||||||
|
password: values.password,
|
||||||
|
...newRecord,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[create, notify, redirectTo, basePath]
|
||||||
|
);
|
||||||
|
|
||||||
|
return <SaveButton {...props} onSave={handleSave} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SaveQrButton;
|
132
src/components/ShowUserPdf.js
Normal file
132
src/components/ShowUserPdf.js
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
import React from "react";
|
||||||
|
import { Title, Button } from "react-admin";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
import { PDFExport } from "@progress/kendo-react-pdf";
|
||||||
|
import QRCode from "qrcode.react";
|
||||||
|
|
||||||
|
function xor(a, b) {
|
||||||
|
var res = "";
|
||||||
|
for (var i = 0; i < a.length; i++) {
|
||||||
|
res += String.fromCharCode(a.charCodeAt(i) ^ b.charCodeAt(i % b.length));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateQrString(serverUrl, username, password) {
|
||||||
|
const magicString = "wo9k5tep252qxsa5yde7366kugy6c01w7oeeya9hrmpf0t7ii7";
|
||||||
|
var urlString = "user=" + username + "&password=" + password;
|
||||||
|
|
||||||
|
urlString = xor(urlString, magicString); // xor with magic string
|
||||||
|
urlString = btoa(urlString); // to base64
|
||||||
|
|
||||||
|
return serverUrl + "/#" + urlString;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ShowUserPdf = props => {
|
||||||
|
const useStyles = makeStyles(theme => ({
|
||||||
|
page: {
|
||||||
|
height: 800,
|
||||||
|
width: 566,
|
||||||
|
padding: "none",
|
||||||
|
backgroundColor: "white",
|
||||||
|
boxShadow: "5px 5px 5px black",
|
||||||
|
margin: "auto",
|
||||||
|
overflowX: "hidden",
|
||||||
|
overflowY: "hidden",
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
height: 144,
|
||||||
|
width: 534,
|
||||||
|
marginLeft: 32,
|
||||||
|
marginTop: 15,
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
width: 233,
|
||||||
|
fontSize: 40,
|
||||||
|
float: "left",
|
||||||
|
marginTop: 15,
|
||||||
|
},
|
||||||
|
logo: {
|
||||||
|
width: 90,
|
||||||
|
marginTop: 20,
|
||||||
|
marginRight: 32,
|
||||||
|
float: "left",
|
||||||
|
},
|
||||||
|
code: {
|
||||||
|
marginLeft: 330,
|
||||||
|
marginTop: 86,
|
||||||
|
},
|
||||||
|
qr: {
|
||||||
|
marginRight: 40,
|
||||||
|
float: "right",
|
||||||
|
},
|
||||||
|
note: {
|
||||||
|
fontSize: 18,
|
||||||
|
marginTop: 100,
|
||||||
|
marginLeft: 32,
|
||||||
|
marginRight: 32,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
|
var resume;
|
||||||
|
|
||||||
|
const exportPDF = () => {
|
||||||
|
resume.save();
|
||||||
|
};
|
||||||
|
|
||||||
|
var qrCode = "";
|
||||||
|
var displayname = "";
|
||||||
|
|
||||||
|
if (
|
||||||
|
props.location.state &&
|
||||||
|
props.location.state.id &&
|
||||||
|
props.location.state.password
|
||||||
|
) {
|
||||||
|
const { id, password } = props.location.state;
|
||||||
|
|
||||||
|
const username = id.substring(1, id.indexOf(":"));
|
||||||
|
const serverUrl = "https://" + id.substring(id.indexOf(":") + 1);
|
||||||
|
|
||||||
|
const qrString = calculateQrString(serverUrl, username, password);
|
||||||
|
|
||||||
|
qrCode = <QRCode value={qrString} size={128} />;
|
||||||
|
displayname = props.location.state.displayname;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Title title="PDF" />
|
||||||
|
<Button label="synapseadmin.action.download_pdf" onClick={exportPDF} />
|
||||||
|
|
||||||
|
<PDFExport
|
||||||
|
paperSize={"A4"}
|
||||||
|
fileName="User.pdf"
|
||||||
|
title=""
|
||||||
|
subject=""
|
||||||
|
keywords=""
|
||||||
|
ref={r => (resume = r)}
|
||||||
|
>
|
||||||
|
<div className={classes.page}>
|
||||||
|
<div className={classes.code}>Ihr persönlicher Anmeldecode:</div>
|
||||||
|
<div className={classes.header}>
|
||||||
|
<div className={classes.name}>{displayname}</div>
|
||||||
|
<img className={classes.logo} alt="Logo" src="images/logo.png" />
|
||||||
|
<div className={classes.qr}>{qrCode}</div>
|
||||||
|
</div>
|
||||||
|
<div className={classes.note}>
|
||||||
|
Hier können Sie Ihre selbst gewählte Schlüsselsicherungs-Passphrase
|
||||||
|
notieren:
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PDFExport>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ShowUserPdf;
|
|
@ -1,89 +0,0 @@
|
||||||
import React, { Fragment, useState } from "react";
|
|
||||||
import {
|
|
||||||
Button,
|
|
||||||
useMutation,
|
|
||||||
useNotify,
|
|
||||||
Confirm,
|
|
||||||
useRefresh,
|
|
||||||
} from "react-admin";
|
|
||||||
import ActionDelete from "@material-ui/icons/Delete";
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
|
||||||
import { fade } from "@material-ui/core/styles/colorManipulator";
|
|
||||||
import classnames from "classnames";
|
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
|
||||||
theme => ({
|
|
||||||
deleteButton: {
|
|
||||||
color: theme.palette.error.main,
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: fade(theme.palette.error.main, 0.12),
|
|
||||||
// Reset on mouse devices
|
|
||||||
"@media (hover: none)": {
|
|
||||||
backgroundColor: "transparent",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
{ name: "RaDeleteDeviceButton" }
|
|
||||||
);
|
|
||||||
|
|
||||||
export const DeviceRemoveButton = props => {
|
|
||||||
const { record } = props;
|
|
||||||
const classes = useStyles(props);
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const refresh = useRefresh();
|
|
||||||
const notify = useNotify();
|
|
||||||
|
|
||||||
const [removeDevice, { loading }] = useMutation();
|
|
||||||
|
|
||||||
if (!record) return null;
|
|
||||||
|
|
||||||
const handleClick = () => setOpen(true);
|
|
||||||
const handleDialogClose = () => setOpen(false);
|
|
||||||
|
|
||||||
const handleConfirm = () => {
|
|
||||||
removeDevice(
|
|
||||||
{
|
|
||||||
type: "delete",
|
|
||||||
resource: "devices",
|
|
||||||
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"),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
setOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Fragment>
|
|
||||||
<Button
|
|
||||||
label="ra.action.remove"
|
|
||||||
onClick={handleClick}
|
|
||||||
className={classnames("ra-delete-button", classes.deleteButton)}
|
|
||||||
>
|
|
||||||
<ActionDelete />
|
|
||||||
</Button>
|
|
||||||
<Confirm
|
|
||||||
isOpen={open}
|
|
||||||
loading={loading}
|
|
||||||
onConfirm={handleConfirm}
|
|
||||||
onClose={handleDialogClose}
|
|
||||||
title="resources.devices.action.erase.title"
|
|
||||||
content="resources.devices.action.erase.content"
|
|
||||||
translateOptions={{
|
|
||||||
id: record.id,
|
|
||||||
name: record.display_name ? record.display_name : record.id,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -1,16 +1,23 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import {
|
import {
|
||||||
|
AutocompleteArrayInput,
|
||||||
|
BooleanInput,
|
||||||
BooleanField,
|
BooleanField,
|
||||||
|
Create,
|
||||||
Datagrid,
|
Datagrid,
|
||||||
Filter,
|
Filter,
|
||||||
|
FormTab,
|
||||||
List,
|
List,
|
||||||
Pagination,
|
Pagination,
|
||||||
|
ReferenceArrayInput,
|
||||||
SelectField,
|
SelectField,
|
||||||
Show,
|
Show,
|
||||||
Tab,
|
Tab,
|
||||||
|
TabbedForm,
|
||||||
TabbedShowLayout,
|
TabbedShowLayout,
|
||||||
TextField,
|
TextField,
|
||||||
|
TextInput,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import get from "lodash/get";
|
import get from "lodash/get";
|
||||||
|
@ -18,6 +25,7 @@ import { Tooltip, Typography, Chip } from "@material-ui/core";
|
||||||
import HttpsIcon from "@material-ui/icons/Https";
|
import HttpsIcon from "@material-ui/icons/Https";
|
||||||
import NoEncryptionIcon from "@material-ui/icons/NoEncryption";
|
import NoEncryptionIcon from "@material-ui/icons/NoEncryption";
|
||||||
import PageviewIcon from "@material-ui/icons/Pageview";
|
import PageviewIcon from "@material-ui/icons/Pageview";
|
||||||
|
import UserIcon from "@material-ui/icons/Group";
|
||||||
import ViewListIcon from "@material-ui/icons/ViewList";
|
import ViewListIcon from "@material-ui/icons/ViewList";
|
||||||
import VisibilityIcon from "@material-ui/icons/Visibility";
|
import VisibilityIcon from "@material-ui/icons/Visibility";
|
||||||
|
|
||||||
|
@ -51,16 +59,117 @@ const EncryptionField = ({ source, record = {}, emptyText }) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const RoomTitle = ({ record }) => {
|
const validateDisplayName = fieldval =>
|
||||||
const translate = useTranslate();
|
fieldval === undefined
|
||||||
var name = "";
|
? "synapseadmin.rooms.room_name_required"
|
||||||
if (record) {
|
: fieldval.length === 0
|
||||||
name = record.name !== "" ? record.name : record.id;
|
? "synapseadmin.rooms.room_name_required"
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
function approximateAliasLength(alias, homeserver) {
|
||||||
|
/* TODO maybe handle punycode in homeserver name */
|
||||||
|
|
||||||
|
var te;
|
||||||
|
|
||||||
|
// Support for TextEncoder is quite widespread, but the polyfill is
|
||||||
|
// pretty large; We will only underestimate the size with the regular
|
||||||
|
// length attribute of String, so we never prevent the user from using
|
||||||
|
// an alias that is short enough for the server, but too long for our
|
||||||
|
// heuristic.
|
||||||
|
try {
|
||||||
|
te = new TextEncoder();
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ReferenceError) {
|
||||||
|
te = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const aliasLength = te === undefined ? alias.length : te.encode(alias).length;
|
||||||
|
|
||||||
|
return "#".length + aliasLength + ":".length + homeserver.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validateAlias = fieldval => {
|
||||||
|
if (fieldval === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const homeserver = localStorage.getItem("home_server");
|
||||||
|
|
||||||
|
if (approximateAliasLength(fieldval, homeserver) > 255) {
|
||||||
|
return "synapseadmin.rooms.alias_too_long";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeLeadingWhitespace = fieldVal =>
|
||||||
|
fieldVal === undefined ? undefined : fieldVal.trimStart();
|
||||||
|
const replaceAllWhitespace = fieldVal =>
|
||||||
|
fieldVal === undefined ? undefined : fieldVal.replace(/\s/, "_");
|
||||||
|
const removeLeadingSigil = fieldVal =>
|
||||||
|
fieldVal === undefined
|
||||||
|
? undefined
|
||||||
|
: fieldVal.startsWith("#")
|
||||||
|
? fieldVal.substr(1)
|
||||||
|
: fieldVal;
|
||||||
|
|
||||||
|
const validateHasAliasIfPublic = formdata => {
|
||||||
|
let errors = {};
|
||||||
|
if (formdata.public) {
|
||||||
|
if (
|
||||||
|
formdata.canonical_alias === undefined ||
|
||||||
|
formdata.canonical_alias.trim().length === 0
|
||||||
|
) {
|
||||||
|
errors.canonical_alias = "synapseadmin.rooms.alias_required_if_public";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RoomCreate = props => (
|
||||||
|
<Create {...props}>
|
||||||
|
<TabbedForm validate={validateHasAliasIfPublic}>
|
||||||
|
<FormTab label="synapseadmin.rooms.details" icon={<ViewListIcon />}>
|
||||||
|
<TextInput
|
||||||
|
source="name"
|
||||||
|
parse={removeLeadingWhitespace}
|
||||||
|
validate={validateDisplayName}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
source="canonical_alias"
|
||||||
|
parse={fv => replaceAllWhitespace(removeLeadingSigil(fv))}
|
||||||
|
validate={validateAlias}
|
||||||
|
placeholder="#"
|
||||||
|
/>
|
||||||
|
<BooleanInput source="public" label="synapseadmin.rooms.make_public" />
|
||||||
|
<BooleanInput
|
||||||
|
source="encrypt"
|
||||||
|
initialValue={true}
|
||||||
|
label="synapseadmin.rooms.encrypt"
|
||||||
|
/>
|
||||||
|
</FormTab>
|
||||||
|
<FormTab
|
||||||
|
label="resources.rooms.fields.invite_members"
|
||||||
|
icon={<UserIcon />}
|
||||||
|
>
|
||||||
|
<ReferenceArrayInput
|
||||||
|
reference="users"
|
||||||
|
source="invitees"
|
||||||
|
filterToQuery={searchText => ({ user_id: searchText })}
|
||||||
|
>
|
||||||
|
<AutocompleteArrayInput
|
||||||
|
optionText="displayname"
|
||||||
|
suggestionText="displayname"
|
||||||
|
/>
|
||||||
|
</ReferenceArrayInput>
|
||||||
|
</FormTab>
|
||||||
|
</TabbedForm>
|
||||||
|
</Create>
|
||||||
|
);
|
||||||
|
|
||||||
|
const RoomTitle = ({ record }) => {
|
||||||
|
const translate = useTranslate();
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{translate("resources.rooms.name", 1)} {name}
|
{translate("resources.rooms.name", 1)} {record ? `"${record.name}"` : ""}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,6 @@ import React, { cloneElement, Fragment } from "react";
|
||||||
import Avatar from "@material-ui/core/Avatar";
|
import Avatar from "@material-ui/core/Avatar";
|
||||||
import PersonPinIcon from "@material-ui/icons/PersonPin";
|
import PersonPinIcon from "@material-ui/icons/PersonPin";
|
||||||
import ContactMailIcon from "@material-ui/icons/ContactMail";
|
import ContactMailIcon from "@material-ui/icons/ContactMail";
|
||||||
import DevicesIcon from "@material-ui/icons/Devices";
|
|
||||||
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
||||||
import {
|
import {
|
||||||
ArrayInput,
|
ArrayInput,
|
||||||
|
@ -23,8 +22,8 @@ import {
|
||||||
PasswordInput,
|
PasswordInput,
|
||||||
TextField,
|
TextField,
|
||||||
TextInput,
|
TextInput,
|
||||||
|
SearchInput,
|
||||||
ReferenceField,
|
ReferenceField,
|
||||||
ReferenceManyField,
|
|
||||||
SelectInput,
|
SelectInput,
|
||||||
BulkDeleteButton,
|
BulkDeleteButton,
|
||||||
DeleteButton,
|
DeleteButton,
|
||||||
|
@ -37,8 +36,8 @@ import {
|
||||||
TopToolbar,
|
TopToolbar,
|
||||||
sanitizeListRestProps,
|
sanitizeListRestProps,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
|
import SaveQrButton from "./SaveQrButton";
|
||||||
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||||
import { DeviceRemoveButton } from "./devices";
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
|
@ -98,6 +97,7 @@ const UserPagination = props => (
|
||||||
|
|
||||||
const UserFilter = props => (
|
const UserFilter = props => (
|
||||||
<Filter {...props}>
|
<Filter {...props}>
|
||||||
|
<SearchInput source="user_id" alwaysOn />
|
||||||
<BooleanInput source="guests" alwaysOn />
|
<BooleanInput source="guests" alwaysOn />
|
||||||
<BooleanInput
|
<BooleanInput
|
||||||
label="resources.users.fields.show_deactivated"
|
label="resources.users.fields.show_deactivated"
|
||||||
|
@ -143,7 +143,7 @@ export const UserList = props => {
|
||||||
className={classes.small}
|
className={classes.small}
|
||||||
/>
|
/>
|
||||||
<TextField source="id" sortable={false} />
|
<TextField source="id" sortable={false} />
|
||||||
<TextField source="displayname" sortable={false} />
|
<TextField source="displayname" />
|
||||||
<BooleanField source="is_guest" sortable={false} />
|
<BooleanField source="is_guest" sortable={false} />
|
||||||
<BooleanField source="admin" sortable={false} />
|
<BooleanField source="admin" sortable={false} />
|
||||||
<BooleanField source="deactivated" sortable={false} />
|
<BooleanField source="deactivated" sortable={false} />
|
||||||
|
@ -152,6 +152,75 @@ export const UserList = props => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function generateRandomUser() {
|
||||||
|
const homeserver = localStorage.getItem("home_server");
|
||||||
|
const user_id =
|
||||||
|
"@" +
|
||||||
|
Array(8)
|
||||||
|
.fill("0123456789abcdefghijklmnopqrstuvwxyz")
|
||||||
|
.map(
|
||||||
|
x =>
|
||||||
|
x[
|
||||||
|
Math.floor(
|
||||||
|
(crypto.getRandomValues(new Uint32Array(1))[0] /
|
||||||
|
(0xffffffff + 1)) *
|
||||||
|
x.length
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.join("") +
|
||||||
|
":" +
|
||||||
|
homeserver;
|
||||||
|
|
||||||
|
const password = Array(20)
|
||||||
|
.fill(
|
||||||
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@-#$"
|
||||||
|
)
|
||||||
|
.map(
|
||||||
|
x =>
|
||||||
|
x[
|
||||||
|
Math.floor(
|
||||||
|
(crypto.getRandomValues(new Uint32Array(1))[0] / (0xffffffff + 1)) *
|
||||||
|
x.length
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: user_id,
|
||||||
|
password: password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// redirect to the related Author show page
|
||||||
|
const redirect = (basePath, id, data) => {
|
||||||
|
return {
|
||||||
|
pathname: "/showpdf",
|
||||||
|
state: {
|
||||||
|
id: data.id,
|
||||||
|
displayname: data.displayname,
|
||||||
|
password: data.password,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const UserCreateToolbar = props => (
|
||||||
|
<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"
|
||||||
|
/>
|
||||||
|
</Toolbar>
|
||||||
|
);
|
||||||
|
|
||||||
// https://matrix.org/docs/spec/appendices#user-identifiers
|
// https://matrix.org/docs/spec/appendices#user-identifiers
|
||||||
const validateUser = regex(
|
const validateUser = regex(
|
||||||
/^@[a-z0-9._=\-/]+:.*/,
|
/^@[a-z0-9._=\-/]+:.*/,
|
||||||
|
@ -162,7 +231,17 @@ const UserEditToolbar = props => {
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
return (
|
return (
|
||||||
<Toolbar {...props}>
|
<Toolbar {...props}>
|
||||||
<SaveButton submitOnEnter={true} />
|
<SaveQrButton
|
||||||
|
label="synapseadmin.action.save_and_show"
|
||||||
|
redirect={redirect}
|
||||||
|
submitOnEnter={true}
|
||||||
|
/>
|
||||||
|
<SaveButton
|
||||||
|
label="synapseadmin.action.save_only"
|
||||||
|
redirect="list"
|
||||||
|
submitOnEnter={false}
|
||||||
|
variant="text"
|
||||||
|
/>
|
||||||
<DeleteButton
|
<DeleteButton
|
||||||
label="resources.users.action.erase"
|
label="resources.users.action.erase"
|
||||||
title={translate("resources.users.helper.erase")}
|
title={translate("resources.users.helper.erase")}
|
||||||
|
@ -173,8 +252,8 @@ const UserEditToolbar = props => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UserCreate = props => (
|
export const UserCreate = props => (
|
||||||
<Create {...props}>
|
<Create record={generateRandomUser()} {...props}>
|
||||||
<SimpleForm>
|
<SimpleForm toolbar={<UserCreateToolbar />}>
|
||||||
<TextInput source="id" autoComplete="off" validate={validateUser} />
|
<TextInput source="id" autoComplete="off" validate={validateUser} />
|
||||||
<TextInput source="displayname" />
|
<TextInput source="displayname" />
|
||||||
<PasswordInput source="password" autoComplete="new-password" />
|
<PasswordInput source="password" autoComplete="new-password" />
|
||||||
|
@ -206,9 +285,9 @@ const UserTitle = ({ record }) => {
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UserEdit = props => {
|
export const UserEdit = props => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const translate = useTranslate();
|
|
||||||
return (
|
return (
|
||||||
<Edit {...props} title={<UserTitle />}>
|
<Edit {...props} title={<UserTitle />}>
|
||||||
<TabbedForm toolbar={<UserEditToolbar />}>
|
<TabbedForm toolbar={<UserEditToolbar />}>
|
||||||
|
@ -258,37 +337,6 @@ export const UserEdit = props => {
|
||||||
</SimpleFormIterator>
|
</SimpleFormIterator>
|
||||||
</ArrayInput>
|
</ArrayInput>
|
||||||
</FormTab>
|
</FormTab>
|
||||||
<FormTab
|
|
||||||
label={translate("resources.devices.name", { smart_count: 2 })}
|
|
||||||
icon={<DevicesIcon />}
|
|
||||||
path="devices"
|
|
||||||
>
|
|
||||||
<ReferenceManyField
|
|
||||||
reference="devices"
|
|
||||||
target="user_id"
|
|
||||||
addLabel={false}
|
|
||||||
>
|
|
||||||
<Datagrid style={{ width: "100%" }}>
|
|
||||||
<TextField source="device_id" sortable={false} />
|
|
||||||
<TextField source="display_name" sortable={false} />
|
|
||||||
<TextField source="last_seen_ip" sortable={false} />
|
|
||||||
<DateField
|
|
||||||
source="last_seen_ts"
|
|
||||||
showTime
|
|
||||||
options={{
|
|
||||||
year: "numeric",
|
|
||||||
month: "2-digit",
|
|
||||||
day: "2-digit",
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
second: "2-digit",
|
|
||||||
}}
|
|
||||||
sortable={false}
|
|
||||||
/>
|
|
||||||
<DeviceRemoveButton />
|
|
||||||
</Datagrid>
|
|
||||||
</ReferenceManyField>
|
|
||||||
</FormTab>
|
|
||||||
<FormTab
|
<FormTab
|
||||||
label="resources.connections.name"
|
label="resources.connections.name"
|
||||||
icon={<SettingsInputComponentIcon />}
|
icon={<SettingsInputComponentIcon />}
|
||||||
|
|
|
@ -11,12 +11,25 @@ export default {
|
||||||
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
|
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
|
||||||
url_error: "Keine gültige Matrix Server URL",
|
url_error: "Keine gültige Matrix Server URL",
|
||||||
},
|
},
|
||||||
|
action: {
|
||||||
|
save_and_show: "Speichern und QR Code erzeugen",
|
||||||
|
save_only: "Nur speichern",
|
||||||
|
download_pdf: "PDF speichern",
|
||||||
|
},
|
||||||
users: {
|
users: {
|
||||||
invalid_user_id:
|
invalid_user_id:
|
||||||
"Muss eine vollständige Matrix Benutzer-ID sein, z.B. @benutzer_id:homeserver",
|
"Muss eine vollständige Matrix Benutzer-ID sein, z.B. @benutzer_id:homeserver",
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
details: "Raumdetails",
|
details: "Raumdetails",
|
||||||
|
room_name: "Raumname",
|
||||||
|
make_public: "Öffentlicher Raum",
|
||||||
|
encrypt: "Verschlüsselter Raum",
|
||||||
|
room_name_required: "Muss angegeben werden",
|
||||||
|
alias_required_if_public: "Muss für öffentliche Räume angegeben werden.",
|
||||||
|
alias: "Alias",
|
||||||
|
alias_too_long:
|
||||||
|
"Darf zusammen mit der Domain des Homeservers 255 bytes nicht überschreiten",
|
||||||
tabs: {
|
tabs: {
|
||||||
basic: "Allgemein",
|
basic: "Allgemein",
|
||||||
members: "Mitglieder",
|
members: "Mitglieder",
|
||||||
|
@ -37,7 +50,7 @@ export default {
|
||||||
id: "Benutzer-ID",
|
id: "Benutzer-ID",
|
||||||
name: "Name",
|
name: "Name",
|
||||||
is_guest: "Gast",
|
is_guest: "Gast",
|
||||||
admin: "Server Administrator",
|
admin: "Admin",
|
||||||
deactivated: "Deaktiviert",
|
deactivated: "Deaktiviert",
|
||||||
guests: "Zeige Gäste",
|
guests: "Zeige Gäste",
|
||||||
show_deactivated: "Zeige deaktivierte Benutzer",
|
show_deactivated: "Zeige deaktivierte Benutzer",
|
||||||
|
@ -51,11 +64,6 @@ export default {
|
||||||
address: "Adresse",
|
address: "Adresse",
|
||||||
creation_ts_ms: "Zeitpunkt der Erstellung",
|
creation_ts_ms: "Zeitpunkt der Erstellung",
|
||||||
consent_version: "Zugestimmte Geschäftsbedingungen",
|
consent_version: "Zugestimmte Geschäftsbedingungen",
|
||||||
// Devices:
|
|
||||||
device_id: "Geräte-ID",
|
|
||||||
display_name: "Gerätename",
|
|
||||||
last_seen_ts: "Zeitstempel",
|
|
||||||
last_seen_ip: "IP-Adresse",
|
|
||||||
},
|
},
|
||||||
helper: {
|
helper: {
|
||||||
deactivate: "Deaktivierte Nutzer können nicht wieder aktiviert werden.",
|
deactivate: "Deaktivierte Nutzer können nicht wieder aktiviert werden.",
|
||||||
|
@ -72,6 +80,8 @@ export default {
|
||||||
name: "Name",
|
name: "Name",
|
||||||
canonical_alias: "Alias",
|
canonical_alias: "Alias",
|
||||||
joined_members: "Mitglieder",
|
joined_members: "Mitglieder",
|
||||||
|
invite_members: "Mitglieder einladen",
|
||||||
|
invitees: "Einladungen",
|
||||||
joined_local_members: "Lokale Mitglieder",
|
joined_local_members: "Lokale Mitglieder",
|
||||||
state_events: "Ereignisse",
|
state_events: "Ereignisse",
|
||||||
version: "Version",
|
version: "Version",
|
||||||
|
@ -112,17 +122,6 @@ export default {
|
||||||
user_agent: "User Agent",
|
user_agent: "User Agent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
devices: {
|
|
||||||
name: "Gerät |||| Geräte",
|
|
||||||
action: {
|
|
||||||
erase: {
|
|
||||||
title: "Entferne %{id}",
|
|
||||||
content: 'Möchten Sie das Gerät "%{name}" wirklich entfernen?',
|
|
||||||
success: "Gerät erfolgreich entfernt.",
|
|
||||||
failure: "Beim Entfernen ist ein Fehler aufgetreten.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
servernotices: {
|
servernotices: {
|
||||||
name: "Serverbenachrichtigungen",
|
name: "Serverbenachrichtigungen",
|
||||||
send: "Servernachricht versenden",
|
send: "Servernachricht versenden",
|
||||||
|
|
|
@ -6,15 +6,30 @@ export default {
|
||||||
auth: {
|
auth: {
|
||||||
base_url: "Homeserver URL",
|
base_url: "Homeserver URL",
|
||||||
welcome: "Welcome to Synapse-admin",
|
welcome: "Welcome to Synapse-admin",
|
||||||
|
server_version: "Synapse version",
|
||||||
username_error: "Please enter fully qualified user ID: '@user:domain'",
|
username_error: "Please enter fully qualified user ID: '@user:domain'",
|
||||||
protocol_error: "URL has to start with 'http://' or 'https://'",
|
protocol_error: "URL has to start with 'http://' or 'https://'",
|
||||||
url_error: "Not a valid Matrix server URL",
|
url_error: "Not a valid Matrix server URL",
|
||||||
},
|
},
|
||||||
|
action: {
|
||||||
|
save_and_show: "Create QR code",
|
||||||
|
save_only: "Save",
|
||||||
|
download_pdf: "Download PDF",
|
||||||
|
},
|
||||||
users: {
|
users: {
|
||||||
invalid_user_id:
|
invalid_user_id:
|
||||||
"Must be a fully qualified Matrix user-id, e.g. @user_id:homeserver",
|
"Must be a fully qualified Matrix user-id, e.g. @user_id:homeserver",
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
|
details: "Room Details",
|
||||||
|
room_name: "Room Name",
|
||||||
|
make_public: "Make room public",
|
||||||
|
encrypt: "Encrypt room",
|
||||||
|
room_name_required: "Must be provided",
|
||||||
|
alias_required_if_public: "Must be provided for a public room",
|
||||||
|
alias: "Alias",
|
||||||
|
alias_too_long:
|
||||||
|
"Must not exceed 255 bytes including the domain of the homeserver.",
|
||||||
tabs: {
|
tabs: {
|
||||||
basic: "Basic",
|
basic: "Basic",
|
||||||
members: "Members",
|
members: "Members",
|
||||||
|
@ -35,7 +50,7 @@ export default {
|
||||||
id: "User-ID",
|
id: "User-ID",
|
||||||
name: "Name",
|
name: "Name",
|
||||||
is_guest: "Guest",
|
is_guest: "Guest",
|
||||||
admin: "Server Administrator",
|
admin: "Admin",
|
||||||
deactivated: "Deactivated",
|
deactivated: "Deactivated",
|
||||||
guests: "Show guests",
|
guests: "Show guests",
|
||||||
show_deactivated: "Show deactivated users",
|
show_deactivated: "Show deactivated users",
|
||||||
|
@ -49,11 +64,6 @@ export default {
|
||||||
address: "Address",
|
address: "Address",
|
||||||
creation_ts_ms: "Creation timestamp",
|
creation_ts_ms: "Creation timestamp",
|
||||||
consent_version: "Consent version",
|
consent_version: "Consent version",
|
||||||
// Devices:
|
|
||||||
device_id: "Device-ID",
|
|
||||||
display_name: "Device name",
|
|
||||||
last_seen_ts: "Timestamp",
|
|
||||||
last_seen_ip: "IP address",
|
|
||||||
},
|
},
|
||||||
helper: {
|
helper: {
|
||||||
deactivate: "Deactivated users cannot be reactivated",
|
deactivate: "Deactivated users cannot be reactivated",
|
||||||
|
@ -70,6 +80,8 @@ export default {
|
||||||
name: "Name",
|
name: "Name",
|
||||||
canonical_alias: "Alias",
|
canonical_alias: "Alias",
|
||||||
joined_members: "Members",
|
joined_members: "Members",
|
||||||
|
invite_members: "Invite Members",
|
||||||
|
invitees: "Invitations",
|
||||||
joined_local_members: "local members",
|
joined_local_members: "local members",
|
||||||
state_events: "State events",
|
state_events: "State events",
|
||||||
version: "Version",
|
version: "Version",
|
||||||
|
@ -110,17 +122,6 @@ export default {
|
||||||
user_agent: "User agent",
|
user_agent: "User agent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
devices: {
|
|
||||||
name: "Device |||| Devices",
|
|
||||||
action: {
|
|
||||||
erase: {
|
|
||||||
title: "Removing %{id}",
|
|
||||||
content: 'Are you sure you want to remove the device "%{name}"?',
|
|
||||||
success: "Device successfully removed.",
|
|
||||||
failure: "An error has occurred.",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
servernotices: {
|
servernotices: {
|
||||||
name: "Server Notices",
|
name: "Server Notices",
|
||||||
send: "Send server notices",
|
send: "Send server notices",
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import { configure } from "enzyme";
|
import { configure } from "enzyme";
|
||||||
import Adapter from "enzyme-adapter-react-16";
|
import Adapter from "enzyme-adapter-react-16";
|
||||||
import fetchMock from "jest-fetch-mock";
|
|
||||||
|
|
||||||
configure({ adapter: new Adapter() });
|
configure({ adapter: new Adapter() });
|
||||||
fetchMock.enableMocks();
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ const resourceMap = {
|
||||||
is_guest: !!u.is_guest,
|
is_guest: !!u.is_guest,
|
||||||
admin: !!u.admin,
|
admin: !!u.admin,
|
||||||
deactivated: !!u.deactivated,
|
deactivated: !!u.deactivated,
|
||||||
|
displayname: u.display_name || u.displayname,
|
||||||
// need timestamp in milliseconds
|
// need timestamp in milliseconds
|
||||||
creation_ts_ms: u.creation_ts * 1000,
|
creation_ts_ms: u.creation_ts * 1000,
|
||||||
}),
|
}),
|
||||||
|
@ -45,8 +46,8 @@ const resourceMap = {
|
||||||
body: data,
|
body: data,
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
}),
|
}),
|
||||||
delete: params => ({
|
delete: id => ({
|
||||||
endpoint: `/_synapse/admin/v1/deactivate/${params.id}`,
|
endpoint: `/_synapse/admin/v1/deactivate/${id}`,
|
||||||
body: { erase: true },
|
body: { erase: true },
|
||||||
method: "POST",
|
method: "POST",
|
||||||
}),
|
}),
|
||||||
|
@ -63,21 +64,30 @@ const resourceMap = {
|
||||||
public: !!r.public,
|
public: !!r.public,
|
||||||
}),
|
}),
|
||||||
data: "rooms",
|
data: "rooms",
|
||||||
total: json => {
|
total: json => json.total_rooms,
|
||||||
return json.total_rooms;
|
create: data => ({
|
||||||
|
endpoint: "/_matrix/client/r0/createRoom",
|
||||||
|
body: {
|
||||||
|
name: data.name,
|
||||||
|
room_alias_name: data.canonical_alias,
|
||||||
|
visibility: data.public ? "public" : "private",
|
||||||
|
invite:
|
||||||
|
Array.isArray(data.invitees) && data.invitees.length > 0
|
||||||
|
? data.invitees
|
||||||
|
: undefined,
|
||||||
|
initial_state: data.encrypt
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
type: "m.room.encryption",
|
||||||
|
state_key: "",
|
||||||
|
content: {
|
||||||
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
devices: {
|
]
|
||||||
map: d => ({
|
: undefined,
|
||||||
...d,
|
},
|
||||||
id: d.device_id,
|
method: "POST",
|
||||||
}),
|
|
||||||
data: "devices",
|
|
||||||
reference: id => ({
|
|
||||||
endpoint: `/_synapse/admin/v2/users/${id}/devices`,
|
|
||||||
}),
|
|
||||||
delete: params => ({
|
|
||||||
endpoint: `/_synapse/admin/v2/users/${params.user_id}/devices/${params.id}`,
|
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
connections: {
|
connections: {
|
||||||
|
@ -179,18 +189,30 @@ const dataProvider = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getManyReference: (resource, params) => {
|
getManyReference: (resource, params) => {
|
||||||
|
// FIXME
|
||||||
console.log("getManyReference " + resource);
|
console.log("getManyReference " + resource);
|
||||||
|
const { page, perPage } = params.pagination;
|
||||||
|
const { field, order } = params.sort;
|
||||||
|
const query = {
|
||||||
|
sort: JSON.stringify([field, order]),
|
||||||
|
range: JSON.stringify([(page - 1) * perPage, page * perPage - 1]),
|
||||||
|
filter: JSON.stringify({
|
||||||
|
...params.filter,
|
||||||
|
[params.target]: params.id,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
const homeserver = localStorage.getItem("base_url");
|
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 ref = res["reference"](params.id);
|
const endpoint_url = homeserver + res.path;
|
||||||
const endpoint_url = homeserver + ref.endpoint;
|
const url = `${endpoint_url}?${stringify(query)}`;
|
||||||
|
|
||||||
return jsonClient(endpoint_url).then(({ headers, json }) => ({
|
return jsonClient(url).then(({ headers, json }) => ({
|
||||||
data: json[res.data].map(res.map),
|
data: json,
|
||||||
|
total: parseInt(headers.get("content-range").split("/").pop(), 10),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -277,11 +299,11 @@ const dataProvider = {
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
if ("delete" in res) {
|
if ("delete" in res) {
|
||||||
const del = res["delete"](params);
|
const del = res["delete"](params.id);
|
||||||
const endpoint_url = homeserver + del.endpoint;
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
return jsonClient(endpoint_url, {
|
return jsonClient(endpoint_url, {
|
||||||
method: "method" in del ? del.method : "DELETE",
|
method: del.method,
|
||||||
body: "body" in del ? JSON.stringify(del.body) : null,
|
body: JSON.stringify(del.body),
|
||||||
}).then(({ json }) => ({
|
}).then(({ json }) => ({
|
||||||
data: json,
|
data: json,
|
||||||
}));
|
}));
|
||||||
|
@ -306,11 +328,11 @@ const dataProvider = {
|
||||||
if ("delete" in res) {
|
if ("delete" in res) {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
params.ids.map(id => {
|
params.ids.map(id => {
|
||||||
const del = res["delete"]({ ...params, id: id });
|
const del = res["delete"](id);
|
||||||
const endpoint_url = homeserver + del.endpoint;
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
return jsonClient(endpoint_url, {
|
return jsonClient(endpoint_url, {
|
||||||
method: "method" in del ? del.method : "DELETE",
|
method: del.method,
|
||||||
body: "body" in del ? JSON.stringify(del.body) : null,
|
body: JSON.stringify(del.body),
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
).then(responses => ({
|
).then(responses => ({
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
import dataProvider from "./dataProvider";
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fetch.resetMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("dataProvider", () => {
|
|
||||||
localStorage.setItem("base_url", "http://localhost");
|
|
||||||
localStorage.setItem("access_token", "access_token");
|
|
||||||
|
|
||||||
it("fetches all users", async () => {
|
|
||||||
fetch.mockResponseOnce(
|
|
||||||
JSON.stringify({
|
|
||||||
users: [
|
|
||||||
{
|
|
||||||
name: "user_id1",
|
|
||||||
password_hash: "password_hash1",
|
|
||||||
is_guest: 0,
|
|
||||||
admin: 0,
|
|
||||||
user_type: null,
|
|
||||||
deactivated: 0,
|
|
||||||
displayname: "User One",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "user_id2",
|
|
||||||
password_hash: "password_hash2",
|
|
||||||
is_guest: 0,
|
|
||||||
admin: 1,
|
|
||||||
user_type: null,
|
|
||||||
deactivated: 0,
|
|
||||||
displayname: "User Two",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
next_token: "100",
|
|
||||||
total: 200,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const users = await dataProvider.getList("users", {
|
|
||||||
pagination: { page: 1, perPage: 5 },
|
|
||||||
sort: { field: "title", order: "ASC" },
|
|
||||||
filter: { author_id: 12 },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(users["data"][0]["id"]).toEqual("user_id1");
|
|
||||||
expect(users["total"]).toEqual(200);
|
|
||||||
expect(fetch).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("fetches one user", async () => {
|
|
||||||
fetch.mockResponseOnce(
|
|
||||||
JSON.stringify({
|
|
||||||
name: "user_id1",
|
|
||||||
password: "user_password",
|
|
||||||
displayname: "User",
|
|
||||||
threepids: [
|
|
||||||
{
|
|
||||||
medium: "email",
|
|
||||||
address: "user@mail_1.com",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
medium: "email",
|
|
||||||
address: "user@mail_2.com",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
avatar_url: "mxc://localhost/user1",
|
|
||||||
admin: false,
|
|
||||||
deactivated: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const user = await dataProvider.getOne("users", { id: "user_id1" });
|
|
||||||
|
|
||||||
expect(user["data"]["id"]).toEqual("user_id1");
|
|
||||||
expect(user["data"]["displayname"]).toEqual("User");
|
|
||||||
expect(fetch).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
60
yarn.lock
60
yarn.lock
|
@ -1406,6 +1406,25 @@
|
||||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
|
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
|
||||||
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
|
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
|
||||||
|
|
||||||
|
"@progress/kendo-drawing@^1.6.0":
|
||||||
|
version "1.6.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@progress/kendo-drawing/-/kendo-drawing-1.6.0.tgz#66e9df431f52c7dd9fd5567be80dcbfa3a162281"
|
||||||
|
integrity sha512-9dGlFvW9fMgqAgcbLi+SfTeMUpNYdoVthwNxwAtsRQ+QwcgXJcdzFpLrLBXp17pXpDDFpiOyMqiwjffNGwtc3w==
|
||||||
|
dependencies:
|
||||||
|
pako "^1.0.5"
|
||||||
|
|
||||||
|
"@progress/kendo-file-saver@^1.0.1":
|
||||||
|
version "1.0.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/@progress/kendo-file-saver/-/kendo-file-saver-1.0.7.tgz#5b602115d1b0b5e26f3e52451a3ed7c29ed76c51"
|
||||||
|
integrity sha512-8tsho/+DATzfTW4BBaHrkF3C3jqH2/bQ+XbjqA0KfmTiBRVK6ygK+tkvkYeDhFlQBbJ02MmJlEC6OmXvXRFkUg==
|
||||||
|
|
||||||
|
"@progress/kendo-react-pdf@^3.10.1":
|
||||||
|
version "3.10.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@progress/kendo-react-pdf/-/kendo-react-pdf-3.10.1.tgz#348517daaddb366bbe840a92ec2fffbfd07ac2d2"
|
||||||
|
integrity sha512-2EKfQCwLFEa+mgCLKQ70iWVu7q2Dh/wJl6pPJ6Ix42BA7SiA2k5UmDk819FLY9pnMgv7WDxwqBP+8CvdkLoP5w==
|
||||||
|
dependencies:
|
||||||
|
"@progress/kendo-file-saver" "^1.0.1"
|
||||||
|
|
||||||
"@redux-saga/core@^1.1.3":
|
"@redux-saga/core@^1.1.3":
|
||||||
version "1.1.3"
|
version "1.1.3"
|
||||||
resolved "https://registry.yarnpkg.com/@redux-saga/core/-/core-1.1.3.tgz#3085097b57a4ea8db5528d58673f20ce0950f6a4"
|
resolved "https://registry.yarnpkg.com/@redux-saga/core/-/core-1.1.3.tgz#3085097b57a4ea8db5528d58673f20ce0950f6a4"
|
||||||
|
@ -3502,13 +3521,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
|
||||||
safe-buffer "^5.0.1"
|
safe-buffer "^5.0.1"
|
||||||
sha.js "^2.4.8"
|
sha.js "^2.4.8"
|
||||||
|
|
||||||
cross-fetch@^3.0.4:
|
|
||||||
version "3.0.5"
|
|
||||||
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.0.5.tgz#2739d2981892e7ab488a7ad03b92df2816e03f4c"
|
|
||||||
integrity sha512-FFLcLtraisj5eteosnX1gf01qYDCOc4fDy0+euOt8Kn9YBY2NtXL/pCoYPavw24NIQkQqm5ZOLsGD5Zzj0gyew==
|
|
||||||
dependencies:
|
|
||||||
node-fetch "2.6.0"
|
|
||||||
|
|
||||||
cross-spawn@7.0.1:
|
cross-spawn@7.0.1:
|
||||||
version "7.0.1"
|
version "7.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
|
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
|
||||||
|
@ -6454,14 +6466,6 @@ jest-environment-node@^24.9.0:
|
||||||
jest-mock "^24.9.0"
|
jest-mock "^24.9.0"
|
||||||
jest-util "^24.9.0"
|
jest-util "^24.9.0"
|
||||||
|
|
||||||
jest-fetch-mock@^3.0.3:
|
|
||||||
version "3.0.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz#31749c456ae27b8919d69824f1c2bd85fe0a1f3b"
|
|
||||||
integrity sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==
|
|
||||||
dependencies:
|
|
||||||
cross-fetch "^3.0.4"
|
|
||||||
promise-polyfill "^8.1.3"
|
|
||||||
|
|
||||||
jest-get-type@^24.9.0:
|
jest-get-type@^24.9.0:
|
||||||
version "24.9.0"
|
version "24.9.0"
|
||||||
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-24.9.0.tgz#1684a0c8a50f2e4901b6644ae861f579eed2ef0e"
|
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-24.9.0.tgz#1684a0c8a50f2e4901b6644ae861f579eed2ef0e"
|
||||||
|
@ -7665,11 +7669,6 @@ no-case@^3.0.3:
|
||||||
lower-case "^2.0.1"
|
lower-case "^2.0.1"
|
||||||
tslib "^1.10.0"
|
tslib "^1.10.0"
|
||||||
|
|
||||||
node-fetch@2.6.0:
|
|
||||||
version "2.6.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
|
|
||||||
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
|
|
||||||
|
|
||||||
node-fetch@^1.0.1:
|
node-fetch@^1.0.1:
|
||||||
version "1.7.3"
|
version "1.7.3"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
|
||||||
|
@ -8110,7 +8109,7 @@ p-try@^2.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
|
resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6"
|
||||||
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
|
integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==
|
||||||
|
|
||||||
pako@~1.0.5:
|
pako@^1.0.5, pako@~1.0.5:
|
||||||
version "1.0.11"
|
version "1.0.11"
|
||||||
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
|
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
|
||||||
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
|
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
|
||||||
|
@ -9151,11 +9150,6 @@ promise-inflight@^1.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
|
resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3"
|
||||||
integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM=
|
integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM=
|
||||||
|
|
||||||
promise-polyfill@^8.1.3:
|
|
||||||
version "8.1.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-8.1.3.tgz#8c99b3cf53f3a91c68226ffde7bde81d7f904116"
|
|
||||||
integrity sha512-MG5r82wBzh7pSKDRa9y+vllNHz3e3d4CNj1PQE4BQYxLme0gKYYBm9YENq+UkEikyZ0XbiGWxYlVw3Rl9O/U8g==
|
|
||||||
|
|
||||||
promise@^7.1.1:
|
promise@^7.1.1:
|
||||||
version "7.3.1"
|
version "7.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
|
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
|
||||||
|
@ -9271,6 +9265,20 @@ q@^1.1.2:
|
||||||
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
|
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
|
||||||
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
|
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
|
||||||
|
|
||||||
|
qr.js@0.0.0:
|
||||||
|
version "0.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/qr.js/-/qr.js-0.0.0.tgz#cace86386f59a0db8050fa90d9b6b0e88a1e364f"
|
||||||
|
integrity sha1-ys6GOG9ZoNuAUPqQ2baw6IoeNk8=
|
||||||
|
|
||||||
|
qrcode.react@^1.0.0:
|
||||||
|
version "1.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/qrcode.react/-/qrcode.react-1.0.0.tgz#7e8889db3b769e555e8eb463d4c6de221c36d5de"
|
||||||
|
integrity sha512-jBXleohRTwvGBe1ngV+62QvEZ/9IZqQivdwzo9pJM4LQMoCM2VnvNBnKdjvGnKyDZ/l0nCDgsPod19RzlPvm/Q==
|
||||||
|
dependencies:
|
||||||
|
loose-envify "^1.4.0"
|
||||||
|
prop-types "^15.6.0"
|
||||||
|
qr.js "0.0.0"
|
||||||
|
|
||||||
qs@6.7.0:
|
qs@6.7.0:
|
||||||
version "6.7.0"
|
version "6.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
|
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue