Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+28
-2
@@ -1,11 +1,31 @@
|
||||
import { TenantUserStatus } from "~/application/enums/tenants/TenantUserStatus";
|
||||
import { TenantUserType } from "~/application/enums/tenants/TenantUserType";
|
||||
import { publishTenantUserSearchUpsert } from "~/services/search/searchIndexProjection.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
|
||||
// R-P2b — User-Lifecycle: Soft-Deaktivierung mit Last-Admin-Guard + optionalem Ownership-Reassign.
|
||||
// Ein Tenant muss IMMER mindestens einen aktiven Owner/Admin behalten, sonst waere er handlungsunfaehig.
|
||||
|
||||
const PRIVILEGED_TYPES = [TenantUserType.OWNER, TenantUserType.ADMIN];
|
||||
const tenantUserSearchInclude = {
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
createdAt: true,
|
||||
email: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
active: true,
|
||||
admin: { select: { userId: true } },
|
||||
logs: {
|
||||
where: { action: "Login" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
take: 1,
|
||||
select: { createdAt: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export type DeactivateTenantUserResult =
|
||||
| { ok: true }
|
||||
@@ -70,7 +90,10 @@ export async function deactivateTenantUser({
|
||||
if (reassignToUserId && reassignToUserId !== targetUserId) {
|
||||
await reassignTenantUserOwnership({ tenantId, fromUserId: targetUserId, toUserId: reassignToUserId });
|
||||
}
|
||||
await db.tenantUser.update({ where: { id: member.id }, data: { status: TenantUserStatus.INACTIVE } });
|
||||
await db.$transaction(async (tx) => {
|
||||
const updated = await tx.tenantUser.update({ where: { id: member.id }, data: { status: TenantUserStatus.INACTIVE }, include: tenantUserSearchInclude });
|
||||
await publishTenantUserSearchUpsert(tx, updated);
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -91,6 +114,9 @@ export async function reactivateTenantUser({
|
||||
if (member.status === TenantUserStatus.ACTIVE) {
|
||||
return { ok: false, reason: "already-active" };
|
||||
}
|
||||
await db.tenantUser.update({ where: { id: member.id }, data: { status: TenantUserStatus.ACTIVE } });
|
||||
await db.$transaction(async (tx) => {
|
||||
const updated = await tx.tenantUser.update({ where: { id: member.id }, data: { status: TenantUserStatus.ACTIVE }, include: tenantUserSearchInclude });
|
||||
await publishTenantUserSearchUpsert(tx, updated);
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
Reference in new issue
Block a user