fix(housekeeping): release authority lock before activity
This commit is contained in:
1 parent
8a894617e7
commit
54f0345aac
3 files changed
+166
-41
No files matched your search
@@ -435,8 +435,10 @@ async function runWithLockedTargetAuthority(
|
||||
userId: number,
|
||||
context: PeopleMutationContext,
|
||||
execute: () => Promise<void>,
|
||||
afterRelease?: () => Promise<void>,
|
||||
): Promise<void> {
|
||||
let externalCompleted = false;
|
||||
let completedFailure: CompletedExternalEffectFailure | undefined;
|
||||
try {
|
||||
await db.transaction(async (tx) => {
|
||||
await loadTarget(userId, context, true, tx, true);
|
||||
@@ -444,9 +446,15 @@ async function runWithLockedTargetAuthority(
|
||||
externalCompleted = true;
|
||||
});
|
||||
} catch (error) {
|
||||
if (externalCompleted) throw new CompletedExternalEffectFailure(error);
|
||||
throw error;
|
||||
if (!externalCompleted) throw error;
|
||||
completedFailure = new CompletedExternalEffectFailure(error);
|
||||
}
|
||||
try {
|
||||
await afterRelease?.();
|
||||
} catch (error) {
|
||||
completedFailure ??= new CompletedExternalEffectFailure(error);
|
||||
}
|
||||
if (completedFailure) throw completedFailure;
|
||||
}
|
||||
|
||||
async function assertBulkTargetHierarchy(
|
||||
@@ -1247,29 +1255,36 @@ async function executeUserMutation(
|
||||
userId,
|
||||
snapshot,
|
||||
() =>
|
||||
runWithLockedTargetAuthority(userId, context, async () => {
|
||||
await requireRcon(await rcon.setTradeLock(userId, locked));
|
||||
await requireRcon(
|
||||
await rcon.alertUser(
|
||||
userId,
|
||||
locked
|
||||
? "Trading has been disabled by staff."
|
||||
: "Trading has been re-enabled by staff.",
|
||||
),
|
||||
);
|
||||
if (target.online === "1") {
|
||||
await requireRcon(await rcon.disconnectUser(userId, target.username));
|
||||
}
|
||||
await logStaffActivity({
|
||||
staffId: context.capability.actor.id,
|
||||
action: locked ? "trade_lock" : "trade_unlock",
|
||||
description: locked
|
||||
? `Trade-locked ${target.username} (#${userId}) until ${untilUnix}`
|
||||
: `Cleared trade lock for ${target.username} (#${userId})`,
|
||||
targetType: "user",
|
||||
targetId: userId,
|
||||
});
|
||||
}),
|
||||
runWithLockedTargetAuthority(
|
||||
userId,
|
||||
context,
|
||||
async () => {
|
||||
await requireRcon(await rcon.setTradeLock(userId, locked));
|
||||
await requireRcon(
|
||||
await rcon.alertUser(
|
||||
userId,
|
||||
locked
|
||||
? "Trading has been disabled by staff."
|
||||
: "Trading has been re-enabled by staff.",
|
||||
),
|
||||
);
|
||||
if (target.online === "1") {
|
||||
await requireRcon(
|
||||
await rcon.disconnectUser(userId, target.username),
|
||||
);
|
||||
}
|
||||
},
|
||||
() =>
|
||||
logStaffActivity({
|
||||
staffId: context.capability.actor.id,
|
||||
action: locked ? "trade_lock" : "trade_unlock",
|
||||
description: locked
|
||||
? `Trade-locked ${target.username} (#${userId}) until ${untilUnix}`
|
||||
: `Cleared trade lock for ${target.username} (#${userId})`,
|
||||
targetType: "user",
|
||||
targetId: userId,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
async function executeBulkMutation(
|
||||
|
||||
Reference in new issue
Block a user