Runde Bedienelemente, Admin zusammengelegt, Kanäle entfallen

Vier der acht Änderungswünsche.

**Knöpfe.** Rund vierzig der siebzig Knöpfe waren blosser Text in Akzentfarbe,
von einem Link nicht zu unterscheiden. Jeder trägt jetzt Rahmen und
Grundfläche, über die Klasse .btn an einer Stelle definiert statt siebzigmal
als Klassenkette. Beim Drücken zieht der Knopf sich zusammen und bekommt einen
inneren Ring — er wirkt kurz dicker, ohne dass die Rahmenbreite sich ändert und
das Umfeld springt; die Rückmeldung setzt ohne Verzögerung ein und klingt
langsam ab, sonst bliebe ein kurzer Klick unsichtbar.

Dazu die neue Regel: Flächen bleiben eckig, alles Bedienbare ist rund. Damit
ist die Rundung eine Auskunft und keine Verzierung.

**Verwaltung.** Rollen, Vorlagen und Änderungsrichtlinie waren drei Einträge in
der Kopfzeile für etwas, das man selten und dann zusammenhängend braucht. Jetzt
ein Eintrag /admin mit Reiterleiste, dazu eine gemeinsame Tabs-Komponente, die
auch der Fallakte zeigt, welcher Reiter offen ist.

**Kanäle.** Ersatzlos entfernt, mitsamt Tabelle. Der Chat gehört dorthin, wo
der Vorgang steht; ein eigener Reiter mit freien Räumen war der Rückweg nach
Discord. Die Personalakte hat jetzt denselben Chat wie die Fallakte — ohne
„als Vermerk übernehmen", denn dafür braucht es einen Verlauf, und Meldungen
gehen nur an Erwähnte, nie in den allgemeinen Kanal: dass es zu jemandem eine
Personalakte gibt, ist selbst eine Auskunft. Ein CHECK erzwingt jetzt, dass
eine Nachricht zu genau einem Ort gehört.

**Kopfzeile.** Suchbalken statt Suchlink, als gewöhnliches Formular ohne ein
Byte im Bündel. Thema, Benachrichtigungen und Abmelden sitzen hinter dem
Profilbild, das von Discord kommt; wer keins hat, bekommt seine Initialen.

