Analyse: Routen fuer Portal und WOMS

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-01 10:19:37 +00:00
1 parent 696f17b470
commit f4c8b291d7
7 files changed
+416 -16

No files matched your search

+3 -1
View File
@@ -183,12 +183,14 @@ export async function activateAnalyse({ customerId, projectId, accentColor, cons
})
}
export async function deactivateAnalyse({ customerId, projectId, now = new Date() }) {
export async function deactivateAnalyse({ customerId, projectId, now = new Date(), by = 'customer' }) {
return withLocks([`analyse:${projectId}`], async () => {
const project = await loadOwnProject(customerId, projectId)
if (!project) throw httpError(403, ELIGIBILITY_MESSAGES.nicht_dein_projekt)
const existing = await getFeatureDoc(customerId, projectId, FEATURE_KEY)
if (!existing || existing.state === 'off') return { doc: existing, changed: false }
// Von uns gesperrt: der Kunde darf daran nichts aendern (nur Mitarbeiter)
if (existing.state === 'disabled' && by === 'customer') return { doc: existing, changed: false }
if (existing.siteKey) {
await analyseDeps.client.putSite(existing.siteKey, { projectId, domains: analyseDomains(project), active: false })
}
+1 -12
View File
@@ -4,7 +4,6 @@ import { config } from '../config.js'
import { deleteDocument, getDocument, listDocuments, Query } from './appwriteAdmin.js'
import { deleteNewsImage } from './newsImages.js'
import { disable } from './siteFeatures.js'
import { analyseDeps, analyseDomains } from './analyse.js'
import { getStripe } from './stripeBilling.js'
import { filesOf, STATUS } from './takeoverCredits.js'
@@ -220,18 +219,8 @@ export async function applyDeletions(plan) {
}
for (const id of entry.featureIds) {
const off = await attempt('portalFeatures', id, async () => {
const feature = await getDocument(FEATURES(), id).catch(() => null)
// disable() meldet bei Analyse auch den Sammeldienst ab (best effort)
await disable(id, { adminNote: 'Abgeschaltet: Aufbewahrungsfrist abgelaufen' })
// Analyse: auch den Sammeldienst abschalten (best effort, die Daten loescht dessen 60-Tage-Job)
if (feature?.featureKey === 'analyse' && feature.siteKey) {
try {
// der Sammeldienst verlangt mindestens eine Domain, auch beim Abschalten
const project = await getDocument(config.collections.websiteProjects, feature.projectId)
await analyseDeps.client.putSite(feature.siteKey, { projectId: feature.projectId, domains: analyseDomains(project), active: false })
} catch (err) {
console.warn(`[retention] Sammeldienst für Analyse ${id} nicht abgeschaltet:`, err.message)
}
}
return true
})
if (off) deleted.features += 1
+15 -1
View File
@@ -293,11 +293,25 @@ export async function activate(docId, { by, adminNote } = {}) {
export async function disable(docId, { by, adminNote } = {}) {
const note = adminNote ?? byNote(by, 'Abgeschaltet')
return updateDocument(config.collections.portalFeatures, docId, {
const doc = await updateDocument(config.collections.portalFeatures, docId, {
...stateFields('disabled'),
disabledAt: new Date().toISOString(),
...(note ? { adminNote: note } : {}),
})
if (doc?.featureKey === 'analyse' && doc.siteKey) await stopAnalyseCollecting(doc)
return doc
}
// Analyse gesperrt: Sammeldienst nimmt keine Daten mehr an. Best effort, Zustand ist schon gespeichert.
// Dynamischer Import: analyse.js importiert dieses Modul.
async function stopAnalyseCollecting(doc) {
try {
const { analyseDeps, analyseDomains } = await import('./analyse.js')
const project = await getDocument(config.collections.websiteProjects, doc.projectId)
await analyseDeps.client.putSite(doc.siteKey, { projectId: doc.projectId, domains: analyseDomains(project), active: false })
} catch (err) {
console.warn(`[siteFeatures] Sammeldienst für ${doc.projectId} nicht abgeschaltet:`, err.message)
}
}
/** Freischaltung ohne Zahlung und ohne Ticket (unlockedByPurchase bleibt false). */