mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 23:11:12 -05:00
Implement superuser lock management
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user