You've already forked AstralRinth
forked from didirus/AstralRinth
feat: moderation locking (#5070)
* feat: base locking impl * feat: lock logic in place in rev endpoint + fetch rev * feat: frontend impl and finalize * feat: auto skip if using the moderation queue page * fix: qa issues * fix: async state + locking fix * fix: lint * fix: fmt * fix: qa issue * fix: qa + redirect bug * fix: lint * feat: delete all locks endpoint for admins * fix: dedupe * fix: fmt * fix: project redirect move to middleware * fix: lint
This commit is contained in:
@@ -9,6 +9,26 @@ export interface ModerationQueue {
|
||||
lastUpdated: Date
|
||||
}
|
||||
|
||||
export interface LockedByUser {
|
||||
id: string
|
||||
username: string
|
||||
avatar_url?: string
|
||||
}
|
||||
|
||||
export interface LockStatusResponse {
|
||||
locked: boolean
|
||||
locked_by?: LockedByUser
|
||||
locked_at?: string
|
||||
expired?: boolean
|
||||
}
|
||||
|
||||
export interface LockAcquireResponse {
|
||||
success: boolean
|
||||
locked_by?: LockedByUser
|
||||
locked_at?: string
|
||||
expired?: boolean
|
||||
}
|
||||
|
||||
const EMPTY_QUEUE: Partial<ModerationQueue> = {
|
||||
items: [],
|
||||
|
||||
@@ -28,6 +48,8 @@ pinia.use(piniaPluginPersistedstate)
|
||||
export const useModerationStore = defineStore('moderation', {
|
||||
state: () => ({
|
||||
currentQueue: createEmptyQueue(),
|
||||
currentLock: null as { projectId: string; lockedAt: Date } | null,
|
||||
isQueueMode: false,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
@@ -41,6 +63,7 @@ export const useModerationStore = defineStore('moderation', {
|
||||
|
||||
actions: {
|
||||
setQueue(projectIDs: string[]) {
|
||||
this.isQueueMode = true
|
||||
this.currentQueue = {
|
||||
items: [...projectIDs],
|
||||
total: projectIDs.length,
|
||||
@@ -51,6 +74,7 @@ export const useModerationStore = defineStore('moderation', {
|
||||
},
|
||||
|
||||
setSingleProject(projectId: string) {
|
||||
this.isQueueMode = false
|
||||
this.currentQueue = {
|
||||
items: [projectId],
|
||||
total: 1,
|
||||
@@ -78,8 +102,71 @@ export const useModerationStore = defineStore('moderation', {
|
||||
},
|
||||
|
||||
resetQueue() {
|
||||
this.isQueueMode = false
|
||||
this.currentQueue = createEmptyQueue()
|
||||
},
|
||||
|
||||
async acquireLock(projectId: string): Promise<LockAcquireResponse> {
|
||||
try {
|
||||
const response = (await useBaseFetch(`moderation/lock/${projectId}`, {
|
||||
method: 'POST',
|
||||
internal: true,
|
||||
})) as LockAcquireResponse
|
||||
|
||||
if (response.success) {
|
||||
this.currentLock = { projectId, lockedAt: new Date() }
|
||||
}
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
console.error('Failed to acquire moderation lock:', error)
|
||||
// Return a failed response so the UI can handle it gracefully
|
||||
return { success: false }
|
||||
}
|
||||
},
|
||||
|
||||
async releaseLock(projectId: string): Promise<boolean> {
|
||||
try {
|
||||
const response = (await useBaseFetch(`moderation/lock/${projectId}`, {
|
||||
method: 'DELETE',
|
||||
internal: true,
|
||||
})) as { success: boolean }
|
||||
|
||||
if (this.currentLock?.projectId === projectId) {
|
||||
this.currentLock = null
|
||||
}
|
||||
|
||||
return response.success
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
async checkLock(projectId: string): Promise<LockStatusResponse> {
|
||||
try {
|
||||
const response = (await useBaseFetch(`moderation/lock/${projectId}`, {
|
||||
method: 'GET',
|
||||
internal: true,
|
||||
})) as LockStatusResponse
|
||||
return response
|
||||
} catch (error) {
|
||||
console.error('Failed to check moderation lock:', error)
|
||||
// Return unlocked status on error so moderation can proceed
|
||||
return { locked: false }
|
||||
}
|
||||
},
|
||||
|
||||
async refreshLock(): Promise<boolean> {
|
||||
if (!this.currentLock) return false
|
||||
|
||||
try {
|
||||
const response = await this.acquireLock(this.currentLock.projectId)
|
||||
return response.success
|
||||
} catch (error) {
|
||||
console.error('Failed to refresh moderation lock:', error)
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
persist: {
|
||||
|
||||
Reference in New Issue
Block a user