Merge branch 'master' into increase_export
This commit is contained in:
commit
5f580fabce
@ -6,5 +6,6 @@
|
|||||||
"singleQuote": false,
|
"singleQuote": false,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false
|
"jsxBracketSameLine": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
}
|
}
|
||||||
|
17
package.json
17
package.json
@ -4,28 +4,29 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@testing-library/jest-dom": "^5.1.1",
|
"@testing-library/jest-dom": "^5.1.1",
|
||||||
"@testing-library/react": "^9.4.0",
|
"@testing-library/react": "^10.0.2",
|
||||||
"@testing-library/user-event": "^8.1.0",
|
"@testing-library/user-event": "^10.0.1",
|
||||||
"enzyme": "^3.11.0",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.2",
|
"enzyme-adapter-react-16": "^1.15.2",
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"eslint-config-prettier": "^6.10.0",
|
"eslint-config-prettier": "^6.10.1",
|
||||||
"eslint-plugin-prettier": "^3.1.2",
|
"eslint-plugin-prettier": "^3.1.2",
|
||||||
"prettier": "^1.19.1"
|
"prettier": "^2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"ra-language-german": "^2.1.2",
|
"ra-language-german": "^2.1.2",
|
||||||
"react": "^16.12.0",
|
"react": "^16.13.1",
|
||||||
"react-admin": "^3.1.3",
|
"react-admin": "^3.4.0",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.13.1",
|
||||||
"react-scripts": "^3.3.0"
|
"react-scripts": "^3.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
@ -37,6 +37,7 @@ const App = () => (
|
|||||||
/>
|
/>
|
||||||
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
<Resource name="rooms" list={RoomList} icon={RoomIcon} />
|
||||||
<Resource name="connections" />
|
<Resource name="connections" />
|
||||||
|
<Resource name="servernotices" />
|
||||||
</Admin>
|
</Admin>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } 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,
|
||||||
@ -34,7 +38,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
minWidth: 300,
|
minWidth: "30em",
|
||||||
marginTop: "6em",
|
marginTop: "6em",
|
||||||
},
|
},
|
||||||
avatar: {
|
avatar: {
|
||||||
@ -70,7 +74,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 +92,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 +127,75 @@ 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 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}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
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 +224,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>
|
||||||
|
);
|
||||||
|
};
|
@ -1,4 +1,4 @@
|
|||||||
import React, { cloneElement } from "react";
|
import React, { cloneElement, Fragment } from "react";
|
||||||
import PersonPinIcon from "@material-ui/icons/PersonPin";
|
import PersonPinIcon from "@material-ui/icons/PersonPin";
|
||||||
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
import SettingsInputComponentIcon from "@material-ui/icons/SettingsInputComponent";
|
||||||
import {
|
import {
|
||||||
@ -10,6 +10,7 @@ import {
|
|||||||
Edit,
|
Edit,
|
||||||
List,
|
List,
|
||||||
Filter,
|
Filter,
|
||||||
|
Toolbar,
|
||||||
SimpleForm,
|
SimpleForm,
|
||||||
SimpleFormIterator,
|
SimpleFormIterator,
|
||||||
TabbedForm,
|
TabbedForm,
|
||||||
@ -22,13 +23,18 @@ import {
|
|||||||
TextInput,
|
TextInput,
|
||||||
ReferenceField,
|
ReferenceField,
|
||||||
SelectInput,
|
SelectInput,
|
||||||
|
BulkDeleteButton,
|
||||||
|
DeleteButton,
|
||||||
|
SaveButton,
|
||||||
regex,
|
regex,
|
||||||
|
useTranslate,
|
||||||
Pagination,
|
Pagination,
|
||||||
CreateButton,
|
CreateButton,
|
||||||
ExportButton,
|
ExportButton,
|
||||||
TopToolbar,
|
TopToolbar,
|
||||||
sanitizeListRestProps,
|
sanitizeListRestProps,
|
||||||
} from "react-admin";
|
} from "react-admin";
|
||||||
|
import { ServerNoticeButton, ServerNoticeBulkButton } from "./ServerNotices";
|
||||||
|
|
||||||
const ListActions = ({
|
const ListActions = ({
|
||||||
currentSort,
|
currentSort,
|
||||||
@ -84,13 +90,27 @@ const UserFilter = props => (
|
|||||||
</Filter>
|
</Filter>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const UserBulkActionButtons = props => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
<ServerNoticeBulkButton {...props} />
|
||||||
|
<BulkDeleteButton
|
||||||
|
{...props}
|
||||||
|
label="resources.users.action.erase"
|
||||||
|
title={translate("resources.users.helper.erase")}
|
||||||
|
/>
|
||||||
|
</Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const UserList = props => (
|
export const UserList = props => (
|
||||||
<List
|
<List
|
||||||
{...props}
|
{...props}
|
||||||
filters={<UserFilter />}
|
filters={<UserFilter />}
|
||||||
filterDefaultValues={{ guests: true, deactivated: false }}
|
filterDefaultValues={{ guests: true, deactivated: false }}
|
||||||
bulkActionButtons={false}
|
|
||||||
actions={<ListActions maxResults={10000} />}
|
actions={<ListActions maxResults={10000} />}
|
||||||
|
bulkActionButtons={<UserBulkActionButtons />}
|
||||||
pagination={<UserPagination />}
|
pagination={<UserPagination />}
|
||||||
>
|
>
|
||||||
<Datagrid rowClick="edit">
|
<Datagrid rowClick="edit">
|
||||||
@ -125,6 +145,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>
|
||||||
@ -148,9 +182,18 @@ export const UserCreate = props => (
|
|||||||
</Create>
|
</Create>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const UserTitle = ({ record }) => {
|
||||||
|
const translate = useTranslate();
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{translate("resources.users.name")}{" "}
|
||||||
|
{record ? `"${record.displayname}"` : ""}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
export const UserEdit = props => (
|
export const UserEdit = props => (
|
||||||
<Edit {...props}>
|
<Edit {...props} title={<UserTitle />}>
|
||||||
<TabbedForm>
|
<TabbedForm toolbar={<UserEditToolbar />}>
|
||||||
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
|
<FormTab label="resources.users.name" icon={<PersonPinIcon />}>
|
||||||
<TextInput source="id" disabled />
|
<TextInput source="id" disabled />
|
||||||
<TextInput source="displayname" />
|
<TextInput source="displayname" />
|
||||||
|
@ -4,8 +4,11 @@ export default {
|
|||||||
...germanMessages,
|
...germanMessages,
|
||||||
synapseadmin: {
|
synapseadmin: {
|
||||||
auth: {
|
auth: {
|
||||||
homeserver: "Heimserver",
|
base_url: "Heimserver URL",
|
||||||
welcome: "Willkommen bei Synapse-admin",
|
welcome: "Willkommen bei Synapse-admin",
|
||||||
|
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:
|
||||||
@ -37,6 +40,10 @@ export default {
|
|||||||
},
|
},
|
||||||
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: {
|
||||||
@ -56,5 +63,40 @@ export default {
|
|||||||
user_agent: "User Agent",
|
user_agent: "User Agent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
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,8 +4,11 @@ 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:
|
||||||
@ -37,6 +40,10 @@ export default {
|
|||||||
},
|
},
|
||||||
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: {
|
||||||
@ -56,5 +63,21 @@ export default {
|
|||||||
user_agent: "User agent",
|
user_agent: "User agent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
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,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);
|
||||||
|
@ -30,6 +30,16 @@ const resourceMap = {
|
|||||||
? parseInt(json.next_token, 10) + perPage
|
? parseInt(json.next_token, 10) + perPage
|
||||||
: from + json.users.length;
|
: from + json.users.length;
|
||||||
},
|
},
|
||||||
|
create: data => ({
|
||||||
|
endpoint: `/_synapse/admin/v2/users/${data.id}`,
|
||||||
|
body: data,
|
||||||
|
method: "PUT",
|
||||||
|
}),
|
||||||
|
delete: id => ({
|
||||||
|
endpoint: `/_synapse/admin/v1/deactivate/${id}`,
|
||||||
|
body: { erase: true },
|
||||||
|
method: "POST",
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
rooms: {
|
rooms: {
|
||||||
path: "/_synapse/admin/v1/rooms",
|
path: "/_synapse/admin/v1/rooms",
|
||||||
@ -52,6 +62,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) {
|
||||||
@ -80,8 +104,8 @@ const dataProvider = {
|
|||||||
|
|
||||||
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 +120,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,9 +133,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}`))
|
||||||
).then(responses => ({
|
).then(responses => ({
|
||||||
data: responses.map(({ json }) => res.map(json)),
|
data: responses.map(({ json }) => res.map(json)),
|
||||||
}));
|
}));
|
||||||
@ -136,18 +160,12 @@ const dataProvider = {
|
|||||||
|
|
||||||
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(({ headers, json }) => ({
|
return jsonClient(url).then(({ headers, json }) => ({
|
||||||
data: json,
|
data: json,
|
||||||
total: parseInt(
|
total: parseInt(headers.get("content-range").split("/").pop(), 10),
|
||||||
headers
|
|
||||||
.get("content-range")
|
|
||||||
.split("/")
|
|
||||||
.pop(),
|
|
||||||
10
|
|
||||||
),
|
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -158,8 +176,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 }) => ({
|
||||||
@ -174,9 +192,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),
|
||||||
})
|
})
|
||||||
@ -191,16 +209,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");
|
||||||
@ -208,12 +251,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.id);
|
||||||
method: "DELETE",
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
}).then(({ json }) => ({
|
return jsonClient(endpoint_url, {
|
||||||
data: json,
|
method: del.method,
|
||||||
}));
|
body: JSON.stringify(del.body),
|
||||||
|
}).then(({ json }) => ({
|
||||||
|
data: json,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return jsonClient(`${endpoint_url}/${params.id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
|
}).then(({ json }) => ({
|
||||||
|
data: json,
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteMany: (resource, params) => {
|
deleteMany: (resource, params) => {
|
||||||
@ -223,17 +278,32 @@ const dataProvider = {
|
|||||||
|
|
||||||
const res = resourceMap[resource];
|
const res = resourceMap[resource];
|
||||||
|
|
||||||
const homeserver_url = homeserver + res.path;
|
if ("delete" in res) {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
params.ids.map(id =>
|
params.ids.map(id => {
|
||||||
jsonClient(`${homeserver_url}/${id}`, {
|
const del = res["delete"](id);
|
||||||
method: "DELETE",
|
const endpoint_url = homeserver + del.endpoint;
|
||||||
body: JSON.stringify(params.data, filterNullValues),
|
return jsonClient(endpoint_url, {
|
||||||
}).then(responses => ({
|
method: del.method,
|
||||||
data: responses.map(({ json }) => json),
|
body: JSON.stringify(del.body),
|
||||||
}))
|
});
|
||||||
)
|
})
|
||||||
);
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
const endpoint_url = homeserver + res.path;
|
||||||
|
return Promise.all(
|
||||||
|
params.ids.map(id =>
|
||||||
|
jsonClient(`${endpoint_url}/${id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
body: JSON.stringify(params.data, filterNullValues),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
).then(responses => ({
|
||||||
|
data: responses.map(({ json }) => json),
|
||||||
|
}));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user