Compare commits

..
2 Commits
Author SHA1 Message Date
ClaudeandClaude Opus 5.5 4fc4c70b7d Archiv/Rechte: Review-Punkte
- archiviertes Projekt bleibt unter Funktionen sichtbar, solange dort eine
  Funktion bestellt/eingerichtet/aktiv ist (z. B. Terminbuchungen)
- auf archivierten Projekten nichts neu bestellen oder einschalten
- Projekttyp Vorlage nur fuer Admins; repo-readme nur fuer bekannte Projekte

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 15:11:54 +00:00
ClaudeandClaude Opus 5.5 3156bb790a Projekte: alle Mitarbeiter, private Repos, Archiv fuer Kunden ausgeblendet
Entscheidungen vom 04.10.2026:
- Projekt-Routen (website-projects, preview, gitea, services, analyse)
  fuer jeden Mitarbeiter (Label mitarbeiter oder admin); Kunden-,
  Mitarbeiter- und Finanz-Verwaltung bleiben nur fuer Admins
- Neue Repos aus der Vorlage werden privat angelegt
- Archivierte Projekte sieht der Kunde nicht mehr: Projektliste,
  Projektdetails, Preview-Zugang, Funktionen (Mitarbeiter-Ansicht schon)
- Projektliste des Kunden mit Limit (Appwrite liefert sonst nur 25)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 15:02:02 +00:00
15 changed files with 172 additions and 25 deletions

No files matched your search

