Implement superuser lock management

This commit is contained in:
gpt-engineer-app[bot]
2025-11-04 23:08:00 +00:00
parent ae22a48ce2
commit 16386f9894
7 changed files with 412 additions and 26 deletions

View File

@@ -494,6 +494,85 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
}
}, [currentLock, releaseLock]);
// Superuser: Force release a specific lock
const superuserReleaseLock = useCallback(async (
submissionId: string
): Promise<boolean> => {
if (!user?.id) return false;
setIsLoading(true);
try {
const { data, error } = await supabase.rpc('superuser_release_lock', {
p_submission_id: submissionId,
p_superuser_id: user.id,
});
if (error) throw error;
toast({
title: 'Lock Forcibly Released',
description: 'The submission has been unlocked and is now available',
});
fetchStats();
if (onLockStateChange) {
onLockStateChange();
}
return data;
} catch (error: unknown) {
toast({
title: 'Failed to Release Lock',
description: getErrorMessage(error),
variant: 'destructive',
});
return false;
} finally {
setIsLoading(false);
}
}, [user, fetchStats, toast, onLockStateChange]);
// Superuser: Clear all locks
const superuserReleaseAllLocks = useCallback(async (): Promise<number> => {
if (!user?.id) return 0;
setIsLoading(true);
try {
const { data, error } = await supabase.rpc('superuser_release_all_locks', {
p_superuser_id: user.id,
});
if (error) throw error;
const count = data || 0;
toast({
title: 'All Locks Cleared',
description: `${count} submission${count !== 1 ? 's' : ''} unlocked`,
});
fetchStats();
if (onLockStateChange) {
onLockStateChange();
}
return count;
} catch (error: unknown) {
toast({
title: 'Failed to Clear Locks',
description: getErrorMessage(error),
variant: 'destructive',
});
return 0;
} finally {
setIsLoading(false);
}
}, [user, fetchStats, toast, onLockStateChange]);
return {
currentLock, // Exposed for reactive UI updates
queueStats,
@@ -510,6 +589,9 @@ export const useModerationQueue = (config?: UseModerationQueueConfig) => {
isLockedByOther,
getLockProgress,
releaseAfterAction,
// Superuser lock management
superuserReleaseLock,
superuserReleaseAllLocks,
};
};