Compare commits
39 commits
csv_import
...
master
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1f56bac356 | ||
![]() |
bbbca0c57c | ||
![]() |
314906657f | ||
![]() |
78e7c5f391 | ||
![]() |
1074178e31 | ||
![]() |
352ab1290a | ||
![]() |
12447b7708 | ||
![]() |
cd4efb7c07 | ||
![]() |
ff59ee4c2e | ||
![]() |
61938405e9 | ||
![]() |
ac0657c428 | ||
![]() |
ab709aee3e | ||
![]() |
6da3c8b885 | ||
![]() |
ab04db5baf | ||
![]() |
8282a3caf8 | ||
![]() |
2fc75cd6fc | ||
![]() |
3fd615943c | ||
![]() |
aaf1ebb909 | ||
![]() |
627f3d2917 | ||
![]() |
168e249296 | ||
![]() |
5bdfb80db7 | ||
![]() |
b7c3684b80 | ||
![]() |
0ada5287d7 | ||
![]() |
3884c50012 | ||
![]() |
300e22a537 | ||
![]() |
009ce803e2 | ||
![]() |
c41b8ab846 | ||
![]() |
7f16f784f9 | ||
![]() |
1002b6464a | ||
![]() |
50b770a312 | ||
![]() |
2d0ce50444 | ||
![]() |
1fb89c9e58 | ||
![]() |
8a4c0fe0fe | ||
![]() |
dd022eab04 | ||
![]() |
437fd70d6d | ||
![]() |
1e6e526e3c | ||
![]() |
d812cff5fc | ||
![]() |
a39033e25b | ||
![]() |
b7f009e559 |
18 changed files with 2697 additions and 1418 deletions
|
@ -1,5 +1,4 @@
|
||||||
# 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/
|
||||||
|
|
31
README.md
31
README.md
|
@ -4,6 +4,33 @@
|
||||||
|
|
||||||
This project is built using [react-admin](https://marmelab.com/react-admin/).
|
This project is built using [react-admin](https://marmelab.com/react-admin/).
|
||||||
|
|
||||||
Use `yarn install` after cloning this repo.
|
It needs at least Synapse v1.15.0 for all functions to work as expected!
|
||||||
|
|
||||||
Use `yarn start` to launch the webserver.
|
## Step-By-Step install:
|
||||||
|
|
||||||
|
You have two options:
|
||||||
|
|
||||||
|
1. Download the source code from github and run using nodejs
|
||||||
|
2. Run the Docker container
|
||||||
|
|
||||||
|
Steps for 1):
|
||||||
|
|
||||||
|
- make sure you have installed the following: git, yarn, nodejs
|
||||||
|
- download the source code: `git clone https://github.com/Awesome-Technologies/synapse-admin.git`
|
||||||
|
- change into downloaded directory: `cd synapse-admin`
|
||||||
|
- download dependencies: `yarn install`
|
||||||
|
- start web server: `yarn start`
|
||||||
|
|
||||||
|
Steps for 2):
|
||||||
|
|
||||||
|
- run the Docker container: `docker run -p 8080:80 awesometechnologies/synapse-admin`
|
||||||
|
- browse to http://localhost:8080
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
- Use `yarn test` to run all style, lint and unit tests
|
||||||
|
- Use `yarn fix` to fix the coding style
|
||||||
|
|
12
package.json
12
package.json
|
@ -1,9 +1,10 @@
|
||||||
{
|
{
|
||||||
"name": "synapse-admin",
|
"name": "synapse-admin",
|
||||||
"version": "0.1.0",
|
"version": "0.2.1",
|
||||||
"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",
|
||||||
|
"homepage": ".",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/Awesome-Technologies/synapse-admin"
|
"url": "https://github.com/Awesome-Technologies/synapse-admin"
|
||||||
|
@ -11,25 +12,26 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/jest-dom": "^5.1.1",
|
"@testing-library/jest-dom": "^5.1.1",
|
||||||
"@testing-library/react": "^10.0.2",
|
"@testing-library/react": "^10.0.2",
|
||||||
"@testing-library/user-event": "^10.0.1",
|
"@testing-library/user-event": "^12.0.11",
|
||||||
"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.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": {
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"ra-language-german": "^2.1.2",
|
"ra-language-german": "^2.1.2",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-admin": "^3.4.0",
|
"react-admin": "^3.7.0",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
"react-scripts": "^3.4.1"
|
"react-scripts": "^3.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "REACT_APP_VERSION=$(git describe --tags) react-scripts start",
|
||||||
"build": "react-scripts build",
|
"build": "REACT_APP_VERSION=$(git describe --tags) react-scripts build",
|
||||||
"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",
|
||||||
|
|
|
@ -38,5 +38,12 @@
|
||||||
To begin the development, run `npm start` or `yarn start`.
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
To create a production bundle, use `npm run build` or `yarn build`.
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
-->
|
-->
|
||||||
|
<footer
|
||||||
|
style="position: relative; z-index: 2; height: 2em; margin-top: -2em; line-height: 2em; background-color: #eee; border: 0.5px solid #ddd">
|
||||||
|
<a id="copyright" href="https://github.com/Awesome-Technologies/synapse-admin"
|
||||||
|
style="margin-left: 1em; color: #888; font-family: Roboto, Helvetica, Arial, sans-serif; font-weight: 100; font-size: 0.8em; text-decoration: none;">
|
||||||
|
Synapse-Admin <b>(%REACT_APP_VERSION%)</b> by Awesome Technologies Innovationslabor GmbH
|
||||||
|
</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
BIN
screenshots.jpg
Normal file
BIN
screenshots.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 222 KiB |
|
@ -4,7 +4,7 @@ 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 } from "./components/rooms";
|
import { RoomList, 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";
|
||||||
|
@ -35,8 +35,10 @@ const App = () => (
|
||||||
edit={UserEdit}
|
edit={UserEdit}
|
||||||
icon={UserIcon}
|
icon={UserIcon}
|
||||||
/>
|
/>
|
||||||
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
<Resource name="rooms" list={RoomList} show={RoomShow} icon={RoomIcon} />
|
||||||
<Resource name="connections" />
|
<Resource name="connections" />
|
||||||
|
<Resource name="devices" />
|
||||||
|
<Resource name="servernotices" />
|
||||||
</Admin>
|
</Admin>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
|
fetchUtils,
|
||||||
|
FormDataConsumer,
|
||||||
Notification,
|
Notification,
|
||||||
useLogin,
|
useLogin,
|
||||||
useNotify,
|
useNotify,
|
||||||
useLocale,
|
useLocale,
|
||||||
useSetLocale,
|
useSetLocale,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
|
PasswordInput,
|
||||||
|
TextInput,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
import { Field, Form } from "react-final-form";
|
import { Form, useForm } from "react-final-form";
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Button,
|
Button,
|
||||||
|
@ -25,7 +29,7 @@ const useStyles = makeStyles(theme => ({
|
||||||
main: {
|
main: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
minHeight: "100vh",
|
minHeight: "calc(100vh - 1em)",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "flex-start",
|
justifyContent: "flex-start",
|
||||||
background: "url(./images/floating-cogs.svg)",
|
background: "url(./images/floating-cogs.svg)",
|
||||||
|
@ -34,8 +38,9 @@ const useStyles = makeStyles(theme => ({
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
minWidth: 300,
|
minWidth: "30em",
|
||||||
marginTop: "6em",
|
marginTop: "6em",
|
||||||
|
marginBottom: "6em",
|
||||||
},
|
},
|
||||||
avatar: {
|
avatar: {
|
||||||
margin: "1em",
|
margin: "1em",
|
||||||
|
@ -60,6 +65,12 @@ const useStyles = makeStyles(theme => ({
|
||||||
actions: {
|
actions: {
|
||||||
padding: "0 1em 1em 1em",
|
padding: "0 1em 1em 1em",
|
||||||
},
|
},
|
||||||
|
serverVersion: {
|
||||||
|
color: "#9e9e9e",
|
||||||
|
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
|
||||||
|
marginBottom: "1em",
|
||||||
|
marginLeft: "0.5em",
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const LoginPage = ({ theme }) => {
|
const LoginPage = ({ theme }) => {
|
||||||
|
@ -70,7 +81,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("base_url");
|
const base_url = localStorage.getItem("base_url");
|
||||||
|
|
||||||
const renderInput = ({
|
const renderInput = ({
|
||||||
meta: { touched, error } = {},
|
meta: { touched, error } = {},
|
||||||
|
@ -88,15 +99,23 @@ const LoginPage = ({ theme }) => {
|
||||||
|
|
||||||
const validate = values => {
|
const validate = values => {
|
||||||
const errors = {};
|
const errors = {};
|
||||||
if (!values.homeserver) {
|
|
||||||
errors.homeserver = translate("ra.validation.required");
|
|
||||||
}
|
|
||||||
if (!values.username) {
|
if (!values.username) {
|
||||||
errors.username = translate("ra.validation.required");
|
errors.username = translate("ra.validation.required");
|
||||||
}
|
}
|
||||||
if (!values.password) {
|
if (!values.password) {
|
||||||
errors.password = translate("ra.validation.required");
|
errors.password = translate("ra.validation.required");
|
||||||
}
|
}
|
||||||
|
if (!values.base_url) {
|
||||||
|
errors.base_url = translate("ra.validation.required");
|
||||||
|
} else {
|
||||||
|
if (!values.base_url.match(/^(http|https):\/\//)) {
|
||||||
|
errors.base_url = translate("synapseadmin.auth.protocol_error");
|
||||||
|
} else if (
|
||||||
|
!values.base_url.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+(:\d{1,5})?$/)
|
||||||
|
) {
|
||||||
|
errors.base_url = translate("synapseadmin.auth.url_error");
|
||||||
|
}
|
||||||
|
}
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,9 +134,101 @@ const LoginPage = ({ theme }) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const extractHomeServer = username => {
|
||||||
|
const usernameRegex = /@[a-zA-Z0-9._=\-/]+:([a-zA-Z0-9\-.]+\.[a-zA-Z]+)/;
|
||||||
|
if (!username) return null;
|
||||||
|
const res = username.match(usernameRegex);
|
||||||
|
if (res) return res[1];
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const UserData = ({ formData }) => {
|
||||||
|
const form = useForm();
|
||||||
|
const [serverVersion, setServerVersion] = useState("");
|
||||||
|
|
||||||
|
const handleUsernameChange = _ => {
|
||||||
|
if (formData.base_url) return;
|
||||||
|
// check if username is a full qualified userId then set base_url accordially
|
||||||
|
const home_server = extractHomeServer(formData.username);
|
||||||
|
const wellKnownUrl = `https://${home_server}/.well-known/matrix/client`;
|
||||||
|
if (home_server) {
|
||||||
|
// fetch .well-known entry to get base_url
|
||||||
|
fetchUtils
|
||||||
|
.fetchJson(wellKnownUrl, { method: "GET" })
|
||||||
|
.then(({ json }) => {
|
||||||
|
form.change("base_url", json["m.homeserver"].base_url);
|
||||||
|
})
|
||||||
|
.catch(_ => {
|
||||||
|
// if there is no .well-known entry, try the home server name
|
||||||
|
form.change("base_url", `https://${home_server}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
_ => {
|
||||||
|
if (
|
||||||
|
!formData.base_url ||
|
||||||
|
!formData.base_url.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+$/)
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
const versionUrl = `${formData.base_url}/_synapse/admin/v1/server_version`;
|
||||||
|
fetchUtils
|
||||||
|
.fetchJson(versionUrl, { method: "GET" })
|
||||||
|
.then(({ json }) => {
|
||||||
|
setServerVersion(
|
||||||
|
`${translate("synapseadmin.auth.server_version")} ${
|
||||||
|
json["server_version"]
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(_ => {
|
||||||
|
setServerVersion("");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[formData.base_url]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className={classes.input}>
|
||||||
|
<TextInput
|
||||||
|
autoFocus
|
||||||
|
name="username"
|
||||||
|
component={renderInput}
|
||||||
|
label={translate("ra.auth.username")}
|
||||||
|
disabled={loading}
|
||||||
|
onBlur={handleUsernameChange}
|
||||||
|
fullWidth
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={classes.input}>
|
||||||
|
<PasswordInput
|
||||||
|
name="password"
|
||||||
|
component={renderInput}
|
||||||
|
label={translate("ra.auth.password")}
|
||||||
|
type="password"
|
||||||
|
disabled={loading}
|
||||||
|
fullWidth
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={classes.input}>
|
||||||
|
<TextInput
|
||||||
|
name="base_url"
|
||||||
|
component={renderInput}
|
||||||
|
label={translate("synapseadmin.auth.base_url")}
|
||||||
|
disabled={loading}
|
||||||
|
fullWidth
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={classes.serverVersion}>{serverVersion}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
initialValues={{ homeserver: homeserver }}
|
initialValues={{ base_url: base_url }}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
validate={validate}
|
validate={validate}
|
||||||
render={({ handleSubmit }) => (
|
render={({ handleSubmit }) => (
|
||||||
|
@ -146,32 +257,9 @@ const LoginPage = ({ theme }) => {
|
||||||
<MenuItem value="en">English</MenuItem>
|
<MenuItem value="en">English</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.input}>
|
<FormDataConsumer>
|
||||||
<Field
|
{formDataProps => <UserData {...formDataProps} />}
|
||||||
autoFocus
|
</FormDataConsumer>
|
||||||
name="homeserver"
|
|
||||||
component={renderInput}
|
|
||||||
label={translate("synapseadmin.auth.homeserver")}
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className={classes.input}>
|
|
||||||
<Field
|
|
||||||
name="username"
|
|
||||||
component={renderInput}
|
|
||||||
label={translate("ra.auth.username")}
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className={classes.input}>
|
|
||||||
<Field
|
|
||||||
name="password"
|
|
||||||
component={renderInput}
|
|
||||||
label={translate("ra.auth.password")}
|
|
||||||
type="password"
|
|
||||||
disabled={loading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<CardActions className={classes.actions}>
|
<CardActions className={classes.actions}>
|
||||||
<Button
|
<Button
|
||||||
|
|
148
src/components/ServerNotices.js
Normal file
148
src/components/ServerNotices.js
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
import React, { Fragment, useState } from "react";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
SaveButton,
|
||||||
|
SimpleForm,
|
||||||
|
TextInput,
|
||||||
|
Toolbar,
|
||||||
|
required,
|
||||||
|
useCreate,
|
||||||
|
useMutation,
|
||||||
|
useNotify,
|
||||||
|
useTranslate,
|
||||||
|
useUnselectAll,
|
||||||
|
} from "react-admin";
|
||||||
|
import MessageIcon from "@material-ui/icons/Message";
|
||||||
|
import IconCancel from "@material-ui/icons/Cancel";
|
||||||
|
import Dialog from "@material-ui/core/Dialog";
|
||||||
|
import DialogContent from "@material-ui/core/DialogContent";
|
||||||
|
import DialogContentText from "@material-ui/core/DialogContentText";
|
||||||
|
import DialogTitle from "@material-ui/core/DialogTitle";
|
||||||
|
|
||||||
|
const ServerNoticeDialog = ({ open, loading, onClose, onSend }) => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
|
||||||
|
const ServerNoticeToolbar = props => (
|
||||||
|
<Toolbar {...props}>
|
||||||
|
<SaveButton label="resources.servernotices.action.send" />
|
||||||
|
<Button label="ra.action.cancel" onClick={onClose}>
|
||||||
|
<IconCancel />
|
||||||
|
</Button>
|
||||||
|
</Toolbar>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onClose={onClose} loading={loading}>
|
||||||
|
<DialogTitle>
|
||||||
|
{translate("resources.servernotices.action.send")}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogContentText>
|
||||||
|
{translate("resources.servernotices.helper.send")}
|
||||||
|
</DialogContentText>
|
||||||
|
<SimpleForm
|
||||||
|
toolbar={<ServerNoticeToolbar />}
|
||||||
|
submitOnEnter={false}
|
||||||
|
redirect={false}
|
||||||
|
save={onSend}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
source="body"
|
||||||
|
label="resources.servernotices.fields.body"
|
||||||
|
fullWidth
|
||||||
|
multiline
|
||||||
|
rows="4"
|
||||||
|
resettable
|
||||||
|
validate={required()}
|
||||||
|
/>
|
||||||
|
</SimpleForm>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ServerNoticeButton = ({ record }) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const notify = useNotify();
|
||||||
|
const [create, { loading }] = useCreate("servernotices");
|
||||||
|
|
||||||
|
const handleDialogOpen = () => setOpen(true);
|
||||||
|
const handleDialogClose = () => setOpen(false);
|
||||||
|
|
||||||
|
const handleSend = values => {
|
||||||
|
create(
|
||||||
|
{ payload: { data: { id: record.id, ...values } } },
|
||||||
|
{
|
||||||
|
onSuccess: () => {
|
||||||
|
notify("resources.servernotices.action.send_success");
|
||||||
|
handleDialogClose();
|
||||||
|
},
|
||||||
|
onFailure: () =>
|
||||||
|
notify("resources.servernotices.action.send_failure", "error"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<Button
|
||||||
|
label="resources.servernotices.send"
|
||||||
|
onClick={handleDialogOpen}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<MessageIcon />
|
||||||
|
</Button>
|
||||||
|
<ServerNoticeDialog
|
||||||
|
open={open}
|
||||||
|
onClose={handleDialogClose}
|
||||||
|
onSend={handleSend}
|
||||||
|
/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ServerNoticeBulkButton = ({ selectedIds }) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const notify = useNotify();
|
||||||
|
const unselectAll = useUnselectAll();
|
||||||
|
const [createMany, { loading }] = useMutation();
|
||||||
|
|
||||||
|
const handleDialogOpen = () => setOpen(true);
|
||||||
|
const handleDialogClose = () => setOpen(false);
|
||||||
|
|
||||||
|
const handleSend = values => {
|
||||||
|
createMany(
|
||||||
|
{
|
||||||
|
type: "createMany",
|
||||||
|
resource: "servernotices",
|
||||||
|
payload: { ids: selectedIds, data: values },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess: ({ data }) => {
|
||||||
|
notify("resources.servernotices.action.send_success");
|
||||||
|
unselectAll("users");
|
||||||
|
handleDialogClose();
|
||||||
|
},
|
||||||
|
onFailure: error =>
|
||||||
|
notify("resources.servernotices.action.send_failure", "error"),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<Button
|
||||||
|
label="resources.servernotices.send"
|
||||||
|
onClick={handleDialogOpen}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<MessageIcon />
|
||||||
|
</Button>
|
||||||
|
<ServerNoticeDialog
|
||||||
|
open={open}
|
||||||
|
onClose={handleDialogClose}
|
||||||
|
onSend={handleSend}
|
||||||
|
/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
};
|
89
src/components/devices.js
Normal file
89
src/components/devices.js
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
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,17 +1,224 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Datagrid, List, TextField, Pagination } from "react-admin";
|
import { connect } from "react-redux";
|
||||||
|
import {
|
||||||
|
BooleanField,
|
||||||
|
Datagrid,
|
||||||
|
Filter,
|
||||||
|
List,
|
||||||
|
Pagination,
|
||||||
|
SelectField,
|
||||||
|
Show,
|
||||||
|
Tab,
|
||||||
|
TabbedShowLayout,
|
||||||
|
TextField,
|
||||||
|
useTranslate,
|
||||||
|
} from "react-admin";
|
||||||
|
import get from "lodash/get";
|
||||||
|
import { Tooltip, Typography, Chip } from "@material-ui/core";
|
||||||
|
import HttpsIcon from "@material-ui/icons/Https";
|
||||||
|
import NoEncryptionIcon from "@material-ui/icons/NoEncryption";
|
||||||
|
import PageviewIcon from "@material-ui/icons/Pageview";
|
||||||
|
import ViewListIcon from "@material-ui/icons/ViewList";
|
||||||
|
import VisibilityIcon from "@material-ui/icons/Visibility";
|
||||||
|
|
||||||
const RoomPagination = props => (
|
const RoomPagination = props => (
|
||||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||||
);
|
);
|
||||||
|
|
||||||
export const RoomList = props => (
|
const EncryptionField = ({ source, record = {}, emptyText }) => {
|
||||||
<List {...props} pagination={<RoomPagination />}>
|
const translate = useTranslate();
|
||||||
<Datagrid>
|
const value = get(record, source);
|
||||||
|
let ariaLabel = value === false ? "ra.boolean.false" : "ra.boolean.true";
|
||||||
|
|
||||||
|
if (value === false || value === true) {
|
||||||
|
return (
|
||||||
|
<Typography component="span" variant="body2">
|
||||||
|
<Tooltip title={translate(ariaLabel, { _: ariaLabel })}>
|
||||||
|
{value === true ? (
|
||||||
|
<HttpsIcon data-testid="true" htmlColor="limegreen" />
|
||||||
|
) : (
|
||||||
|
<NoEncryptionIcon data-testid="false" color="error" />
|
||||||
|
)}
|
||||||
|
</Tooltip>
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Typography component="span" variant="body2">
|
||||||
|
{emptyText}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const RoomTitle = ({ record }) => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
var name = "";
|
||||||
|
if (record) {
|
||||||
|
name = record.name !== "" ? record.name : record.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{translate("resources.rooms.name", 1)} {name}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RoomShow = props => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<Show {...props} title={<RoomTitle />}>
|
||||||
|
<TabbedShowLayout>
|
||||||
|
<Tab label="synapseadmin.rooms.tabs.basic" icon={<ViewListIcon />}>
|
||||||
<TextField source="room_id" />
|
<TextField source="room_id" />
|
||||||
<TextField source="name" />
|
<TextField source="name" />
|
||||||
<TextField source="canonical_alias" />
|
<TextField source="canonical_alias" />
|
||||||
|
<TextField source="creator" />
|
||||||
|
</Tab>
|
||||||
|
|
||||||
|
<Tab
|
||||||
|
label="synapseadmin.rooms.tabs.detail"
|
||||||
|
icon={<PageviewIcon />}
|
||||||
|
path="detail"
|
||||||
|
>
|
||||||
<TextField source="joined_members" />
|
<TextField source="joined_members" />
|
||||||
|
<TextField source="joined_local_members" />
|
||||||
|
<TextField source="state_events" />
|
||||||
|
<TextField source="version" />
|
||||||
|
<TextField
|
||||||
|
source="encryption"
|
||||||
|
emptyText={translate("resources.rooms.enums.unencrypted")}
|
||||||
|
/>
|
||||||
|
</Tab>
|
||||||
|
|
||||||
|
<Tab
|
||||||
|
label="synapseadmin.rooms.tabs.permission"
|
||||||
|
icon={<VisibilityIcon />}
|
||||||
|
path="permission"
|
||||||
|
>
|
||||||
|
<BooleanField source="federatable" />
|
||||||
|
<BooleanField source="public" />
|
||||||
|
<SelectField
|
||||||
|
source="join_rules"
|
||||||
|
choices={[
|
||||||
|
{ id: "public", name: "resources.rooms.enums.join_rules.public" },
|
||||||
|
{ id: "knock", name: "resources.rooms.enums.join_rules.knock" },
|
||||||
|
{ id: "invite", name: "resources.rooms.enums.join_rules.invite" },
|
||||||
|
{
|
||||||
|
id: "private",
|
||||||
|
name: "resources.rooms.enums.join_rules.private",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<SelectField
|
||||||
|
source="guest_access"
|
||||||
|
choices={[
|
||||||
|
{
|
||||||
|
id: "can_join",
|
||||||
|
name: "resources.rooms.enums.guest_access.can_join",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "forbidden",
|
||||||
|
name: "resources.rooms.enums.guest_access.forbidden",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<SelectField
|
||||||
|
source="history_visibility"
|
||||||
|
choices={[
|
||||||
|
{
|
||||||
|
id: "invited",
|
||||||
|
name: "resources.rooms.enums.history_visibility.invited",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "joined",
|
||||||
|
name: "resources.rooms.enums.history_visibility.joined",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "shared",
|
||||||
|
name: "resources.rooms.enums.history_visibility.shared",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "world_readable",
|
||||||
|
name: "resources.rooms.enums.history_visibility.world_readable",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Tab>
|
||||||
|
</TabbedShowLayout>
|
||||||
|
</Show>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const RoomFilter = ({ ...props }) => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<Filter {...props}>
|
||||||
|
<Chip
|
||||||
|
label={translate("resources.rooms.fields.joined_local_members")}
|
||||||
|
source="joined_local_members"
|
||||||
|
defaultValue={false}
|
||||||
|
style={{ marginBottom: 8 }}
|
||||||
|
/>
|
||||||
|
<Chip
|
||||||
|
label={translate("resources.rooms.fields.state_events")}
|
||||||
|
source="state_events"
|
||||||
|
defaultValue={false}
|
||||||
|
style={{ marginBottom: 8 }}
|
||||||
|
/>
|
||||||
|
<Chip
|
||||||
|
label={translate("resources.rooms.fields.version")}
|
||||||
|
source="version"
|
||||||
|
defaultValue={false}
|
||||||
|
style={{ marginBottom: 8 }}
|
||||||
|
/>
|
||||||
|
<Chip
|
||||||
|
label={translate("resources.rooms.fields.federatable")}
|
||||||
|
source="federatable"
|
||||||
|
defaultValue={false}
|
||||||
|
style={{ marginBottom: 8 }}
|
||||||
|
/>
|
||||||
|
</Filter>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const FilterableRoomList = ({ ...props }) => {
|
||||||
|
const filter = props.roomFilters;
|
||||||
|
const localMembersFilter =
|
||||||
|
filter && filter.joined_local_members ? true : false;
|
||||||
|
const stateEventsFilter = filter && filter.state_events ? true : false;
|
||||||
|
const versionFilter = filter && filter.version ? true : false;
|
||||||
|
const federateableFilter = filter && filter.federatable ? true : false;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<List
|
||||||
|
{...props}
|
||||||
|
pagination={<RoomPagination />}
|
||||||
|
sort={{ field: "name", order: "ASC" }}
|
||||||
|
filters={<RoomFilter />}
|
||||||
|
>
|
||||||
|
<Datagrid rowClick="show">
|
||||||
|
<EncryptionField
|
||||||
|
source="is_encrypted"
|
||||||
|
sortBy="encryption"
|
||||||
|
label={<HttpsIcon />}
|
||||||
|
/>
|
||||||
|
<TextField source="name" />
|
||||||
|
<TextField source="joined_members" />
|
||||||
|
{localMembersFilter && <TextField source="joined_local_members" />}
|
||||||
|
{stateEventsFilter && <TextField source="state_events" />}
|
||||||
|
{versionFilter && <TextField source="version" />}
|
||||||
|
{federateableFilter && <BooleanField source="federatable" />}
|
||||||
|
<BooleanField source="public" />
|
||||||
</Datagrid>
|
</Datagrid>
|
||||||
</List>
|
</List>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function mapStateToProps(state) {
|
||||||
|
return {
|
||||||
|
roomFilters: state.admin.resources.rooms.list.params.displayedFilters,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RoomList = connect(mapStateToProps)(FilterableRoomList);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import React from "react";
|
import React, { cloneElement, Fragment } from "react";
|
||||||
|
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 DevicesIcon from "@material-ui/icons/Devices";
|
||||||
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
||||||
import {
|
import {
|
||||||
ArrayInput,
|
ArrayInput,
|
||||||
|
@ -10,21 +13,84 @@ import {
|
||||||
Edit,
|
Edit,
|
||||||
List,
|
List,
|
||||||
Filter,
|
Filter,
|
||||||
|
Toolbar,
|
||||||
SimpleForm,
|
SimpleForm,
|
||||||
SimpleFormIterator,
|
SimpleFormIterator,
|
||||||
TabbedForm,
|
TabbedForm,
|
||||||
FormTab,
|
FormTab,
|
||||||
BooleanField,
|
BooleanField,
|
||||||
BooleanInput,
|
BooleanInput,
|
||||||
ImageField,
|
|
||||||
PasswordInput,
|
PasswordInput,
|
||||||
TextField,
|
TextField,
|
||||||
TextInput,
|
TextInput,
|
||||||
ReferenceField,
|
ReferenceField,
|
||||||
|
ReferenceManyField,
|
||||||
SelectInput,
|
SelectInput,
|
||||||
|
BulkDeleteButton,
|
||||||
|
DeleteButton,
|
||||||
|
SaveButton,
|
||||||
regex,
|
regex,
|
||||||
|
useTranslate,
|
||||||
Pagination,
|
Pagination,
|
||||||
|
CreateButton,
|
||||||
|
ExportButton,
|
||||||
|
TopToolbar,
|
||||||
|
sanitizeListRestProps,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
|
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||||
|
import { DeviceRemoveButton } from "./devices";
|
||||||
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
small: {
|
||||||
|
height: "40px",
|
||||||
|
width: "40px",
|
||||||
|
},
|
||||||
|
large: {
|
||||||
|
height: "120px",
|
||||||
|
width: "120px",
|
||||||
|
float: "right",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const UserListActions = ({
|
||||||
|
currentSort,
|
||||||
|
className,
|
||||||
|
resource,
|
||||||
|
filters,
|
||||||
|
displayedFilters,
|
||||||
|
exporter, // you can hide ExportButton if exporter = (null || false)
|
||||||
|
filterValues,
|
||||||
|
permanentFilter,
|
||||||
|
hasCreate, // you can hide CreateButton if hasCreate = false
|
||||||
|
basePath,
|
||||||
|
selectedIds,
|
||||||
|
onUnselectItems,
|
||||||
|
showFilter,
|
||||||
|
maxResults,
|
||||||
|
total,
|
||||||
|
...rest
|
||||||
|
}) => (
|
||||||
|
<TopToolbar className={className} {...sanitizeListRestProps(rest)}>
|
||||||
|
{filters &&
|
||||||
|
cloneElement(filters, {
|
||||||
|
resource,
|
||||||
|
showFilter,
|
||||||
|
displayedFilters,
|
||||||
|
filterValues,
|
||||||
|
context: "button",
|
||||||
|
})}
|
||||||
|
<CreateButton basePath={basePath} />
|
||||||
|
<ExportButton
|
||||||
|
disabled={total === 0}
|
||||||
|
resource={resource}
|
||||||
|
sort={currentSort}
|
||||||
|
filter={{ ...filterValues, ...permanentFilter }}
|
||||||
|
exporter={exporter}
|
||||||
|
maxResults={maxResults}
|
||||||
|
/>
|
||||||
|
</TopToolbar>
|
||||||
|
);
|
||||||
|
|
||||||
const UserPagination = props => (
|
const UserPagination = props => (
|
||||||
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
<Pagination {...props} rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||||
|
@ -41,39 +107,50 @@ const UserFilter = props => (
|
||||||
</Filter>
|
</Filter>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const UserList = props => (
|
const UserBulkActionButtons = props => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<ServerNoticeBulkButton {...props} />
|
||||||
|
<BulkDeleteButton
|
||||||
|
{...props}
|
||||||
|
label="resources.users.action.erase"
|
||||||
|
title={translate("resources.users.helper.erase")}
|
||||||
|
/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const AvatarField = ({ source, className, record = {} }) => (
|
||||||
|
<Avatar src={record[source]} className={className} />
|
||||||
|
);
|
||||||
|
|
||||||
|
export const UserList = props => {
|
||||||
|
const classes = useStyles();
|
||||||
|
return (
|
||||||
<List
|
<List
|
||||||
{...props}
|
{...props}
|
||||||
filters={<UserFilter />}
|
filters={<UserFilter />}
|
||||||
filterDefaultValues={{ guests: true, deactivated: false }}
|
filterDefaultValues={{ guests: true, deactivated: false }}
|
||||||
bulkActionButtons={false}
|
actions={<UserListActions maxResults={10000} />}
|
||||||
|
bulkActionButtons={<UserBulkActionButtons />}
|
||||||
pagination={<UserPagination />}
|
pagination={<UserPagination />}
|
||||||
>
|
>
|
||||||
<Datagrid rowClick="edit">
|
<Datagrid rowClick="edit">
|
||||||
<ReferenceField
|
<AvatarField
|
||||||
source="Avatar"
|
source="avatar_src"
|
||||||
reference="users"
|
|
||||||
link={false}
|
|
||||||
sortable={false}
|
sortable={false}
|
||||||
>
|
className={classes.small}
|
||||||
<ImageField source="avatar_url" title="displayname" />
|
/>
|
||||||
</ReferenceField>
|
<TextField source="id" sortable={false} />
|
||||||
<TextField source="id" />
|
<TextField source="displayname" sortable={false} />
|
||||||
{/* Hack since the users endpoint does not give displaynames in the list*/}
|
|
||||||
<ReferenceField
|
|
||||||
source="name"
|
|
||||||
reference="users"
|
|
||||||
link={false}
|
|
||||||
sortable={false}
|
|
||||||
>
|
|
||||||
<TextField source="displayname" />
|
|
||||||
</ReferenceField>
|
|
||||||
<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} />
|
||||||
</Datagrid>
|
</Datagrid>
|
||||||
</List>
|
</List>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// https://matrix.org/docs/spec/appendices#user-identifiers
|
// https://matrix.org/docs/spec/appendices#user-identifiers
|
||||||
const validateUser = regex(
|
const validateUser = regex(
|
||||||
|
@ -81,6 +158,20 @@ 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")}
|
||||||
|
/>
|
||||||
|
<ServerNoticeButton />
|
||||||
|
</Toolbar>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const UserCreate = props => (
|
export const UserCreate = props => (
|
||||||
<Create {...props}>
|
<Create {...props}>
|
||||||
<SimpleForm>
|
<SimpleForm>
|
||||||
|
@ -104,10 +195,29 @@ export const UserCreate = props => (
|
||||||
</Create>
|
</Create>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const UserEdit = props => (
|
const UserTitle = ({ record }) => {
|
||||||
<Edit {...props}>
|
const translate = useTranslate();
|
||||||
<TabbedForm>
|
return (
|
||||||
|
<span>
|
||||||
|
{translate("resources.users.name", {
|
||||||
|
smart_count: 1,
|
||||||
|
})}{" "}
|
||||||
|
{record ? `"${record.displayname}"` : ""}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const UserEdit = props => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<Edit {...props} title={<UserTitle />}>
|
||||||
|
<TabbedForm toolbar={<UserEditToolbar />}>
|
||||||
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
|
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
|
||||||
|
<AvatarField
|
||||||
|
source="avatar_src"
|
||||||
|
sortable={false}
|
||||||
|
className={classes.large}
|
||||||
|
/>
|
||||||
<TextInput source="id" disabled />
|
<TextInput source="id" disabled />
|
||||||
<TextInput source="displayname" />
|
<TextInput source="displayname" />
|
||||||
<PasswordInput source="password" autoComplete="new-password" />
|
<PasswordInput source="password" autoComplete="new-password" />
|
||||||
|
@ -116,6 +226,25 @@ export const UserEdit = props => (
|
||||||
source="deactivated"
|
source="deactivated"
|
||||||
helperText="resources.users.helper.deactivate"
|
helperText="resources.users.helper.deactivate"
|
||||||
/>
|
/>
|
||||||
|
<DateField
|
||||||
|
source="creation_ts_ms"
|
||||||
|
showTime
|
||||||
|
options={{
|
||||||
|
year: "numeric",
|
||||||
|
month: "2-digit",
|
||||||
|
day: "2-digit",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<TextField source="consent_version" />
|
||||||
|
</FormTab>
|
||||||
|
<FormTab
|
||||||
|
label="resources.users.threepid"
|
||||||
|
icon={<ContactMailIcon />}
|
||||||
|
path="threepid"
|
||||||
|
>
|
||||||
<ArrayInput source="threepids">
|
<ArrayInput source="threepids">
|
||||||
<SimpleFormIterator>
|
<SimpleFormIterator>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
|
@ -129,11 +258,48 @@ 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 />}
|
||||||
|
path="connections"
|
||||||
|
>
|
||||||
|
<ReferenceField
|
||||||
|
reference="connections"
|
||||||
|
source="id"
|
||||||
|
addLabel={false}
|
||||||
|
link={false}
|
||||||
>
|
>
|
||||||
<ReferenceField reference="connections" source="id" addLabel={false}>
|
|
||||||
<ArrayField
|
<ArrayField
|
||||||
source="devices[].sessions[0].connections"
|
source="devices[].sessions[0].connections"
|
||||||
label="resources.connections.name"
|
label="resources.connections.name"
|
||||||
|
@ -165,3 +331,4 @@ export const UserEdit = props => (
|
||||||
</TabbedForm>
|
</TabbedForm>
|
||||||
</Edit>
|
</Edit>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
106
src/i18n/de.js
106
src/i18n/de.js
|
@ -4,13 +4,26 @@ export default {
|
||||||
...germanMessages,
|
...germanMessages,
|
||||||
synapseadmin: {
|
synapseadmin: {
|
||||||
auth: {
|
auth: {
|
||||||
homeserver: "Heimserver",
|
base_url: "Heimserver URL",
|
||||||
welcome: "Willkommen bei Synapse-admin",
|
welcome: "Willkommen bei Synapse-admin",
|
||||||
|
server_version: "Synapse Version",
|
||||||
|
username_error: "Bitte vollständigen Nutzernamen angeben: '@user:domain'",
|
||||||
|
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
|
||||||
|
url_error: "Keine gültige Matrix Server URL",
|
||||||
},
|
},
|
||||||
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: {
|
||||||
|
details: "Raumdetails",
|
||||||
|
tabs: {
|
||||||
|
basic: "Allgemein",
|
||||||
|
members: "Mitglieder",
|
||||||
|
detail: "Details",
|
||||||
|
permission: "Berechtigungen",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
resources: {
|
resources: {
|
||||||
users: {
|
users: {
|
||||||
|
@ -18,12 +31,13 @@ export default {
|
||||||
name: "Benutzer",
|
name: "Benutzer",
|
||||||
email: "E-Mail",
|
email: "E-Mail",
|
||||||
msisdn: "Telefon",
|
msisdn: "Telefon",
|
||||||
|
threepid: "E-Mail / Telefon",
|
||||||
fields: {
|
fields: {
|
||||||
avatar: "Avatar",
|
avatar: "Avatar",
|
||||||
id: "Benutzer-ID",
|
id: "Benutzer-ID",
|
||||||
name: "Name",
|
name: "Name",
|
||||||
is_guest: "Gast",
|
is_guest: "Gast",
|
||||||
admin: "Admin",
|
admin: "Server Administrator",
|
||||||
deactivated: "Deaktiviert",
|
deactivated: "Deaktiviert",
|
||||||
guests: "Zeige Gäste",
|
guests: "Zeige Gäste",
|
||||||
show_deactivated: "Zeige deaktivierte Benutzer",
|
show_deactivated: "Zeige deaktivierte Benutzer",
|
||||||
|
@ -31,12 +45,24 @@ export default {
|
||||||
displayname: "Anzeigename",
|
displayname: "Anzeigename",
|
||||||
password: "Passwort",
|
password: "Passwort",
|
||||||
avatar_url: "Avatar URL",
|
avatar_url: "Avatar URL",
|
||||||
|
avatar_src: "Avatar",
|
||||||
medium: "Medium",
|
medium: "Medium",
|
||||||
threepids: "3PIDs",
|
threepids: "3PIDs",
|
||||||
address: "Adresse",
|
address: "Adresse",
|
||||||
|
creation_ts_ms: "Zeitpunkt der Erstellung",
|
||||||
|
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.",
|
||||||
|
erase: "DSGVO konformes Löschen der Benutzerdaten",
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
erase: "Lösche Benutzerdaten",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
|
@ -46,6 +72,36 @@ export default {
|
||||||
name: "Name",
|
name: "Name",
|
||||||
canonical_alias: "Alias",
|
canonical_alias: "Alias",
|
||||||
joined_members: "Mitglieder",
|
joined_members: "Mitglieder",
|
||||||
|
joined_local_members: "Lokale Mitglieder",
|
||||||
|
state_events: "Ereignisse",
|
||||||
|
version: "Version",
|
||||||
|
is_encrypted: "Verschlüsselt",
|
||||||
|
encryption: "Verschlüsselungs-Algorithmus",
|
||||||
|
federatable: "Föderierbar",
|
||||||
|
public: "Öffentlich",
|
||||||
|
creator: "Ersteller",
|
||||||
|
join_rules: "Beitrittsregeln",
|
||||||
|
guest_access: "Gastzugriff",
|
||||||
|
history_visibility: "Historie-Sichtbarkeit",
|
||||||
|
},
|
||||||
|
enums: {
|
||||||
|
join_rules: {
|
||||||
|
public: "Öffentlich",
|
||||||
|
knock: "Auf Anfrage",
|
||||||
|
invite: "Nur auf Einladung",
|
||||||
|
private: "Privat",
|
||||||
|
},
|
||||||
|
guest_access: {
|
||||||
|
can_join: "Gäste können beitreten",
|
||||||
|
forbidden: "Gäste können nicht beitreten",
|
||||||
|
},
|
||||||
|
history_visibility: {
|
||||||
|
invited: "Ab Einladung",
|
||||||
|
joined: "Ab Beitritt",
|
||||||
|
shared: "Ab Setzen der Einstellung",
|
||||||
|
world_readable: "Jeder",
|
||||||
|
},
|
||||||
|
unencrypted: "Nicht verschlüsselt",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
connections: {
|
connections: {
|
||||||
|
@ -56,5 +112,51 @@ 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: {
|
||||||
|
name: "Serverbenachrichtigungen",
|
||||||
|
send: "Servernachricht versenden",
|
||||||
|
fields: {
|
||||||
|
body: "Nachricht",
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
send: "Sende Nachricht",
|
||||||
|
send_success: "Nachricht erfolgreich versendet.",
|
||||||
|
send_failure: "Beim Versenden ist ein Fehler aufgetreten.",
|
||||||
|
},
|
||||||
|
helper: {
|
||||||
|
send:
|
||||||
|
'Sendet eine Serverbenachrichtigung an die ausgewählten Nutzer. Hierfür muss das Feature "Server Notices" auf dem Server aktiviert sein.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ra: {
|
||||||
|
...germanMessages.ra,
|
||||||
|
auth: {
|
||||||
|
...germanMessages.ra.auth,
|
||||||
|
auth_check_error: "Anmeldung fehlgeschlagen",
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
...germanMessages.ra.input,
|
||||||
|
password: {
|
||||||
|
...germanMessages.ra.input.password,
|
||||||
|
toggle_hidden: "Anzeigen",
|
||||||
|
toggle_visible: "Verstecken",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
notification: {
|
||||||
|
...germanMessages.ra.notifiaction,
|
||||||
|
logged_out: "Abgemeldet",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,13 +4,24 @@ export default {
|
||||||
...englishMessages,
|
...englishMessages,
|
||||||
synapseadmin: {
|
synapseadmin: {
|
||||||
auth: {
|
auth: {
|
||||||
homeserver: "Homeserver",
|
base_url: "Homeserver URL",
|
||||||
welcome: "Welcome to Synapse-admin",
|
welcome: "Welcome to Synapse-admin",
|
||||||
|
username_error: "Please enter fully qualified user ID: '@user:domain'",
|
||||||
|
protocol_error: "URL has to start with 'http://' or 'https://'",
|
||||||
|
url_error: "Not a valid Matrix server URL",
|
||||||
},
|
},
|
||||||
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: {
|
||||||
|
tabs: {
|
||||||
|
basic: "Basic",
|
||||||
|
members: "Members",
|
||||||
|
detail: "Details",
|
||||||
|
permission: "Permissions",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
resources: {
|
resources: {
|
||||||
users: {
|
users: {
|
||||||
|
@ -18,12 +29,13 @@ export default {
|
||||||
name: "User |||| Users",
|
name: "User |||| Users",
|
||||||
email: "Email",
|
email: "Email",
|
||||||
msisdn: "Phone",
|
msisdn: "Phone",
|
||||||
|
threepid: "Email / Phone",
|
||||||
fields: {
|
fields: {
|
||||||
avatar: "Avatar",
|
avatar: "Avatar",
|
||||||
id: "User-ID",
|
id: "User-ID",
|
||||||
name: "Name",
|
name: "Name",
|
||||||
is_guest: "Guest",
|
is_guest: "Guest",
|
||||||
admin: "Admin",
|
admin: "Server Administrator",
|
||||||
deactivated: "Deactivated",
|
deactivated: "Deactivated",
|
||||||
guests: "Show guests",
|
guests: "Show guests",
|
||||||
show_deactivated: "Show deactivated users",
|
show_deactivated: "Show deactivated users",
|
||||||
|
@ -31,12 +43,24 @@ export default {
|
||||||
displayname: "Displayname",
|
displayname: "Displayname",
|
||||||
password: "Password",
|
password: "Password",
|
||||||
avatar_url: "Avatar URL",
|
avatar_url: "Avatar URL",
|
||||||
|
avatar_src: "Avatar",
|
||||||
medium: "Medium",
|
medium: "Medium",
|
||||||
threepids: "3PIDs",
|
threepids: "3PIDs",
|
||||||
address: "Address",
|
address: "Address",
|
||||||
|
creation_ts_ms: "Creation timestamp",
|
||||||
|
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",
|
||||||
|
erase: "Mark the user as GDPR-erased",
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
erase: "Erase user data",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
|
@ -46,6 +70,36 @@ export default {
|
||||||
name: "Name",
|
name: "Name",
|
||||||
canonical_alias: "Alias",
|
canonical_alias: "Alias",
|
||||||
joined_members: "Members",
|
joined_members: "Members",
|
||||||
|
joined_local_members: "local members",
|
||||||
|
state_events: "State events",
|
||||||
|
version: "Version",
|
||||||
|
is_encrypted: "Encrypted",
|
||||||
|
encryption: "Encryption",
|
||||||
|
federatable: "Federatable",
|
||||||
|
public: "Public",
|
||||||
|
creator: "Creator",
|
||||||
|
join_rules: "Join rules",
|
||||||
|
guest_access: "Guest access",
|
||||||
|
history_visibility: "History visibility",
|
||||||
|
},
|
||||||
|
enums: {
|
||||||
|
join_rules: {
|
||||||
|
public: "Public",
|
||||||
|
knock: "Knock",
|
||||||
|
invite: "Invite",
|
||||||
|
private: "Private",
|
||||||
|
},
|
||||||
|
guest_access: {
|
||||||
|
can_join: "Guests can join",
|
||||||
|
forbidden: "Guests can not join",
|
||||||
|
},
|
||||||
|
history_visibility: {
|
||||||
|
invited: "Since invited",
|
||||||
|
joined: "Since joined",
|
||||||
|
shared: "Since shared",
|
||||||
|
world_readable: "Anyone",
|
||||||
|
},
|
||||||
|
unencrypted: "Unencrypted",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
connections: {
|
connections: {
|
||||||
|
@ -56,5 +110,32 @@ 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: {
|
||||||
|
name: "Server Notices",
|
||||||
|
send: "Send server notices",
|
||||||
|
fields: {
|
||||||
|
body: "Message",
|
||||||
|
},
|
||||||
|
action: {
|
||||||
|
send: "Send note",
|
||||||
|
send_success: "Server notice successfully sent.",
|
||||||
|
send_failure: "An error has occurred.",
|
||||||
|
},
|
||||||
|
helper: {
|
||||||
|
send:
|
||||||
|
'Sends a server notice to the selected users. The feature "Server Notices" has to be activated at the server.',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
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();
|
||||||
|
|
|
@ -1,23 +1,8 @@
|
||||||
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: ({ base_url, username, password }) => {
|
||||||
console.log("login ");
|
console.log("login ");
|
||||||
const options = {
|
const options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -28,17 +13,16 @@ const authProvider = {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const url = window.decodeURIComponent(homeserver);
|
// use the base_url from login instead of the well_known entry from the
|
||||||
const trimmed_url = url.trim().replace(/\s/g, "");
|
// server, since the admin might want to access the admin API via some
|
||||||
const login_api_url =
|
// private address
|
||||||
ensureHttpsForUrl(trimmed_url) + "/_matrix/client/r0/login";
|
localStorage.setItem("base_url", base_url);
|
||||||
|
|
||||||
|
const decoded_base_url = window.decodeURIComponent(base_url);
|
||||||
|
const login_api_url = decoded_base_url + "/_matrix/client/r0/login";
|
||||||
|
|
||||||
return fetchUtils.fetchJson(login_api_url, options).then(({ json }) => {
|
return fetchUtils.fetchJson(login_api_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);
|
||||||
|
|
|
@ -14,22 +14,42 @@ const jsonClient = (url, options = {}) => {
|
||||||
return fetchUtils.fetchJson(url, options);
|
return fetchUtils.fetchJson(url, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mxcUrlToHttp = mxcUrl => {
|
||||||
|
const homeserver = localStorage.getItem("base_url");
|
||||||
|
const re = /^mxc:\/\/([^/]+)\/(\w+)/;
|
||||||
|
var ret = re.exec(mxcUrl);
|
||||||
|
console.log("mxcClient " + ret);
|
||||||
|
if (ret == null) return null;
|
||||||
|
const serverName = ret[1];
|
||||||
|
const mediaId = ret[2];
|
||||||
|
return `${homeserver}/_matrix/media/r0/thumbnail/${serverName}/${mediaId}?width=24&height=24&method=scale`;
|
||||||
|
};
|
||||||
|
|
||||||
const resourceMap = {
|
const resourceMap = {
|
||||||
users: {
|
users: {
|
||||||
path: "/_synapse/admin/v2/users",
|
path: "/_synapse/admin/v2/users",
|
||||||
map: u => ({
|
map: u => ({
|
||||||
...u,
|
...u,
|
||||||
id: u.name,
|
id: u.name,
|
||||||
|
avatar_src: mxcUrlToHttp(u.avatar_url),
|
||||||
is_guest: !!u.is_guest,
|
is_guest: !!u.is_guest,
|
||||||
admin: !!u.admin,
|
admin: !!u.admin,
|
||||||
deactivated: !!u.deactivated,
|
deactivated: !!u.deactivated,
|
||||||
|
// need timestamp in milliseconds
|
||||||
|
creation_ts_ms: u.creation_ts * 1000,
|
||||||
}),
|
}),
|
||||||
data: "users",
|
data: "users",
|
||||||
total: (json, from, perPage) => {
|
total: json => json.total,
|
||||||
return json.next_token
|
create: data => ({
|
||||||
? parseInt(json.next_token, 10) + perPage
|
endpoint: `/_synapse/admin/v2/users/${data.id}`,
|
||||||
: from + json.users.length;
|
body: data,
|
||||||
},
|
method: "PUT",
|
||||||
|
}),
|
||||||
|
delete: params => ({
|
||||||
|
endpoint: `/_synapse/admin/v1/deactivate/${params.id}`,
|
||||||
|
body: { erase: true },
|
||||||
|
method: "POST",
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
path: "/_synapse/admin/v1/rooms",
|
path: "/_synapse/admin/v1/rooms",
|
||||||
|
@ -38,12 +58,28 @@ const resourceMap = {
|
||||||
id: r.room_id,
|
id: r.room_id,
|
||||||
alias: r.canonical_alias,
|
alias: r.canonical_alias,
|
||||||
members: r.joined_members,
|
members: r.joined_members,
|
||||||
|
is_encrypted: !!r.encryption,
|
||||||
|
federatable: !!r.federatable,
|
||||||
|
public: !!r.public,
|
||||||
}),
|
}),
|
||||||
data: "rooms",
|
data: "rooms",
|
||||||
total: json => {
|
total: json => {
|
||||||
return json.total_rooms;
|
return json.total_rooms;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
devices: {
|
||||||
|
map: d => ({
|
||||||
|
...d,
|
||||||
|
id: d.device_id,
|
||||||
|
}),
|
||||||
|
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: {
|
||||||
path: "/_synapse/admin/v1/whois",
|
path: "/_synapse/admin/v1/whois",
|
||||||
map: c => ({
|
map: c => ({
|
||||||
|
@ -52,6 +88,20 @@ const resourceMap = {
|
||||||
}),
|
}),
|
||||||
data: "connections",
|
data: "connections",
|
||||||
},
|
},
|
||||||
|
servernotices: {
|
||||||
|
map: n => ({ id: n.event_id }),
|
||||||
|
create: data => ({
|
||||||
|
endpoint: "/_synapse/admin/v1/send_server_notice",
|
||||||
|
body: {
|
||||||
|
user_id: data.id,
|
||||||
|
content: {
|
||||||
|
msgtype: "m.text",
|
||||||
|
body: data.body,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
}),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function filterNullValues(key, value) {
|
function filterNullValues(key, value) {
|
||||||
|
@ -62,11 +112,20 @@ function filterNullValues(key, value) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSearchOrder(order) {
|
||||||
|
if (order === "DESC") {
|
||||||
|
return "b";
|
||||||
|
} else {
|
||||||
|
return "f";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const dataProvider = {
|
const dataProvider = {
|
||||||
getList: (resource, params) => {
|
getList: (resource, params) => {
|
||||||
console.log("getList " + resource);
|
console.log("getList " + resource);
|
||||||
const { user_id, guests, deactivated } = params.filter;
|
const { user_id, guests, deactivated } = params.filter;
|
||||||
const { page, perPage } = params.pagination;
|
const { page, perPage } = params.pagination;
|
||||||
|
const { field, order } = params.sort;
|
||||||
const from = (page - 1) * perPage;
|
const from = (page - 1) * perPage;
|
||||||
const query = {
|
const query = {
|
||||||
from: from,
|
from: from,
|
||||||
|
@ -74,14 +133,16 @@ const dataProvider = {
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
guests: guests,
|
guests: guests,
|
||||||
deactivated: deactivated,
|
deactivated: deactivated,
|
||||||
|
order_by: field,
|
||||||
|
dir: getSearchOrder(order),
|
||||||
};
|
};
|
||||||
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 homeserver_url = homeserver + res.path;
|
const endpoint_url = homeserver + res.path;
|
||||||
const url = `${homeserver_url}?${stringify(query)}`;
|
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),
|
||||||
|
@ -96,8 +157,8 @@ const dataProvider = {
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = homeserver + res.path;
|
const endpoint_url = homeserver + res.path;
|
||||||
return jsonClient(`${homeserver_url}/${params.id}`).then(({ json }) => ({
|
return jsonClient(`${endpoint_url}/${params.id}`).then(({ json }) => ({
|
||||||
data: res.map(json),
|
data: res.map(json),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
@ -109,39 +170,27 @@ const dataProvider = {
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = 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)),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
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 homeserver_url = homeserver + res.path;
|
const ref = res["reference"](params.id);
|
||||||
const url = `${homeserver_url}?${stringify(query)}`;
|
const endpoint_url = homeserver + ref.endpoint;
|
||||||
|
|
||||||
return jsonClient(url).then(({ headers, json }) => ({
|
return jsonClient(endpoint_url).then(({ headers, json }) => ({
|
||||||
data: json,
|
data: json[res.data].map(res.map),
|
||||||
total: parseInt(headers.get("content-range").split("/").pop(), 10),
|
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -152,8 +201,8 @@ const dataProvider = {
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = homeserver + res.path;
|
const endpoint_url = homeserver + res.path;
|
||||||
return jsonClient(`${homeserver_url}/${params.data.id}`, {
|
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 }) => ({
|
||||||
|
@ -168,9 +217,9 @@ const dataProvider = {
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = 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),
|
||||||
})
|
})
|
||||||
|
@ -185,16 +234,41 @@ const dataProvider = {
|
||||||
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
if (!("create" in res)) return Promise.reject();
|
||||||
|
|
||||||
const homeserver_url = homeserver + res.path;
|
const create = res["create"](params.data);
|
||||||
return jsonClient(`${homeserver_url}/${params.data.id}`, {
|
const endpoint_url = homeserver + create.endpoint;
|
||||||
method: "PUT",
|
return jsonClient(endpoint_url, {
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
method: create.method,
|
||||||
|
body: JSON.stringify(create.body, filterNullValues),
|
||||||
}).then(({ json }) => ({
|
}).then(({ json }) => ({
|
||||||
data: res.map(json),
|
data: res.map(json),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
createMany: (resource, params) => {
|
||||||
|
console.log("createMany " + resource);
|
||||||
|
const homeserver = localStorage.getItem("base_url");
|
||||||
|
if (!homeserver || !(resource in resourceMap)) return Promise.reject();
|
||||||
|
|
||||||
|
const res = resourceMap[resource];
|
||||||
|
if (!("create" in res)) return Promise.reject();
|
||||||
|
|
||||||
|
return Promise.all(
|
||||||
|
params.ids.map(id => {
|
||||||
|
params.data.id = id;
|
||||||
|
const cre = res["create"](params.data);
|
||||||
|
const endpoint_url = homeserver + cre.endpoint;
|
||||||
|
return jsonClient(endpoint_url, {
|
||||||
|
method: cre.method,
|
||||||
|
body: JSON.stringify(cre.body, filterNullValues),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
delete: (resource, params) => {
|
delete: (resource, params) => {
|
||||||
console.log("delete " + resource);
|
console.log("delete " + resource);
|
||||||
const homeserver = localStorage.getItem("base_url");
|
const homeserver = localStorage.getItem("base_url");
|
||||||
|
@ -202,12 +276,24 @@ const dataProvider = {
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = homeserver + res.path;
|
if ("delete" in res) {
|
||||||
return jsonClient(`${homeserver_url}/${params.id}`, {
|
const del = res["delete"](params);
|
||||||
method: "DELETE",
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
|
return jsonClient(endpoint_url, {
|
||||||
|
method: "method" in del ? del.method : "DELETE",
|
||||||
|
body: "body" in del ? JSON.stringify(del.body) : null,
|
||||||
}).then(({ json }) => ({
|
}).then(({ json }) => ({
|
||||||
data: 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) => {
|
||||||
|
@ -217,17 +303,32 @@ const dataProvider = {
|
||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = homeserver + res.path;
|
if ("delete" in res) {
|
||||||
|
return Promise.all(
|
||||||
|
params.ids.map(id => {
|
||||||
|
const del = res["delete"]({ ...params, id: id });
|
||||||
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
|
return jsonClient(endpoint_url, {
|
||||||
|
method: "method" in del ? del.method : "DELETE",
|
||||||
|
body: "body" in del ? JSON.stringify(del.body) : null,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
params.ids.map(id =>
|
params.ids.map(id =>
|
||||||
jsonClient(`${homeserver_url}/${id}`, {
|
jsonClient(`${endpoint_url}/${id}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
}).then(responses => ({
|
})
|
||||||
data: responses.map(({ json }) => json),
|
|
||||||
}))
|
|
||||||
)
|
)
|
||||||
);
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
78
src/synapse/dataProvider.test.js
Normal file
78
src/synapse/dataProvider.test.js
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue