separated MAX_PINNED_POSTS from MAX_GROUP_PINNED_POSTS variable

This commit is contained in:
Ulf Gebhardt 2026-01-17 17:52:11 +01:00
parent 1111ccfe94
commit 39264177c0
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
6 changed files with 13 additions and 7 deletions

View File

@ -48,3 +48,4 @@ IMAGOR_SECRET=mysecret
CATEGORIES_ACTIVE=false
MAX_PINNED_POSTS=1
MAX_GROUP_PINNED_POSTS=1

View File

@ -40,3 +40,4 @@ IMAGOR_SECRET=mysecret
CATEGORIES_ACTIVE=false
MAX_PINNED_POSTS=1
MAX_GROUP_PINNED_POSTS=1

View File

@ -138,6 +138,9 @@ const options = {
MAX_PINNED_POSTS: Number.isNaN(Number(process.env.MAX_PINNED_POSTS))
? 1
: Number(process.env.MAX_PINNED_POSTS),
MAX_GROUP_PINNED_POSTS: Number.isNaN(Number(process.env.MAX_GROUP_PINNED_POSTS))
? 1
: Number(process.env.MAX_GROUP_PINNED_POSTS),
}
const language = {

View File

@ -211,7 +211,7 @@ describe('pin groupPosts', () => {
describe('MAX_GROUP_PINNED_POSTS is 1', () => {
beforeEach(async () => {
config = { ...defaultConfig, MAX_PINNED_POSTS: 1 }
config = { ...defaultConfig, MAX_GROUP_PINNED_POSTS: 1 }
authenticatedUser = await publicUser.toJson()
})
it('returns post-1-to-public-group as first, pinned post', async () => {
@ -297,7 +297,7 @@ describe('pin groupPosts', () => {
describe('MAX_GROUP_PINNED_POSTS is 2', () => {
beforeEach(async () => {
config = { ...defaultConfig, MAX_PINNED_POSTS: 2 }
config = { ...defaultConfig, MAX_GROUP_PINNED_POSTS: 2 }
authenticatedUser = await publicUser.toJson()
})
it('returns post-1-to-public-group as first, post-2-to-public-group as second pinned post', async () => {

View File

@ -474,12 +474,12 @@ export default {
}
const { config } = context
if (config.MAX_PINNED_POSTS === 0) {
if (config.MAX_GROUP_PINNED_POSTS === 0) {
throw new Error('Pinned posts are not allowed!')
}
// If MAX_PINNED_POSTS === 1 -> Delete old pin
if (config.MAX_PINNED_POSTS === 1) {
// If MAX_GROUP_PINNED_POSTS === 1 -> Delete old pin
if (config.MAX_GROUP_PINNED_POSTS === 1) {
await context.database.write({
query: `
MATCH (post:Post {id: $params.id})-[:IN]->(group:Group)
@ -488,7 +488,7 @@ export default {
DELETE pinned`,
variables: { user: context.user, params },
})
// If MAX_PINNED_POSTS !== 1 -> Check if max is reached
// If MAX_GROUP_PINNED_POSTS !== 1 -> Check if max is reached
} else {
const result = await context.database.query({
query: `
@ -497,7 +497,7 @@ export default {
RETURN toString(count(pinnedPosts)) as count`,
variables: { user: context.user, params },
})
if (result.records[0].get('count') >= config.MAX_PINNED_POSTS) {
if (result.records[0].get('count') >= config.MAX_GROUP_PINNED_POSTS) {
throw new Error('Reached maxed pinned posts already. Unpin a post first.')
}
}

View File

@ -57,6 +57,7 @@ export const TEST_CONFIG = {
INVITE_CODES_GROUP_PER_USER: 7,
CATEGORIES_ACTIVE: false,
MAX_PINNED_POSTS: 1,
MAX_GROUP_PINNED_POSTS: 1,
LANGUAGE_DEFAULT: 'en',
LOG_LEVEL: 'DEBUG',