Compare commits
32 Commits
0.4.2
...
AMP/2020.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
931fafc21d | ||
|
|
c604b47adc | ||
|
|
fb8cff3e3e | ||
|
|
8db881a64d | ||
|
|
c09e59d47a | ||
|
|
725e24d944 | ||
|
|
8bdf76f27e | ||
|
|
7c9a87bc86 | ||
|
|
1f56bac356 | ||
|
|
dd00a76603 | ||
|
|
2915fd3e5b | ||
|
|
a4662c2557 | ||
|
|
f6ca169fbc | ||
|
|
07862591fd | ||
|
|
ab649fbf70 | ||
|
|
880223e5de | ||
|
|
76fdc80e3e | ||
|
|
375649756f | ||
|
|
662735a91f | ||
|
|
0823976edd | ||
|
|
d3cd2e9e33 | ||
|
|
24abcd4e4a | ||
|
|
c1c32e3268 | ||
|
|
ca15435625 | ||
|
|
e9c3901b68 | ||
|
|
7aec6f9369 | ||
|
|
d2a3f07a59 | ||
|
|
bf7867f106 | ||
|
|
f0e32abc4f | ||
|
|
61b1580735 | ||
|
|
0f7e4c1909 | ||
|
|
c9bce409d2 |
@@ -1,5 +1,5 @@
|
||||
# Builder
|
||||
FROM node:10-alpine as builder
|
||||
FROM node:current as builder
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
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.18.0 for all functions to work as expected!
|
||||
|
||||
## Step-By-Step install:
|
||||
|
||||
@@ -29,3 +29,8 @@ Steps for 2):
|
||||
## 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",
|
||||
"version": "0.2.1",
|
||||
"version": "AMP/2020.08",
|
||||
"description": "Admin GUI for the Matrix.org server Synapse",
|
||||
"author": "Awesome Technologies Innovationslabor GmbH",
|
||||
"license": "Apache-2.0",
|
||||
@@ -18,10 +18,15 @@
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.10.1",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"jest-fetch-mock": "^3.0.3",
|
||||
"prettier": "^2.0.0"
|
||||
},
|
||||
"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",
|
||||
"qrcode.react": "^1.0.0",
|
||||
"ra-language-german": "^2.1.2",
|
||||
"react": "^16.13.1",
|
||||
"react-admin": "^3.7.0",
|
||||
|
||||
BIN
public/fonts/DejaVu/DejaVuSans-Bold.ttf
Normal file
BIN
public/fonts/DejaVu/DejaVuSans-Bold.ttf
Normal file
Binary file not shown.
BIN
public/fonts/DejaVu/DejaVuSans-Mono.ttf
Normal file
BIN
public/fonts/DejaVu/DejaVuSans-Mono.ttf
Normal file
Binary file not shown.
BIN
public/fonts/DejaVu/DejaVuSans-Oblique.ttf
Normal file
BIN
public/fonts/DejaVu/DejaVuSans-Oblique.ttf
Normal file
Binary file not shown.
BIN
public/fonts/DejaVu/DejaVuSans.ttf
Normal file
BIN
public/fonts/DejaVu/DejaVuSans.ttf
Normal file
Binary file not shown.
BIN
public/images/logo.png
Normal file
BIN
public/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 358 KiB |
@@ -9,6 +9,32 @@
|
||||
name="description"
|
||||
content="Synapse-Admin"
|
||||
/>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: "DejaVu Sans";
|
||||
src: url("%PUBLIC_URL%/fonts/DejaVu/DejaVuSans.ttf") format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DejaVu Sans";
|
||||
font-weight: bold;
|
||||
src: url("%PUBLIC_URL%/fonts/DejaVu/DejaVuSans-Bold.ttf") format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DejaVu Sans";
|
||||
font-style: italic;
|
||||
src: url("%PUBLIC_URL%/fonts/DejaVu/DejaVuSans-Oblique.ttf") format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DejaVu Sans";
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
src: url("%PUBLIC_URL%/fonts/DejaVu/DejaVuSans-Oblique.ttf") format("truetype");
|
||||
}
|
||||
@font-face {
|
||||
font-family: "DejaVu Sans Mono";
|
||||
src: url("%PUBLIC_URL%/fonts/DejaVu/DejaVuSans-Mono.ttf") format("truetype");
|
||||
}
|
||||
</style>
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
@@ -46,4 +72,4 @@
|
||||
</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
16
src/App.js
16
src/App.js
@@ -4,12 +4,14 @@ import polyglotI18nProvider from "ra-i18n-polyglot";
|
||||
import authProvider from "./synapse/authProvider";
|
||||
import dataProvider from "./synapse/dataProvider";
|
||||
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 UserIcon from "@material-ui/icons/Group";
|
||||
import { ViewListIcon as RoomIcon } from "@material-ui/icons/ViewList";
|
||||
import germanMessages from "./i18n/de";
|
||||
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?
|
||||
const messages = {
|
||||
@@ -27,6 +29,9 @@ const App = () => (
|
||||
authProvider={authProvider}
|
||||
dataProvider={dataProvider}
|
||||
i18nProvider={i18nProvider}
|
||||
customRoutes={[
|
||||
<Route key="showpdf" path="/showpdf" component={ShowUserPdf} />,
|
||||
]}
|
||||
>
|
||||
<Resource
|
||||
name="users"
|
||||
@@ -35,9 +40,16 @@ const App = () => (
|
||||
edit={UserEdit}
|
||||
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="devices" />
|
||||
<Resource name="room_members" />
|
||||
<Resource name="servernotices" />
|
||||
</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;
|
||||
210
src/components/ShowUserPdf.js
Normal file
210
src/components/ShowUserPdf.js
Normal file
@@ -0,0 +1,210 @@
|
||||
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",
|
||||
fontFamily: "DejaVu Sans, Sans-Serif",
|
||||
fontSize: 15,
|
||||
},
|
||||
header: {
|
||||
height: 144,
|
||||
width: 534,
|
||||
marginLeft: 32,
|
||||
marginTop: 15,
|
||||
},
|
||||
name: {
|
||||
width: 240,
|
||||
fontSize: 35,
|
||||
float: "left",
|
||||
marginTop: 100,
|
||||
},
|
||||
logo: {
|
||||
width: 90,
|
||||
marginTop: 50,
|
||||
marginRight: 70,
|
||||
float: "right",
|
||||
},
|
||||
body: {
|
||||
clear: "both",
|
||||
},
|
||||
table_cell: {
|
||||
verticalAlign: "top",
|
||||
},
|
||||
code_note: {
|
||||
marginLeft: 32,
|
||||
marginTop: 86,
|
||||
},
|
||||
qr: {
|
||||
marginTop: 15,
|
||||
marginLeft: 32,
|
||||
},
|
||||
credentials_note: {
|
||||
marginTop: 86,
|
||||
marginLeft: 10,
|
||||
},
|
||||
credentials_text: {
|
||||
marginLeft: 10,
|
||||
fontSize: 12,
|
||||
},
|
||||
credentials: {
|
||||
fontFamily: "DejaVu Sans Mono, monospace",
|
||||
},
|
||||
note: {
|
||||
fontSize: 18,
|
||||
marginTop: 100,
|
||||
marginLeft: 32,
|
||||
marginRight: 32,
|
||||
},
|
||||
}));
|
||||
|
||||
const classes = useStyles();
|
||||
|
||||
var resume;
|
||||
|
||||
const exportPDF = () => {
|
||||
resume.save();
|
||||
};
|
||||
|
||||
var qrCode = "";
|
||||
var displayname = "";
|
||||
var id = "";
|
||||
var password = "";
|
||||
var username = "";
|
||||
var serverUrl = "";
|
||||
|
||||
if (
|
||||
props.location.state &&
|
||||
props.location.state.id &&
|
||||
props.location.state.password
|
||||
) {
|
||||
id = props.location.state.id;
|
||||
password = props.location.state.password;
|
||||
|
||||
username = id.substring(1, id.indexOf(":"));
|
||||
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.header}>
|
||||
<div className={classes.name}>{displayname}</div>
|
||||
<img className={classes.logo} alt="Logo" src="images/logo.png" />
|
||||
</div>
|
||||
<div className={classes.body}>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="200px">
|
||||
<div className={classes.code_note}>
|
||||
Ihr persönlicher Anmeldecode:
|
||||
</div>
|
||||
</td>
|
||||
<td className={classes.table_cell}>
|
||||
<div className={classes.credentials_note}>
|
||||
Ihre persönlichen Zugangsdaten:
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div className={classes.qr}>{qrCode}</div>
|
||||
</td>
|
||||
<td className={classes.table_cell}>
|
||||
<div className={classes.credentials_text}>
|
||||
<br />
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Heimserver:</td>
|
||||
<td>
|
||||
<span className={classes.credentials}>
|
||||
{serverUrl}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Benutzername:</td>
|
||||
<td>
|
||||
<span className={classes.credentials}>
|
||||
{username}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Passwort:</td>
|
||||
<td>
|
||||
<span className={classes.credentials}>
|
||||
{password}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div className={classes.note}>
|
||||
Hier können Sie Ihre selbst gewählte
|
||||
Schlüsselsicherungs-Passphrase notieren:
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<hr />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PDFExport>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ShowUserPdf;
|
||||
@@ -1,16 +1,25 @@
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
AutocompleteArrayInput,
|
||||
BooleanInput,
|
||||
BooleanField,
|
||||
Create,
|
||||
Datagrid,
|
||||
Filter,
|
||||
FormTab,
|
||||
List,
|
||||
Pagination,
|
||||
ReferenceArrayInput,
|
||||
ReferenceField,
|
||||
ReferenceManyField,
|
||||
SelectField,
|
||||
Show,
|
||||
Tab,
|
||||
TabbedForm,
|
||||
TabbedShowLayout,
|
||||
TextField,
|
||||
TextInput,
|
||||
useTranslate,
|
||||
} from "react-admin";
|
||||
import get from "lodash/get";
|
||||
@@ -18,6 +27,7 @@ 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 UserIcon from "@material-ui/icons/Group";
|
||||
import ViewListIcon from "@material-ui/icons/ViewList";
|
||||
import VisibilityIcon from "@material-ui/icons/Visibility";
|
||||
|
||||
@@ -51,16 +61,117 @@ const EncryptionField = ({ source, record = {}, emptyText }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const RoomTitle = ({ record }) => {
|
||||
const translate = useTranslate();
|
||||
var name = "";
|
||||
if (record) {
|
||||
name = record.name !== "" ? record.name : record.id;
|
||||
const validateDisplayName = fieldval =>
|
||||
fieldval === undefined
|
||||
? "synapseadmin.rooms.room_name_required"
|
||||
: fieldval.length === 0
|
||||
? "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 (
|
||||
<span>
|
||||
{translate("resources.rooms.name", 1)} {name}
|
||||
{translate("resources.rooms.name", 1)} {record ? `"${record.name}"` : ""}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -92,6 +203,34 @@ export const RoomShow = props => {
|
||||
/>
|
||||
</Tab>
|
||||
|
||||
<Tab label="synapseadmin.rooms.tabs.members" icon={<UserIcon />}>
|
||||
<ReferenceManyField
|
||||
reference="room_members"
|
||||
target="room_id"
|
||||
addLabel={false}
|
||||
>
|
||||
<Datagrid
|
||||
style={{ width: "100%" }}
|
||||
rowClick={(id, basePath, record) => "/users/" + id}
|
||||
>
|
||||
<TextField
|
||||
source="id"
|
||||
sortable={false}
|
||||
label="resources.users.fields.id"
|
||||
/>
|
||||
<ReferenceField
|
||||
label="resources.users.fields.displayname"
|
||||
source="id"
|
||||
reference="users"
|
||||
sortable={false}
|
||||
link=""
|
||||
>
|
||||
<TextField source="displayname" sortable={false} />
|
||||
</ReferenceField>
|
||||
</Datagrid>
|
||||
</ReferenceManyField>
|
||||
</Tab>
|
||||
|
||||
<Tab
|
||||
label="synapseadmin.rooms.tabs.permission"
|
||||
icon={<VisibilityIcon />}
|
||||
|
||||
@@ -23,8 +23,10 @@ import {
|
||||
PasswordInput,
|
||||
TextField,
|
||||
TextInput,
|
||||
SearchInput,
|
||||
ReferenceField,
|
||||
ReferenceManyField,
|
||||
SelectField,
|
||||
SelectInput,
|
||||
BulkDeleteButton,
|
||||
DeleteButton,
|
||||
@@ -37,6 +39,7 @@ import {
|
||||
TopToolbar,
|
||||
sanitizeListRestProps,
|
||||
} from "react-admin";
|
||||
import SaveQrButton from "./SaveQrButton";
|
||||
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||
import { DeviceRemoveButton } from "./devices";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
@@ -98,6 +101,7 @@ const UserPagination = props => (
|
||||
|
||||
const UserFilter = props => (
|
||||
<Filter {...props}>
|
||||
<SearchInput source="user_id" alwaysOn />
|
||||
<BooleanInput source="guests" alwaysOn />
|
||||
<BooleanInput
|
||||
label="resources.users.fields.show_deactivated"
|
||||
@@ -143,15 +147,92 @@ export const UserList = props => {
|
||||
className={classes.small}
|
||||
/>
|
||||
<TextField source="id" sortable={false} />
|
||||
<TextField source="displayname" sortable={false} />
|
||||
<TextField source="displayname" />
|
||||
<BooleanField source="is_guest" sortable={false} />
|
||||
<BooleanField source="admin" sortable={false} />
|
||||
<SelectField
|
||||
source="user_type"
|
||||
choices={[
|
||||
{ id: null, name: "resources.users.type.default" },
|
||||
{ id: "free", name: "resources.users.type.free" },
|
||||
{ id: "limited", name: "resources.users.type.limited" },
|
||||
]}
|
||||
/>
|
||||
<BooleanField source="deactivated" sortable={false} />
|
||||
</Datagrid>
|
||||
</List>
|
||||
);
|
||||
};
|
||||
|
||||
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
|
||||
const validateUser = regex(
|
||||
/^@[a-z0-9._=\-/]+:.*/,
|
||||
@@ -162,7 +243,17 @@ const UserEditToolbar = props => {
|
||||
const translate = useTranslate();
|
||||
return (
|
||||
<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
|
||||
label="resources.users.action.erase"
|
||||
title={translate("resources.users.helper.erase")}
|
||||
@@ -173,12 +264,20 @@ const UserEditToolbar = props => {
|
||||
};
|
||||
|
||||
export const UserCreate = props => (
|
||||
<Create {...props}>
|
||||
<SimpleForm>
|
||||
<Create record={generateRandomUser()} {...props}>
|
||||
<SimpleForm toolbar={<UserCreateToolbar />}>
|
||||
<TextInput source="id" autoComplete="off" validate={validateUser} />
|
||||
<TextInput source="displayname" />
|
||||
<PasswordInput source="password" autoComplete="new-password" />
|
||||
<BooleanInput source="admin" />
|
||||
<SelectInput
|
||||
source="user_type"
|
||||
choices={[
|
||||
{ id: null, name: "resources.users.type.default" },
|
||||
{ id: "free", name: "resources.users.type.free" },
|
||||
{ id: "limited", name: "resources.users.type.limited" },
|
||||
]}
|
||||
/>
|
||||
<ArrayInput source="threepids">
|
||||
<SimpleFormIterator>
|
||||
<SelectInput
|
||||
@@ -206,13 +305,17 @@ const UserTitle = ({ record }) => {
|
||||
</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={translate("resources.users.name", { smart_count: 1 })}
|
||||
icon={<PersonPinIcon />}
|
||||
>
|
||||
<AvatarField
|
||||
source="avatar_src"
|
||||
sortable={false}
|
||||
@@ -221,6 +324,15 @@ export const UserEdit = props => {
|
||||
<TextInput source="id" disabled />
|
||||
<TextInput source="displayname" />
|
||||
<PasswordInput source="password" autoComplete="new-password" />
|
||||
<SelectInput
|
||||
source="user_type"
|
||||
choices={[
|
||||
{ id: null, name: "resources.users.type.default" },
|
||||
{ id: "free", name: "resources.users.type.free" },
|
||||
{ id: "limited", name: "resources.users.type.limited" },
|
||||
]}
|
||||
emptyText="resources.users.type.default"
|
||||
/>
|
||||
<BooleanInput source="admin" />
|
||||
<BooleanInput
|
||||
source="deactivated"
|
||||
|
||||
@@ -11,12 +11,25 @@ export default {
|
||||
protocol_error: "Die URL muss mit 'http://' oder 'https://' beginnen",
|
||||
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: {
|
||||
invalid_user_id:
|
||||
"Muss eine vollständige Matrix Benutzer-ID sein, z.B. @benutzer_id:homeserver",
|
||||
},
|
||||
rooms: {
|
||||
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: {
|
||||
basic: "Allgemein",
|
||||
members: "Mitglieder",
|
||||
@@ -51,12 +64,18 @@ export default {
|
||||
address: "Adresse",
|
||||
creation_ts_ms: "Zeitpunkt der Erstellung",
|
||||
consent_version: "Zugestimmte Geschäftsbedingungen",
|
||||
user_type: "Kontotyp",
|
||||
// Devices:
|
||||
device_id: "Geräte-ID",
|
||||
display_name: "Gerätename",
|
||||
last_seen_ts: "Zeitstempel",
|
||||
last_seen_ip: "IP-Adresse",
|
||||
},
|
||||
type: {
|
||||
default: "Standard",
|
||||
free: "Basic",
|
||||
limited: "Eingeschränkt",
|
||||
},
|
||||
helper: {
|
||||
deactivate: "Deaktivierte Nutzer können nicht wieder aktiviert werden.",
|
||||
erase: "DSGVO konformes Löschen der Benutzerdaten",
|
||||
@@ -72,6 +91,8 @@ export default {
|
||||
name: "Name",
|
||||
canonical_alias: "Alias",
|
||||
joined_members: "Mitglieder",
|
||||
invite_members: "Mitglieder einladen",
|
||||
invitees: "Einladungen",
|
||||
joined_local_members: "Lokale Mitglieder",
|
||||
state_events: "Ereignisse",
|
||||
version: "Version",
|
||||
|
||||
@@ -6,15 +6,30 @@ export default {
|
||||
auth: {
|
||||
base_url: "Homeserver URL",
|
||||
welcome: "Welcome to Synapse-admin",
|
||||
server_version: "Synapse version",
|
||||
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",
|
||||
},
|
||||
action: {
|
||||
save_and_show: "Create QR code",
|
||||
save_only: "Save",
|
||||
download_pdf: "Download PDF",
|
||||
},
|
||||
users: {
|
||||
invalid_user_id:
|
||||
"Must be a fully qualified Matrix user-id, e.g. @user_id:homeserver",
|
||||
},
|
||||
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: {
|
||||
basic: "Basic",
|
||||
members: "Members",
|
||||
@@ -55,6 +70,11 @@ export default {
|
||||
last_seen_ts: "Timestamp",
|
||||
last_seen_ip: "IP address",
|
||||
},
|
||||
type: {
|
||||
default: "Standard",
|
||||
free: "Basic",
|
||||
limited: "Limited",
|
||||
},
|
||||
helper: {
|
||||
deactivate: "Deactivated users cannot be reactivated",
|
||||
erase: "Mark the user as GDPR-erased",
|
||||
@@ -70,6 +90,8 @@ export default {
|
||||
name: "Name",
|
||||
canonical_alias: "Alias",
|
||||
joined_members: "Members",
|
||||
invite_members: "Invite Members",
|
||||
invitees: "Invitations",
|
||||
joined_local_members: "local members",
|
||||
state_events: "State events",
|
||||
version: "Version",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { configure } from "enzyme";
|
||||
import Adapter from "enzyme-adapter-react-16";
|
||||
import fetchMock from "jest-fetch-mock";
|
||||
|
||||
configure({ adapter: new Adapter() });
|
||||
fetchMock.enableMocks();
|
||||
|
||||
@@ -35,6 +35,7 @@ const resourceMap = {
|
||||
is_guest: !!u.is_guest,
|
||||
admin: !!u.admin,
|
||||
deactivated: !!u.deactivated,
|
||||
displayname: u.display_name || u.displayname,
|
||||
// need timestamp in milliseconds
|
||||
creation_ts_ms: u.creation_ts * 1000,
|
||||
}),
|
||||
@@ -63,9 +64,31 @@ const resourceMap = {
|
||||
public: !!r.public,
|
||||
}),
|
||||
data: "rooms",
|
||||
total: json => {
|
||||
return json.total_rooms;
|
||||
},
|
||||
total: json => 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",
|
||||
},
|
||||
},
|
||||
]
|
||||
: undefined,
|
||||
},
|
||||
method: "POST",
|
||||
}),
|
||||
},
|
||||
devices: {
|
||||
map: d => ({
|
||||
@@ -88,6 +111,15 @@ const resourceMap = {
|
||||
}),
|
||||
data: "connections",
|
||||
},
|
||||
room_members: {
|
||||
map: m => ({
|
||||
id: m,
|
||||
}),
|
||||
reference: id => ({
|
||||
endpoint: `/_synapse/admin/v1/rooms/${id}/members`,
|
||||
}),
|
||||
data: "members",
|
||||
},
|
||||
servernotices: {
|
||||
map: n => ({ id: n.event_id }),
|
||||
create: data => ({
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user