Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* `dsgvo reactivate --user <id>` — cancel a pending deletion. Clears
|
||||
* User.pendingDeletion + scheduledDeletionAt + deletionRequestedAt +
|
||||
* deletionRequestId and writes a CANCEL_USER_DELETION audit row.
|
||||
*
|
||||
* Fails (exit 1) if the user is not currently pendingDeletion=true.
|
||||
*/
|
||||
import { defineCommand } from "citty";
|
||||
import consola from "consola";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
export const dsgvoReactivateCommand = defineCommand({
|
||||
meta: { name: "reactivate", description: "Cancel a pending user deletion." },
|
||||
args: {
|
||||
user: { type: "string", required: true, description: "Target User.id." },
|
||||
tenant: { type: "string", required: false, description: "Tenant id stamped on the audit row." },
|
||||
actor: { type: "string", required: false, description: "Operator id stamped on the audit row." },
|
||||
},
|
||||
async run({ args }) {
|
||||
const userId = String(args.user);
|
||||
const tenantId = args.tenant ? String(args.tenant) : null;
|
||||
const actorId = args.actor ? String(args.actor) : "cli-operator";
|
||||
const requestId = randomUUID();
|
||||
|
||||
const [{ getDbClient }, { createAuditEvent }] = await Promise.all([
|
||||
import("@toolctrl/db/client.server"),
|
||||
import("@toolctrl/db/audit-events.server"),
|
||||
]);
|
||||
const prisma = getDbClient();
|
||||
const existing = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { pendingDeletion: true },
|
||||
});
|
||||
if (!existing) {
|
||||
consola.error(`User ${userId} not found.`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
if (!existing.pendingDeletion) {
|
||||
consola.warn(`User ${userId} is not pendingDeletion; nothing to do.`);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
await prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
pendingDeletion: false,
|
||||
deletionRequestedAt: null,
|
||||
scheduledDeletionAt: null,
|
||||
deletionRequestId: null,
|
||||
},
|
||||
});
|
||||
await createAuditEvent({
|
||||
tenantId,
|
||||
actorId,
|
||||
actorType: "admin",
|
||||
action: "CANCEL_USER_DELETION",
|
||||
targetType: "User",
|
||||
targetId: userId,
|
||||
regulatoryScope: ["gdpr"],
|
||||
dataSensitivity: "pii",
|
||||
outcome: "success",
|
||||
metadata: { requestId, intent: "reactivate", source: "cli" },
|
||||
});
|
||||
consola.success(`User ${userId} reactivated. requestId=${requestId}`);
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user