Steuere das Herunterladen von Originalen je Rolle, benenne Dateien richtig und zeige HTML-Mails gesichert im Sandbox-Rahmen.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a5daf6713
commit
075525ee17
26 files changed
+494
-71
No files matched your search
@@ -3,6 +3,8 @@ import { api } from "../api.js";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { ErrorNote } from "../pages/widgets.jsx";
|
||||
import { formatWhen } from "./admin-core.js";
|
||||
import { DownloadPolicy } from "./DownloadPolicy.jsx";
|
||||
import { isEmployee } from "./admin-core.js";
|
||||
import { PasswordForm } from "./widgets.jsx";
|
||||
|
||||
export function Account() {
|
||||
@@ -54,6 +56,17 @@ export function Account() {
|
||||
</header>
|
||||
<ErrorNote error={error} />
|
||||
{notice ? <p className="notice" role="status">{notice}</p> : null}
|
||||
{isEmployee(session) ? null : (
|
||||
<section className="card stack" aria-label="Herunterladen">
|
||||
<h2>Herunterladen von Originalen</h2>
|
||||
<DownloadPolicy
|
||||
path="/api/v1/auth/download-defaults"
|
||||
editable
|
||||
withDirect
|
||||
intro="Diese Regel übernehmen neue Räume. Bestehende Räume ändert ihr Eigentümer in der Raumverwaltung. Die Regel für direkt freigegebene Personen gilt sofort für alle deine Einträge."
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
<section className="card stack" aria-label="Passwort">
|
||||
<h2>Passwort ändern</h2>
|
||||
<p className="muted">Beim Ändern werden deine anderen Sitzungen beendet.</p>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api } from "../api.js";
|
||||
import { ErrorNote } from "../pages/widgets.jsx";
|
||||
|
||||
const ROLES = [
|
||||
["manager", "Verwalter"],
|
||||
["member", "Mitglieder"],
|
||||
["reader", "Leser"],
|
||||
];
|
||||
|
||||
// Who may save a document or mail to their device. Reading in Tsumugu stays possible for everyone.
|
||||
// The rule applies to saving and opening the original, not to what the screen shows.
|
||||
export function DownloadPolicy({ path, editable, withDirect = false, intro }) {
|
||||
const [roles, setRoles] = useState(null);
|
||||
const [canChange, setCanChange] = useState(editable);
|
||||
const [error, setError] = useState("");
|
||||
const [notice, setNotice] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api(path).then((data) => {
|
||||
if (!alive) return;
|
||||
setRoles(data.roles);
|
||||
if (data.can_change !== undefined) setCanChange(data.can_change);
|
||||
}).catch((err) => alive && setError(err.message));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [path]);
|
||||
|
||||
async function change(key, value) {
|
||||
setError("");
|
||||
setNotice("");
|
||||
const next = { ...roles, [key]: value };
|
||||
try {
|
||||
const saved = await api(path, { method: "PUT", body: next });
|
||||
setRoles(saved.roles);
|
||||
setNotice("Die Regel ist gespeichert.");
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (!roles) return error ? <ErrorNote error={error} /> : null;
|
||||
const items = withDirect ? [...ROLES, ["direct", "Direkt freigegebene Personen"]] : ROLES;
|
||||
return (
|
||||
<fieldset className="pick-group">
|
||||
<legend>Herunterladen erlaubt für</legend>
|
||||
{intro ? <p className="muted">{intro}</p> : null}
|
||||
{items.map(([key, label]) => (
|
||||
<label key={key} className="check">
|
||||
<input type="checkbox" checked={Boolean(roles[key])} disabled={!canChange} onChange={(event) => change(key, event.target.checked)} />
|
||||
{label}
|
||||
</label>
|
||||
))}
|
||||
<span className="muted">Lesen in Tsumugu bleibt für alle Rollen möglich. Die Regel betrifft das Speichern und Öffnen der Originale sowie das Übergabepaket. Was auf dem Bildschirm erscheint, lässt sich damit nicht gegen Abfotografieren schützen.</span>
|
||||
{canChange ? null : <span className="muted">Nur der Eigentümer kann die Regel ändern.</span>}
|
||||
<ErrorNote error={error} />
|
||||
{notice ? <p className="notice" role="status">{notice}</p> : null}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
+34
-24
@@ -92,18 +92,48 @@ export async function fetchMailPart(elementId, context, suffix) {
|
||||
return response.blob();
|
||||
}
|
||||
|
||||
export async function downloadMailPart(elementId, context, suffix, filename) {
|
||||
const blob = await fetchMailPart(elementId, context, suffix);
|
||||
// The name the server gave the file (RFC 5987 form first), so a saved file keeps its real name.
|
||||
export function nameFromDisposition(header, fallback) {
|
||||
const text = header || "";
|
||||
const star = /filename\*\s*=\s*UTF-8''([^;]+)/i.exec(text);
|
||||
if (star) {
|
||||
try {
|
||||
return decodeURIComponent(star[1].trim());
|
||||
} catch {
|
||||
/* fall through to the plain name */
|
||||
}
|
||||
}
|
||||
const plain = /filename\s*=\s*"([^"]+)"/i.exec(text) || /filename\s*=\s*([^;]+)/i.exec(text);
|
||||
return plain ? plain[1].trim() : fallback;
|
||||
}
|
||||
|
||||
export function saveBlob(blob, filename) {
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename || "nachricht.eml";
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
}
|
||||
|
||||
// Saves a document to the device. The server checks the download right of the role.
|
||||
export async function saveDocument(path, context, fallbackName) {
|
||||
const params = mailQuery(context);
|
||||
params.set("save", "true");
|
||||
const response = await fetch(`${path}?${params}`, { credentials: "include", headers: scopeHeaders() });
|
||||
if (!response.ok) {
|
||||
const data = await response.json().catch(() => null);
|
||||
throw new Error(data?.detail || "Die Datei ist nicht verfügbar.");
|
||||
}
|
||||
saveBlob(await response.blob(), nameFromDisposition(response.headers.get("Content-Disposition"), fallbackName));
|
||||
}
|
||||
|
||||
export async function downloadMailPart(elementId, context, suffix, filename) {
|
||||
await saveDocument(`/api/v1/external-refs/${elementId}/mail/${suffix}`, context, filename || "nachricht.eml");
|
||||
}
|
||||
|
||||
export async function fetchExternal(elementId, context) {
|
||||
const params = new URLSearchParams();
|
||||
if (context?.kind && context?.id) {
|
||||
@@ -140,27 +170,7 @@ export async function fetchFile(elementId, context) {
|
||||
}
|
||||
|
||||
export async function downloadFile(elementId, context, filename) {
|
||||
const params = new URLSearchParams();
|
||||
if (context?.kind && context?.id) {
|
||||
params.set("context_kind", context.kind);
|
||||
params.set("context_id", context.id);
|
||||
}
|
||||
const response = await fetch(`/api/v1/files/${elementId}/content?${params}`, {
|
||||
credentials: "include",
|
||||
headers: scopeHeaders(),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error("Die Datei ist nicht verfügbar.");
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = filename || "datei";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
await saveDocument(`/api/v1/files/${elementId}/content`, context, filename || "datei");
|
||||
}
|
||||
|
||||
export async function fetchBlob(path) {
|
||||
|
||||
@@ -150,3 +150,6 @@ body.is-resizing .library__resizer { background: color-mix(in srgb, var(--accent
|
||||
.app-main:has(.workspace) .library__main { flex: 1; }
|
||||
}
|
||||
@media (max-width: 759px) { body.is-phone-reading .library__toggle { display: none; } }
|
||||
|
||||
.mail-frame { display: block; width: 100%; height: 60vh; min-height: 260px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
|
||||
.mail-reading .segmented { display: inline-flex; gap: 6px; margin-bottom: 8px; }
|
||||
@@ -1,9 +1,38 @@
|
||||
import { useState } from "react";
|
||||
|
||||
// The cleaned HTML of a mail is shown in a frame without scripts and without any reach into the app:
|
||||
// an empty `sandbox` gives it its own origin, and the policy inside allows no loads except inline images.
|
||||
const FRAME_POLICY = "default-src 'none'; img-src data:; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'";
|
||||
|
||||
export function mailDocument(html) {
|
||||
return `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${FRAME_POLICY}">`
|
||||
+ '<meta name="referrer" content="no-referrer"><meta name="viewport" content="width=device-width, initial-scale=1"><base target="_blank">'
|
||||
+ "<style>body{margin:12px;font:15px/1.45 system-ui,sans-serif;color:#1c1b18;background:#fff;overflow-wrap:anywhere}"
|
||||
+ "img,table{max-width:100%}table{border-collapse:collapse}a{color:#0b5d4b}blockquote{margin:8px 0 8px 4px;padding-left:10px;border-left:3px solid #ccc;color:#555}</style>"
|
||||
+ `</head><body>${html}</body></html>`;
|
||||
}
|
||||
|
||||
export function MailBody({ html, text, truncated, notices = [] }) {
|
||||
const [view, setView] = useState(html ? "html" : "text");
|
||||
const mode = html ? view : "text";
|
||||
return (
|
||||
<div className="mail-reading">
|
||||
{html ? <div className="mail-letter__html" dangerouslySetInnerHTML={{ __html: html }} /> : null}
|
||||
<p className="muted">Vereinfachte Textfassung. Sie ist nicht die formatierte Ansicht.</p>
|
||||
{text ? <pre className="mail-letter__body">{text}</pre> : <p className="muted">Diese Nachricht hat keinen lesbaren Text.</p>}
|
||||
{html ? (
|
||||
<div className="segmented" role="group" aria-label="Darstellung der Nachricht">
|
||||
<button type="button" className={mode === "html" ? "" : "quiet"} aria-pressed={mode === "html"} onClick={() => setView("html")}>Formatiert</button>
|
||||
<button type="button" className={mode === "text" ? "" : "quiet"} aria-pressed={mode === "text"} onClick={() => setView("text")}>Nur Text</button>
|
||||
</div>
|
||||
) : null}
|
||||
{mode === "html" ? (
|
||||
<>
|
||||
<iframe className="mail-frame" title="Nachricht" sandbox="allow-popups allow-popups-to-escape-sandbox" referrerPolicy="no-referrer" srcDoc={mailDocument(html)} />
|
||||
<p className="muted">Aus Sicherheitsgründen sind Skripte, eingebettete Formulare und Bilder von fremden Servern entfernt. Links öffnen externe Seiten: nur bekannten Absendern vertrauen.</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{text ? <pre className="mail-letter__body">{text}</pre> : <p className="muted">Diese Nachricht hat keinen lesbaren Text.</p>}
|
||||
</>
|
||||
)}
|
||||
{truncated ? <p className="muted">Der Text ist gekürzt, weil die Nachricht sehr groß ist. Das Original bleibt die vollständige E-Mail.</p> : null}
|
||||
{notices.map((item) => <p key={item} className="notice">{item}</p>)}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DocumentView } from "./DocumentView.jsx";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { documentToText, downloadMailPart, fetchExternal, fetchFile, fetchMailPart, isDirty, markDirty, textToDocument, api } from "../api.js";
|
||||
import { documentToText, downloadMailPart, fetchExternal, fetchFile, fetchMailPart, isDirty, markDirty, saveDocument, textToDocument, api } from "../api.js";
|
||||
import { SourceAssignment, representationOf, stageFor } from "../sources/registry.jsx";
|
||||
import "../sources/builtin-views.jsx";
|
||||
import { ErrorNote } from "./widgets.jsx";
|
||||
@@ -356,12 +356,10 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
setError("");
|
||||
try {
|
||||
const view = representationOf(element);
|
||||
const blob = view === "source-file" || view === "text"
|
||||
? await fetchExternal(element.id, context)
|
||||
: await fetchFile(element.id, context);
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, "_blank", "noopener");
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
const path = view === "source-file" || view === "text"
|
||||
? `/api/v1/external-refs/${element.id}/content`
|
||||
: `/api/v1/files/${element.id}/content`;
|
||||
await saveDocument(path, context, element.file?.filename || element.title || "dokument");
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
@@ -526,8 +524,8 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
</p>
|
||||
</div>
|
||||
<div className="reader-pane__tools">
|
||||
{element.kind !== "note" && !isMail ? (
|
||||
<button type="button" className="icon-button" aria-label="Original öffnen" onClick={openOriginal}>
|
||||
{element.kind !== "note" && !isMail && binding.rights.download ? (
|
||||
<button type="button" className="icon-button" aria-label="Original herunterladen" title="Original herunterladen" onClick={openOriginal}>
|
||||
<NavIcon name="link" />
|
||||
</button>
|
||||
) : null}
|
||||
@@ -572,13 +570,13 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
{!isMail && !locked && !unassigned && phase === "missing" ? (
|
||||
<div className="reader-pane__state">
|
||||
<p>Für diesen Inhalt gibt es keine eingebaute Vorschau.</p>
|
||||
<button type="button" onClick={openOriginal}>Original öffnen</button>
|
||||
{binding.rights.download ? <button type="button" onClick={openOriginal}>Original herunterladen</button> : null}
|
||||
</div>
|
||||
) : null}
|
||||
{!isMail && phase === "error" ? (
|
||||
<div className="reader-pane__state">
|
||||
<p>Die Vorschau ist nicht verfügbar.</p>
|
||||
<button type="button" onClick={openOriginal}>Original öffnen</button>
|
||||
{binding.rights.download ? <button type="button" onClick={openOriginal}>Original herunterladen</button> : null}
|
||||
</div>
|
||||
) : null}
|
||||
{!isMail && media === "text" ? <pre className="mail-letter__body">{sourceText}</pre> : null}
|
||||
@@ -590,7 +588,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
{!isMail && media === "other" && blobUrl ? (
|
||||
<div className="reader-pane__state">
|
||||
<p>Die Datei ist geladen, aber hier nicht als Seite darstellbar.</p>
|
||||
<a href={blobUrl} target="_blank" rel="noreferrer">Original öffnen</a>
|
||||
{binding.rights.download ? <a href={blobUrl} target="_blank" rel="noreferrer">Original öffnen</a> : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
lastManagerIds,
|
||||
roleLabel,
|
||||
} from "../admin/admin-core.js";
|
||||
import { DownloadPolicy } from "../admin/DownloadPolicy.jsx";
|
||||
import { OneTimeSecret } from "../admin/widgets.jsx";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { ErrorNote } from "./widgets.jsx";
|
||||
@@ -176,6 +177,8 @@ export function RoomAdmin({ room, onRenamed, onArchived }) {
|
||||
</label>
|
||||
) : null}
|
||||
|
||||
<DownloadPolicy path={`/api/v1/rooms/${room.id}/download-policy`} editable={Boolean(room.is_owner)} />
|
||||
|
||||
<h3>Mitglieder</h3>
|
||||
<ul className="index">
|
||||
{members.map((member) => (
|
||||
|
||||
@@ -200,9 +200,11 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
|
||||
{element.kind === "note" ? <RegisteredNote element={element} context={context} binding={binding} onReload={onChange} /> : null}
|
||||
{element.kind === "file" && element.file ? (
|
||||
element.file.status === "active" ? (
|
||||
<button type="button" onClick={() => downloadFile(element.id, context, element.file.filename)}>
|
||||
{element.file.filename} herunterladen
|
||||
</button>
|
||||
binding.rights.download ? (
|
||||
<button type="button" onClick={() => downloadFile(element.id, context, element.file.filename).catch((err) => setError(err.message))}>
|
||||
{element.file.filename} herunterladen
|
||||
</button>
|
||||
) : <p className="muted">{element.file.filename} · Das Herunterladen ist für dich nicht freigegeben.</p>
|
||||
) : (
|
||||
<p className="error">Die Datei ist gerade nicht verfügbar.</p>
|
||||
)
|
||||
|
||||
@@ -124,7 +124,7 @@ export function TextStage({ element, context }) {
|
||||
);
|
||||
}
|
||||
|
||||
export function MailStage({ element, context, shownDirection }) {
|
||||
export function MailStage({ element, context, binding, shownDirection }) {
|
||||
const [letter, setLetter] = useState(null);
|
||||
const [error, setError] = useState("");
|
||||
const [shownFor, setShownFor] = useState(null);
|
||||
@@ -236,7 +236,7 @@ export function MailStage({ element, context, shownDirection }) {
|
||||
async function openOriginal() {
|
||||
setError("");
|
||||
try {
|
||||
await downloadMailPart(element.id, context, "original", "nachricht.eml");
|
||||
await downloadMailPart(element.id, context, "original", `${letter?.title || "nachricht"}.eml`);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
@@ -262,7 +262,7 @@ export function MailStage({ element, context, shownDirection }) {
|
||||
{media === "image" && blobUrl ? <img className="reader-image" alt={shownFile?.filename || element.title} src={blobUrl} /> : null}
|
||||
{media === "pdf" && pdf ? <canvas ref={canvasRef} className="reader-canvas" /> : null}
|
||||
{media === "pdf-frame" && blobUrl ? <DocumentView title={shownFile?.filename || element.title} url={blobUrl} /> : null}
|
||||
{media === "other" && blobUrl ? <a href={blobUrl} target="_blank" rel="noreferrer">Anlage öffnen</a> : null}
|
||||
{media === "other" && blobUrl && binding?.rights?.download ? <a href={blobUrl} target="_blank" rel="noreferrer">Anlage öffnen</a> : null}
|
||||
{pages > 1 ? (
|
||||
<div className="reader-pages">
|
||||
<button type="button" disabled={page <= 1} onClick={() => setPage((current) => Math.max(1, current - 1))}>Vorherige Seite</button>
|
||||
@@ -271,7 +271,7 @@ export function MailStage({ element, context, shownDirection }) {
|
||||
</div>
|
||||
) : null}
|
||||
<MailBody html={letter.html} text={letter.text} truncated={letter.text_truncated} notices={letter.notices} />
|
||||
<button type="button" onClick={openOriginal}>Vollständige E-Mail</button>
|
||||
{binding?.rights?.download ? <button type="button" onClick={openOriginal}>Vollständige E-Mail herunterladen</button> : null}
|
||||
</>
|
||||
) : (
|
||||
<p className="muted">{error ? "Die vollständige Nachricht konnte nicht geladen werden." : "Die vollständige Nachricht wird geladen …"}</p>
|
||||
|
||||
Reference in new issue
Block a user