Skip to content
2 changes: 1 addition & 1 deletion server/data/cleanup-documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function cleanupOrphanDocuments (dbPool, logger) {
.where({ content_hash: contentHash })
.count('* as count')

if (count === 0) {
if (Number(count) === 0) {
// Content has no more references - delete file and content record
const [content] = await dbPool('bm_web_document_contents')
.where({ content_hash: contentHash })
Expand Down
2 changes: 1 addition & 1 deletion server/graphql/resolvers/mutations/delete-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = async function deleteDocument (obj, { id }, { log, session, sta
.where({ content_hash: contentHash })
.count('* as count')

if (count === 0) {
if (Number(count) === 0) {
// No more references - delete content record and file
const relativePath = document.path.replace('uploads/documents/', '').split('/').join(path.sep)
const fullPath = path.join(UPLOAD_PATH, relativePath)
Expand Down
2 changes: 1 addition & 1 deletion server/graphql/resolvers/scalars/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
.select('a.id as appeal_id', 'a.server_id', 'ad.comment_id')

for (const link of appealLinks) {
if (link.comment_id === 0) {
if (Number(link.comment_id) === 0) {
usages.push({
type: 'appeal',
id: String(link.appeal_id),
Expand Down
2 changes: 1 addition & 1 deletion server/routes/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function documentsRoute (dbPool) {
}

// If attached to a comment, also check view.comments permission
if (appealDoc.comment_id !== 0) {
if (Number(appealDoc.comment_id) !== 0) {
const canViewComments = acl.hasServerPermission(appeal.server_id, 'player.appeals', 'view.comments')
if (!canViewComments) {
ctx.status = 403
Expand Down
2 changes: 1 addition & 1 deletion server/routes/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
.first()
let successful = false

if (result) {
if (result && result.password) {

Check warning on line 87 in server/routes/session.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=BanManagement_BanManager-WebUI&issues=AZ-w6oUaKElHIHuLuJBM&open=AZ-w6oUaKElHIHuLuJBM&pullRequest=1842
const match = await verify(result.password, request.body.password)

if (match) successful = true
Expand Down
25 changes: 21 additions & 4 deletions server/routes/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ module.exports = function uploadRoute (dbPool) {
}

// Check rate limit (skip for users with bypass permission)
const canBypassRateLimit = acl.hasPermission('player.appeals', 'attachment.ratelimit.bypass') ||
acl.hasPermission('player.reports', 'attachment.ratelimit.bypass')
let canBypassRateLimit = acl.hasPermission('player.appeals', 'attachment.ratelimit.bypass') ||
acl.hasPermission('player.reports', 'attachment.ratelimit.bypass')

if (!canBypassRateLimit) {
for (const server of ctx.state.serversPool.keys()) {
if (acl.hasServerPermission(server, 'player.appeals', 'attachment.ratelimit.bypass') ||
acl.hasServerPermission(server, 'player.reports', 'attachment.ratelimit.bypass')) {
canBypassRateLimit = true
break
}
}
}

if (!canBypassRateLimit) {
const ipAddr = requestIp.getClientIp(ctx.request)
Expand All @@ -75,8 +85,15 @@ module.exports = function uploadRoute (dbPool) {
}

// Check if user has attachment.create permission for appeals OR reports
const hasAppealsPermission = acl.hasPermission('player.appeals', 'attachment.create')
const hasReportsPermission = acl.hasPermission('player.reports', 'attachment.create')
let hasAppealsPermission = acl.hasPermission('player.appeals', 'attachment.create')
let hasReportsPermission = acl.hasPermission('player.reports', 'attachment.create')

if (!hasAppealsPermission && !hasReportsPermission) {
for (const server of ctx.state.serversPool.keys()) {
if (acl.hasServerPermission(server, 'player.appeals', 'attachment.create')) hasAppealsPermission = true
if (acl.hasServerPermission(server, 'player.reports', 'attachment.create')) hasReportsPermission = true
}
}

if (!hasAppealsPermission && !hasReportsPermission) {
ctx.status = 403
Expand Down
Loading