+17 -3
View File
@@ -1,6 +1,20 @@
import { config } from '../config.js'
import { ADMIN_LABEL, STAFF_LABELS } from '../services/staffLabels.js'
export async function requireAppwriteStaff(req, res, next) {
/**
* Prueft das Appwrite-JWT aus dem Ticketsystem und verlangt eines der Labels `allowed`.
* requireAppwriteStaff: nur "admin" (Kunden, Mitarbeiter, Finanzen ...).
* requireAppwriteTeam: jeder Mitarbeiter ("mitarbeiter" oder "admin") - Projekt-Aktionen
* (Anlegen, Zuordnen, Archivieren, Preview, Analyse, Gitea-Import), Entscheidung 2026-10-04.
*/
function requireAppwriteLabels(allowed, deniedMessage) {
return (req, res, next) => checkAppwriteJwt(req, res, next, allowed, deniedMessage)
}
export const requireAppwriteStaff = requireAppwriteLabels([ADMIN_LABEL], 'Admin-Berechtigung erforderlich')
export const requireAppwriteTeam = requireAppwriteLabels(STAFF_LABELS, 'Nur für Mitarbeiter')
async function checkAppwriteJwt(req, res, next, allowed, deniedMessage) {
const authHeader = req.get('Authorization') || ''
const match = authHeader.match(/^Bearer\s+(.+)$/i)
if (!match) {
@@ -32,8 +46,8 @@ export async function requireAppwriteStaff(req, res, next) {
return res.status(401).json({ error: data?.message || 'Ungültiges JWT' })
}
if (!Array.isArray(data?.labels) || !data.labels.includes('admin')) {
return res.status(403).json({ error: 'Admin-Berechtigung erforderlich' })
if (!Array.isArray(data?.labels) || !allowed.some((label) => data.labels.includes(label))) {
return res.status(403).json({ error: deniedMessage })
}
req.appwriteUser = data
+3 -2
View File
@@ -2,12 +2,13 @@
import { Router } from 'express'
import { config } from '../../config.js'
import { getDocument } from '../../services/appwriteAdmin.js'
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
import { requireAppwriteTeam } from '../../middleware/appwriteStaff.js'
import { activateAnalyse, analyseEligibility, controllerView, deactivateAnalyse, ELIGIBILITY_MESSAGES, validateTextform } from '../../services/analyse.js'
import { getFeatureDoc } from '../../services/siteFeatures.js'
const router = Router()
router.use(requireAppwriteStaff)
// Projekt-Aktionen: jeder Mitarbeiter (nicht nur Admins)
router.use(requireAppwriteTeam)
function sendError(res, err) {
const status = [400, 403, 404, 409, 503].includes(err.status) && !err.type ? err.status : 500
+1 -1
View File
@@ -49,7 +49,7 @@ async function ticketExists(ticketId) {
// Die Funktionsdokumente des Kunden werden einmal gelesen und fuer alle Projekte und Funktionen verwendet
async function adminView(customerId) {
const docs = await listCustomerFeatureDocs(customerId)
const projects = await listCustomerFeatures(customerId, { docs })
const projects = await listCustomerFeatures(customerId, { docs, includeArchived: true })
for (const p of projects) {
for (const key of FEATURE_KEYS) {
const view = p.features[key]
+11 -2
View File
@@ -1,10 +1,13 @@
import { Router } from 'express'
import { config } from '../../config.js'
import { listDocuments, Query } from '../../services/appwriteAdmin.js'
import { syncReposToAppwrite, fetchRepoReadme, importNewRepos } from '../../services/giteaAdmin.js'
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
import { requireAppwriteTeam } from '../../middleware/appwriteStaff.js'
const router = Router()
router.use(requireAppwriteStaff)
// Projekt-Aktionen: jeder Mitarbeiter (nicht nur Admins)
router.use(requireAppwriteTeam)
router.post('/sync-repos', async (_req, res) => {
try {
@@ -35,6 +38,12 @@ router.get('/repo-readme', async (req, res) => {
}
try {
// Nur Repos, die ein Projekt sind - der System-Schluessel sieht sonst jedes (auch private) Repo
const known = await listDocuments(config.collections.websiteProjects, [
Query.equal('repoFullName', repoFullName),
Query.limit(1),
])
if (!known[0]) return res.status(404).json({ error: 'Projekt nicht gefunden' })
const readme = await fetchRepoReadme(repoFullName)
if (!readme) {
return res.json({ ok: true, found: false, repoFullName })
+3 -2
View File
@@ -2,7 +2,7 @@
import { Router } from 'express'
import { config } from '../../config.js'
import { getDocument, updateDocument } from '../../services/appwriteAdmin.js'
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
import { requireAppwriteTeam } from '../../middleware/appwriteStaff.js'
import { envKey, encryptEnv, decryptEnv, envNames, validateEnvChange } from '../../services/previewEnv.js'
import { listRunLogs, readRunLog, isRunFile } from '../../services/previewLogs.js'
import * as runnerClient from '../../services/previewRunnerClient.js'
@@ -11,7 +11,8 @@ import { withLocks } from '../../services/keyedLock.js'
import { repoHasDevScript } from '../../services/previewDevScript.js'
const router = Router()
router.use(requireAppwriteStaff)
// Projekt-Aktionen: jeder Mitarbeiter (nicht nur Admins)
router.use(requireAppwriteTeam)
const BUSY = 'Server ausgelastet, versuche es gleich noch mal'
const MODES = ['auto', 'build', 'dev', 'off']
+3 -2
View File
@@ -2,11 +2,12 @@ import { Router } from 'express'
import { config } from '../../config.js'
import { listDocuments, Query } from '../../services/appwriteAdmin.js'
import { servicesCatalog } from '../../services/projectKinds.js'
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
import { requireAppwriteTeam } from '../../middleware/appwriteStaff.js'
const router = Router()
router.use(requireAppwriteStaff)
// Projekt-Aktionen: jeder Mitarbeiter (nicht nur Admins)
router.use(requireAppwriteTeam)
const CHUNK = 100
+7 -2
View File
@@ -6,11 +6,12 @@ import {
} from '../../services/giteaAdmin.js'
import { assignProject, reconcileProject } from '../../services/projectAssignment.js'
import { completeAssignment } from '../../services/projectKindAssign.js'
import { requireAppwriteStaff } from '../../middleware/appwriteStaff.js'
import { requireAppwriteTeam } from '../../middleware/appwriteStaff.js'
const router = Router()
router.use(requireAppwriteStaff)
// Projekt-Aktionen: jeder Mitarbeiter (nicht nur Admins)
router.use(requireAppwriteTeam)
router.post('/create-from-template', async (req, res) => {
const { repoName, displayName, subdomain, customerId = '', ticketId = '', owner, kind = '' } = req.body || {}
@@ -40,6 +41,10 @@ router.post('/create-from-template', async (req, res) => {
// Projekt bearbeiten: Name / Subdomain / Typ -> synchronisiert Git + Preview + Appwrite
router.patch('/:id', async (req, res) => {
const { projectName, subdomain, projectType } = req.body || {}
// Vorlagen bleiben Admin-Sache (im Ticketsystem nur fuer Admins sichtbar)
if (projectType === 'template' && !req.appwriteUser?.labels?.includes('admin')) {
return res.status(403).json({ error: 'Nur Admins können Vorlagen anlegen.' })
}
try {
const result = await updateWebsiteProject(req.params.id, { projectName, subdomain, projectType })
return res.json({ ok: true, ...result })
+2 -1
View File
@@ -292,7 +292,8 @@ router.get('/preview-access', async (req, res) => {
const projects = await listDocuments(config.collections.websiteProjects, queries)
const project = projects[0]
if (!project) {
// Archiviert: fuer Kunden wie kein Projekt (das Portal blendet es aus)
if (!project || (project.archived && !admin)) {
return res.json({ allowed: false, reason: 'no_project' })
}
if (!isPreviewProjectReady(project)) {
+2 -1
View File
@@ -147,7 +147,7 @@ router.post('/news/checkout', requireSession, async (req, res) => {
return res.status(400).json({ error: 'Bitte wähle ein Projekt.' })
}
const customerId = getSessionCustomerId(req)
await assertOwnProject(customerId, projectId)
await assertOwnProject(customerId, projectId, { forNewOrder: true })
// Pruefen, Sitzung anlegen und eintragen als Ganzes je (Kunde, Projekt): zwei schnelle Klicks duerfen keine
// zwei Sitzungen erzeugen, sonst ueberschreibt die zweite die ID der ersten und deren Zahlung findet kein Dokument
const session = await withLocks([`feature-order:${customerId}:${projectId}`], async () => {
@@ -188,6 +188,7 @@ router.post('/analyse/activate', analyseGuard, async (req, res) => {
return res.status(403).json({ error: 'In der Kundenansicht kann nichts geändert werden.' })
}
const { projectId, accentColor, consent } = req.body || {}
await assertOwnProject(getSessionCustomerId(req), analyseProjectId(projectId), { forNewOrder: true })
const { doc } = await activateAnalyse({
customerId: getSessionCustomerId(req),
projectId: analyseProjectId(projectId),
+5 -2
View File
@@ -14,7 +14,8 @@ const router = Router()
async function loadOwnProject(req, res, next) {
const customerId = getSessionCustomerId(req)
const project = await getDocument(config.collections.websiteProjects, req.params.id).catch(() => null)
if (!project || !customerId || project.customerId !== customerId) {
// Archivierte Projekte sieht der Kunde nicht mehr (wie in der Liste)
if (!project || !customerId || project.customerId !== customerId || project.archived) {
return res.status(404).json({ error: 'Projekt nicht gefunden' })
}
req.project = project
@@ -31,9 +32,11 @@ router.get('/', requireSession, async (req, res) => {
const projects = await listDocuments(config.collections.websiteProjects, [
Query.equal('customerId', customerId),
Query.orderDesc('$createdAt'),
Query.limit(500), // ohne Limit liefert Appwrite nur 25
])
const sanitized = projects.map((p) => ({
// Archivierte Projekte (Vorschau entfernt) blendet das Portal aus (Entscheidung 2026-10-04)
const sanitized = projects.filter((p) => !p.archived).map((p) => ({
id: p.$id,
projectName: p.projectName || '',
subdomain: p.subdomain || '',
+3 -1
View File
@@ -218,7 +218,9 @@ export async function generateRepoFromTemplate({ owner, repoName, description })
body: JSON.stringify({
owner: targetOwner,
name: repoName,
private: false,
// Kundenquelltext nicht oeffentlich (Entscheidung 2026-10-04). Portal und Preview-Runner
// lesen Gitea mit dem System-Schluessel, Mitarbeiter sehen Org-Repos ueber das Team Owners.
private: true,
// Die Beschreibung ist der Projektname in Gitea (Abgleich und Webhook lesen ihn von dort)
description: description || `Website-Projekt ${repoName}`,
git_content: true,
+15 -6
View File
@@ -64,7 +64,8 @@ export async function getFeatureDoc(customerId, projectId, key) {
}
}
export async function assertOwnProject(customerId, projectId) {
/** forNewOrder: Neu bestellen/einschalten geht auf archivierten Projekten nicht mehr (Kunde sieht sie nicht). */
export async function assertOwnProject(customerId, projectId, { forNewOrder = false } = {}) {
let project = null
try {
project = await getDocument(config.collections.websiteProjects, projectId)
@@ -72,6 +73,9 @@ export async function assertOwnProject(customerId, projectId) {
if (err.status !== 404) throw err
}
if (!project || !customerId || project.customerId !== customerId) throw httpError(403, 'Kein Zugriff auf dieses Projekt')
if (forNewOrder && project.archived) {
throw httpError(409, 'Dieses Projekt ist archiviert - dafür kann nichts mehr bestellt oder eingeschaltet werden.')
}
return project
}
@@ -129,14 +133,19 @@ export function listCustomerFeatureDocs(customerId) {
return listDocuments(config.collections.portalFeatures, [Query.equal('customerId', customerId), Query.limit(1000)])
}
/** docs: bereits geladene Funktionsdokumente des Kunden (listCustomerFeatureDocs), damit sie nicht doppelt gelesen werden. */
export async function listCustomerFeatures(customerId, { docs: geladen } = {}) {
const projects = await listDocuments(config.collections.websiteProjects, [
/**
* docs: bereits geladene Funktionsdokumente des Kunden (listCustomerFeatureDocs), damit sie nicht doppelt gelesen werden.
* includeArchived: nur fuer die Mitarbeiter-Ansicht. Der Kunde sieht archivierte Projekte nur noch, solange dort
* eine Funktion bestellt/eingerichtet/aktiv ist - sonst kaeme er z. B. nicht mehr an seine Terminbuchungen.
*/
export async function listCustomerFeatures(customerId, { docs: geladen, includeArchived = false } = {}) {
const docs = geladen ?? (await listCustomerFeatureDocs(customerId))
const laufend = new Set(docs.filter((d) => ['ordered', 'setup', 'active'].includes(d.state)).map((d) => d.projectId))
const projects = (await listDocuments(config.collections.websiteProjects, [
Query.equal('customerId', customerId),
Query.orderDesc('$createdAt'),
Query.limit(1000),
])
const docs = geladen ?? (await listCustomerFeatureDocs(customerId))
])).filter((p) => includeArchived || !p.archived || laufend.has(p.$id))
const result = []
for (const p of projects) {
const features = {}
+11
View File
@@ -67,3 +67,14 @@ test('Route: anderer Kunde bleibt ausgesperrt', async () => {
assert.equal(r.allowed, false)
assert.equal(r.reason, 'no_project')
})
test('Route: archiviertes Projekt ist fuer den Kunden gesperrt (Entscheidung 2026-10-04)', async () => {
const doc = aw.all('websiteProjects').find((d) => d.$id === 'p1')
doc.archived = true
try {
const r = await access(token.c1)
assert.equal(r.allowed, false)
assert.equal(r.reason, 'no_project')
} finally {
doc.archived = false
}
})
+2
View File
@@ -76,6 +76,8 @@ test('Neues Projekt ohne Subdomain: kein subdomain-Konflikt mehr, Kunde bleibt d
// Gitea-Beschreibung = Anzeigename (Abgleich/Webhook lesen den Namen von dort)
const gen = gitea.calls.find((c) => c.method === 'POST' && c.path.endsWith('/generate'))
assert.equal(gen.body.description, 'Zweites ohne Website')
// Kundenquelltext nicht oeffentlich (Entscheidung 2026-10-04)
assert.equal(gen.body.private, true)
})
test('Neues Projekt: Webhook repository/created legt das Dokument zuerst an -> eines, mit Kunde und Ticket', async () => {
+87
View File
@@ -0,0 +1,87 @@
// Entscheidungen vom 04.10.2026: Projekt-Aktionen fuer alle Mitarbeiter, archivierte Projekte im
// Kundenportal ausgeblendet. (Private Repos: siehe projektAblauf.test.js, generate-Aufruf.)
import { test, after } from 'node:test'
import assert from 'node:assert/strict'
import { startAppwriteMock } from './support/appwriteMock.js'
import { startFakeStripe } from './support/fakeStripe.js'
import { useTestEnv } from './support/testEnv.js'
const aw = await startAppwriteMock()
const st = await startFakeStripe()
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
const { startTestApp, rawGet, get, send, sessionCookie } = await import('./support/testApp.js')
const { default: projectsRouter } = await import('../server/routes/projects.js')
const { default: servicesRouter } = await import('../server/routes/admin/services.js')
const { default: customersRouter } = await import('../server/routes/admin/customers.js')
const { default: websiteProjectsRouter } = await import('../server/routes/admin/websiteProjects.js')
const { default: giteaRouter } = await import('../server/routes/admin/gitea.js')
const { default: funktionenRouter } = await import('../server/routes/funktionen.js')
const app = await startTestApp({
'/api/projects': projectsRouter,
'/api/admin/services': servicesRouter,
'/api/admin/customers': customersRouter,
'/api/admin/website-projects': websiteProjectsRouter,
'/api/admin/gitea': giteaRouter,
'/api/funktionen': funktionenRouter,
})
after(() => Promise.all([aw.close(), st.close(), app.close()]))
aw.seed('websiteProjects', { $id: 'p_aktiv', customerId: 'c1', projectName: 'Aktiv', subdomain: 'aktiv', status: 'deployed' })
aw.seed('websiteProjects', { $id: 'p_archiv', customerId: 'c1', projectName: 'Alt', subdomain: 'alt', status: 'archived', archived: true })
const kunde = { cookie: sessionCookie({ customerId: 'c1', appwriteUserId: 'u1' }) }
const bearer = (jwt) => ({ headers: { Authorization: `Bearer ${jwt}` } })
test('Kundenportal: archivierte Projekte stehen nicht in der Liste', async () => {
const { projects } = await get('/api/projects', kunde)
assert.deepEqual(projects.map((p) => p.id), ['p_aktiv'])
})
test('Kundenportal: archiviertes Projekt auch per Direktaufruf nicht erreichbar', async () => {
assert.equal((await rawGet('/api/projects/p_archiv/work', kunde)).status, 404)
assert.equal((await rawGet('/api/projects/p_aktiv/work', kunde)).status, 200)
})
test('Projekt-Routen: Mitarbeiter ohne Admin-Label kommen rein, Kunden-Konto nicht', async () => {
assert.equal((await rawGet('/api/admin/services', bearer('jwt-staff'))).status, 200)
assert.equal((await rawGet('/api/admin/services', bearer('jwt-admin'))).status, 200)
const kundeKonto = await rawGet('/api/admin/services', bearer('jwt-kunde'))
assert.equal(kundeKonto.status, 403)
assert.equal(kundeKonto.body.error, 'Nur für Mitarbeiter')
assert.equal((await rawGet('/api/admin/services')).status, 401)
})
test('Kunden-Verwaltung bleibt nur fuer Admins', async () => {
const r = await rawGet('/api/admin/customers', bearer('jwt-staff'))
assert.equal(r.status, 403)
assert.equal(r.body.error, 'Admin-Berechtigung erforderlich')
})
test('Funktionen: Kunde sieht archivierte Projekte nicht, die Mitarbeiter-Ansicht schon', async () => {
const { listCustomerFeatures } = await import('../server/services/siteFeatures.js')
assert.deepEqual((await listCustomerFeatures('c1', { docs: [] })).map((p) => p.projectId), ['p_aktiv'])
assert.deepEqual(
(await listCustomerFeatures('c1', { docs: [], includeArchived: true })).map((p) => p.projectId).sort(),
['p_aktiv', 'p_archiv']
)
})
test('Funktionen: archiviertes Projekt mit laufender Funktion bleibt fuer den Kunden sichtbar (Buchungen verwalten)', async () => {
const { listCustomerFeatures } = await import('../server/services/siteFeatures.js')
const docs = [{ customerId: 'c1', projectId: 'p_archiv', featureKey: 'termine', state: 'active' }]
assert.deepEqual((await listCustomerFeatures('c1', { docs })).map((p) => p.projectId).sort(), ['p_aktiv', 'p_archiv'])
const aus = [{ customerId: 'c1', projectId: 'p_archiv', featureKey: 'termine', state: 'off' }]
assert.deepEqual((await listCustomerFeatures('c1', { docs: aus })).map((p) => p.projectId), ['p_aktiv'])
})
test('Neu bestellen auf archiviertem Projekt geht nicht', async () => {
const r = await send('POST', '/api/funktionen/news/checkout', { ...kunde, body: { projectId: 'p_archiv', consent: true } })
assert.equal(r.status, 409)
assert.match(r.body.error, /archiviert/)
})
test('Vorlage bleibt Admin-Sache; README nur fuer bekannte Projekte', async () => {
const t = await send('PATCH', '/api/admin/website-projects/p_aktiv', { ...bearer('jwt-staff'), body: { projectType: 'template' } })
assert.equal(t.status, 403)
const fremd = await rawGet('/api/admin/gitea/repo-readme?repoFullName=JUSN/tickte-system', bearer('jwt-staff'))
assert.equal(fremd.status, 404)
})