Fix magic numbers in item update logic

This commit is contained in:
ekzyis 2023-10-13 22:27:27 +02:00
parent 8ace053be5
commit 78745379aa
2 changed files with 9 additions and 3 deletions

View File

@ -7,7 +7,8 @@ import domino from 'domino'
import {
ITEM_SPAM_INTERVAL, ITEM_FILTER_THRESHOLD,
DONT_LIKE_THIS_COST, COMMENT_DEPTH_LIMIT, COMMENT_TYPE_QUERY,
ANON_COMMENT_FEE, ANON_USER_ID, ANON_POST_FEE, ANON_ITEM_SPAM_INTERVAL, POLL_COST
ANON_COMMENT_FEE, ANON_USER_ID, ANON_POST_FEE, ANON_ITEM_SPAM_INTERVAL, POLL_COST,
ITEM_ALLOW_EDITS
} from '../../lib/constants'
import { msatsToSats } from '../../lib/format'
import { parse } from 'tldts'
@ -1011,9 +1012,9 @@ export const updateItem = async (parent, { sub: subName, forward, options, ...it
// in case they lied about their existing boost
await ssValidate(advSchema, { boost: item.boost }, { models, me, existingBoost: old.boost })
// if it's not the FAQ, not their bio, and older than 10 minutes
// prevent update if it's not explicitly allowed, not their bio, not their job and older than 10 minutes
const user = await models.user.findUnique({ where: { id: me.id } })
if (![349, 76894, 78763, 81862].includes(old.id) && user.bioId !== old.id &&
if (!ITEM_ALLOW_EDITS.includes(old.id) && user.bioId !== old.id &&
typeof item.maxBid === 'undefined' && Date.now() > new Date(old.createdAt).getTime() + 10 * 60000) {
throw new GraphQLError('item can no longer be editted', { extensions: { code: 'BAD_INPUT' } })
}

View File

@ -69,3 +69,8 @@ export const LOST_BLURBS = [
"your hat was stolen by a mischievous prairie dog. You won't catch the dog, but you can always find another hat.",
'you lost your hat while crossing the river on your journey west. Maybe you can find a replacement hat in the next town.'
]
export const ITEM_ALLOW_EDITS = [
// FAQ, privacy policy, changelog, content guidelines
349, 76894, 78763, 81862
]