@ -1,5 +1,7 @@
'use strict' ;
'use strict' ;
const validator = require ( 'validator' ) ;
const user = require ( '../user' ) ;
const user = require ( '../user' ) ;
const posts = require ( '../posts' ) ;
const posts = require ( '../posts' ) ;
const flags = require ( '../flags' ) ;
const flags = require ( '../flags' ) ;
@ -149,29 +151,25 @@ modsController.flags.detail = async function (req, res, next) {
} ;
} ;
modsController . postQueue = async function ( req , res , next ) {
modsController . postQueue = async function ( req , res , next ) {
// Admins, global mods, and individual mods only
if ( ! req . loggedIn ) {
const isPrivileged = await user . isPrivileged ( req . uid ) ;
if ( ! isPrivileged ) {
return next ( ) ;
return next ( ) ;
}
}
const { id } = req . params ;
const { cid } = req . query ;
const { cid } = req . query ;
const page = parseInt ( req . query . page , 10 ) || 1 ;
const page = parseInt ( req . query . page , 10 ) || 1 ;
const postsPerPage = 20 ;
const postsPerPage = 20 ;
let postData = await posts . getQueuedPosts ( ) ;
let postData = await posts . getQueuedPosts ( { id : id } ) ;
const [ isAdminOrGlobalMod , moderatedCids , categoriesData ] = await Promise . all ( [
const [ isAdmin , isGlobalMod , moderatedCids , categoriesData ] = await Promise . all ( [
user . isAdminOrGlobalMod ( req . uid ) ,
user . isAdministrator ( req . uid ) ,
user . isGlobalModerator ( req . uid ) ,
user . getModeratedCids ( req . uid ) ,
user . getModeratedCids ( req . uid ) ,
helpers . getSelectedCategory ( cid ) ,
helpers . getSelectedCategory ( cid ) ,
] ) ;
] ) ;
if ( cid && ! moderatedCids . includes ( Number ( cid ) ) && ! isAdminOrGlobalMod ) {
return next ( ) ;
}
postData = postData . filter ( p => p &&
postData = postData . filter ( p => p &&
( ! categoriesData . selectedCids . length || categoriesData . selectedCids . includes ( p . category . cid ) ) &&
( ! categoriesData . selectedCids . length || categoriesData . selectedCids . includes ( p . category . cid ) ) &&
( isAdmin Or GlobalMod || moderatedCids . includes ( Number ( p . category . cid ) ) ) ) ;
( isAdmin || isGlobalMod || moderatedCids . includes ( Number ( p . category . cid ) ) || req . uid === p . user . uid ) ) ;
( { posts : postData } = await plugins . hooks . fire ( 'filter:post-queue.get' , {
( { posts : postData } = await plugins . hooks . fire ( 'filter:post-queue.get' , {
posts : postData ,
posts : postData ,
@ -182,13 +180,19 @@ modsController.postQueue = async function (req, res, next) {
const start = ( page - 1 ) * postsPerPage ;
const start = ( page - 1 ) * postsPerPage ;
const stop = start + postsPerPage - 1 ;
const stop = start + postsPerPage - 1 ;
postData = postData . slice ( start , stop + 1 ) ;
postData = postData . slice ( start , stop + 1 ) ;
const crumbs = [ { text : '[[pages:post-queue]]' , url : id ? '/post-queue' : undefined } ] ;
if ( id && postData . length ) {
const text = postData [ 0 ] . data . tid ? '[[post-queue:reply]]' : '[[post-queue:topic]]' ;
crumbs . push ( { text : text } ) ;
}
res . render ( 'post-queue' , {
res . render ( 'post-queue' , {
title : '[[pages:post-queue]]' ,
title : '[[pages:post-queue]]' ,
posts : postData ,
posts : postData ,
isAdmin : isAdmin ,
canAccept : isAdmin || isGlobalMod || ! ! moderatedCids . length ,
... categoriesData ,
... categoriesData ,
allCategoriesUrl : ` post-queue ${ helpers . buildQueryString ( req . query , 'cid' , '' ) } ` ,
allCategoriesUrl : ` post-queue ${ helpers . buildQueryString ( req . query , 'cid' , '' ) } ` ,
pagination : pagination . create ( page , pageCount ) ,
pagination : pagination . create ( page , pageCount ) ,
breadcrumbs : helpers . buildBreadcrumbs ( [ { text : '[[pages:post-queue]]' } ] ) ,
breadcrumbs : helpers . buildBreadcrumbs ( crumbs ) ,
} ) ;
} ) ;
} ;
} ;