Nebenbei: Aktenzeichen in Tests waren nur auf vier Stellen eindeutig und
kollidierten zwischen Läufen, weil Akten nicht löschbar sind.
This commit is contained in:
Harlekin
2026-09-03 15:07:43 +02:00
parent db40c5d3b2
commit 54176f17ba
80 changed files with 1130 additions and 745 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ import type { EffectivePermissions } from '@/lib/auth/permissions'
*/
export async function loadChatView(p: EffectivePermissions, scope: ChatScope) {
const { ort, nachrichten } = await listMessages(p, scope)
const scopeId = ort.caseId ?? ort.channelId!
const scopeId = ort.caseId ?? ort.personnelFileId!
const [autoren, vorschauen, reaktionen, lastReadAt, mitglieder] = await Promise.all([
db.user.findMany({
@@ -22,7 +22,7 @@ export async function loadChatView(p: EffectivePermissions, scope: ChatScope) {
}),
resolveCasePreviews(p, nachrichten.flatMap((n) => extractCaseNumbers(n.body))),
listReactions(p, nachrichten.map((n) => n.id)),
loadReadMarker(p, ort.caseId ? 'case' : 'channel', scopeId),
loadReadMarker(p, ort.caseId ? 'case' : 'personnel', scopeId),
// Für die Anzeige der Erwähnungen: Benutzername auf Anzeigename.
db.user.findMany({
where: { isActive: true },
+38 -101
View File
@@ -2,28 +2,32 @@ import { db } from '@/lib/db'
import { writeAudit } from '@/lib/audit'
import { AccessError, must } from '@/lib/errors'
import { visibleCaseWhere } from '@/lib/access/caseFilter'
import { visibleChannelWhere, visibleMessageWhere } from '@/lib/access/chatFilter'
import { visibleMessageWhere } from '@/lib/access/chatFilter'
import { visiblePersonnelWhere } from '@/lib/access/personnelFilter'
import { canEditCase } from '@/lib/access/caseWrite'
import { extractMentionNames } from '@/lib/chat/mentions'
import type { ReactionKey } from '@/lib/chat/terms'
import { caseTopic, channelTopic, publish, type Topic } from '@/lib/realtime/publish'
import { enqueueCaseNotification } from '@/lib/notify/enqueue'
import { caseTopic, personnelTopic, publish, type Topic } from '@/lib/realtime/publish'
import { enqueueCaseNotification, enqueuePersonnelNotification } from '@/lib/notify/enqueue'
import type { EffectivePermissions } from '@/lib/auth/permissions'
import type { Prisma } from '@afis/db'
/**
* Aktenchat und freie Kanäle.
* Der Aktenchat.
*
* Der Chat ist **ausdrücklich kein Aktenbestandteil** — er ist der formlose
* Teil, den die Abteilung bisher auf Discord hatte. Deshalb darf hier
* bearbeitet und zurückgezogen werden, ohne dass eine Version entsteht.
* Er hängt immer an einer Akte — einer Fallakte oder einer Personalakte — und
* ist **ausdrücklich kein Aktenbestandteil**: er ist der formlose Teil, den
* die Abteilung bisher auf Discord hatte. Deshalb darf hier bearbeitet und
* zurückgezogen werden, ohne dass eine Version entsteht.
*
* Die Brücke zum Aktenbestand ist `adoptAsEntry`: eine Nachricht wird per
* Klick zu einem Vermerk. Ab da gelten die harten Regeln der Akte.
* Siehe docs/06-chat-und-realtime.md.
*/
export type ChatScope = { kind: 'case'; caseNumber: string } | { kind: 'channel'; key: string }
export type ChatScope =
| { kind: 'case'; caseNumber: string }
| { kind: 'personnel'; fileId: string }
const NACHRICHT = {
id: true,
@@ -36,7 +40,7 @@ const NACHRICHT = {
mentions: true,
createdAt: true,
caseId: true,
channelId: true,
personnelFileId: true,
} satisfies Prisma.ChatMessageSelect
/**
@@ -47,7 +51,7 @@ const NACHRICHT = {
export async function resolveScope(
p: EffectivePermissions,
scope: ChatScope,
): Promise<{ caseId?: string; channelId?: string; topic: Topic; label: string } | null> {
): Promise<{ caseId?: string; personnelFileId?: string; topic: Topic; label: string } | null> {
if (scope.kind === 'case') {
const akte = await db.case.findFirst({
where: { AND: [visibleCaseWhere(p), { caseNumber: scope.caseNumber }] },
@@ -56,12 +60,15 @@ export async function resolveScope(
return akte ? { caseId: akte.id, topic: caseTopic(akte.id), label: akte.caseNumber } : null
}
const kanal = await db.channel.findFirst({
where: { AND: [visibleChannelWhere(p), { key: scope.key, isArchived: false }] },
select: { id: true, key: true },
// Personalakten setzen neben der Stufe ein eigenes Recht voraus.
if (!p.isAdmin && !p.permissions.has('personnel.read')) return null
const akte = await db.personnelFile.findFirst({
where: { AND: [visiblePersonnelWhere(p), { id: scope.fileId }] },
select: { id: true, displayName: true },
})
return kanal
? { channelId: kanal.id, topic: channelTopic(kanal.id), label: kanal.key }
return akte
? { personnelFileId: akte.id, topic: personnelTopic(akte.id), label: akte.displayName }
: null
}
@@ -82,7 +89,7 @@ export async function listMessages(
const wo: Prisma.ChatMessageWhereInput = ort.caseId
? { caseId: ort.caseId }
: { channelId: ort.channelId }
: { personnelFileId: ort.personnelFileId }
const nachrichten = await db.chatMessage.findMany({
where: { AND: [wo, ...(options.since ? [{ id: { gt: options.since } }] : [])] },
@@ -149,7 +156,7 @@ export async function sendMessage(
const ziel = await db.chatMessage.findFirst({
where: {
id: input.replyToId,
...(ort.caseId ? { caseId: ort.caseId } : { channelId: ort.channelId }),
...(ort.caseId ? { caseId: ort.caseId } : { personnelFileId: ort.personnelFileId }),
},
select: { id: true },
})
@@ -161,7 +168,7 @@ export async function sendMessage(
data: {
id: input.id,
caseId: ort.caseId ?? null,
channelId: ort.channelId ?? null,
personnelFileId: ort.personnelFileId ?? null,
authorId: p.userId,
body: text,
replyToId,
@@ -188,18 +195,15 @@ export async function sendMessage(
onlyFor: erwaehnt.length > 0 ? erwaehnt.map((u) => u.id) : undefined,
meta: { messageId: nachricht.id },
})
} else if (erwaehnt.length > 0) {
// In einem Kanal gibt es keine Akte, deren Sichtbarkeit zu prüfen wäre.
// Die Mindeststufe des Kanals hat der Absender schon passiert, und
// erwähnt wird nur, wer sie ebenfalls hat.
await tx.notificationOutbox.createMany({
data: erwaehnt.map((user) => ({
kind: 'chat.mention',
channelId: ort.channelId,
actorId: p.userId,
recipientId: user.id,
meta: { messageId: nachricht.id, channelKey: ort.label, actorName: absenderName },
})),
} else if (ort.personnelFileId) {
// Im Chat einer Personalakte geht nur an ausdrücklich Erwähnte etwas
// hinaus, und auch das nur an die, die die Akte lesen dürfen.
await enqueuePersonnelNotification(tx, {
personnelFileId: ort.personnelFileId,
actorId: p.userId,
actorName: absenderName,
mentioned: erwaehnt.map((user) => user.id),
meta: { messageId: nachricht.id },
})
}
@@ -378,9 +382,9 @@ export async function adoptAsEntry(
return { entryId }
}
function themaVon(nachricht: { caseId: string | null; channelId: string | null }): Topic {
function themaVon(nachricht: { caseId: string | null; personnelFileId: string | null }): Topic {
if (nachricht.caseId) return caseTopic(nachricht.caseId)
return channelTopic(nachricht.channelId!)
return personnelTopic(nachricht.personnelFileId!)
}
// ---------------------------------------------------------------------------
@@ -396,7 +400,7 @@ function themaVon(nachricht: { caseId: string | null; channelId: string | null }
*/
export async function loadReadMarker(
p: EffectivePermissions,
scopeType: 'case' | 'channel',
scopeType: 'case' | 'personnel',
scopeId: string,
): Promise<Date | null> {
const marker = await db.readMarker.findUnique({
@@ -408,7 +412,7 @@ export async function loadReadMarker(
export async function markRead(
p: EffectivePermissions,
scopeType: 'case' | 'channel',
scopeType: 'case' | 'personnel',
scopeId: string,
at: Date = new Date(),
): Promise<void> {
@@ -418,70 +422,3 @@ export async function markRead(
update: { lastReadAt: at },
})
}
// ---------------------------------------------------------------------------
// Kanäle
// ---------------------------------------------------------------------------
/** Die Kanäle, die dieser Nutzer sehen darf. */
export async function listChannels(p: EffectivePermissions) {
return db.channel.findMany({
where: { AND: [visibleChannelWhere(p), { isArchived: false }] },
orderBy: { name: 'asc' },
select: {
id: true,
key: true,
name: true,
description: true,
minClearance: true,
createdAt: true,
},
})
}
/**
* Kanal anlegen.
*
* Die Mindeststufe lässt sich nicht über die eigene heben — sonst legte
* jemand einen Raum an, den er selbst nicht mehr betreten kann, und dieselbe
* Regel gilt schon bei Akten und Dokumenten.
*/
export async function createChannel(
p: EffectivePermissions,
input: { key: string; name: string; description?: string | null; minClearance: number },
): Promise<{ key: string }> {
if (!p.isAdmin && !p.permissions.has('case.create')) throw new AccessError('no-permission')
if (input.minClearance > p.clearanceLevel && !p.isAdmin) {
throw new AccessError('clearance-too-low')
}
const key = input.key.trim().toLowerCase()
if (!/^[a-z0-9][a-z0-9-]{1,40}$/.test(key)) throw new AccessError('channel-key-invalid')
const vorhanden = await db.channel.findUnique({ where: { key }, select: { id: true } })
if (vorhanden) throw new AccessError('channel-key-taken')
return db.$transaction(async (tx) => {
const kanal = await tx.channel.create({
data: {
key,
name: input.name.trim().slice(0, 120),
description: input.description?.trim() || null,
minClearance: input.minClearance,
createdById: p.userId,
},
select: { key: true },
})
await writeAudit(tx, {
actorId: p.userId,
action: 'channel.create',
targetType: 'Channel',
targetId: kanal.key,
clearanceAtTime: p.clearanceLevel,
meta: { key: kanal.key, minClearance: input.minClearance },
})
return kanal
})
}