Files
overleaf-cep/services/web/modules/template-gallery/index.mjs
yu-i-i 976716f607 Template gallery: add template management authorization middleware
- Middleware to enforce template access rules
- Introduce template manager role
- Fix minor issues
2026-05-19 15:51:35 +02:00

44 lines
1.3 KiB
JavaScript

import Settings from '@overleaf/settings'
import TemplateGalleryRouter from './app/src/TemplateGalleryRouter.mjs'
function boolFromEnv(env) {
if (env === undefined || env === null) return undefined
if (typeof env === "string") {
const envLower = env.toLowerCase()
if (envLower === 'true') return true
if (envLower === 'false') return false
}
throw new Error("Invalid value for boolean environment variable")
}
let TemplateGalleryModule = {}
if (process.env.OVERLEAF_TEMPLATE_GALLERY === 'true') {
TemplateGalleryModule = {
router: TemplateGalleryRouter,
}
Settings.templates = {
nonAdminCanManage: boolFromEnv(process.env.OVERLEAF_NON_ADMIN_CAN_PUBLISH_TEMPLATES),
user_id: process.env.OVERLEAF_TEMPLATES_USER_ID
}
const templateKeys = process.env.OVERLEAF_TEMPLATE_CATEGORIES
? process.env.OVERLEAF_TEMPLATE_CATEGORIES + ' all'
: 'all'
Settings.templateLinks = templateKeys.split(/\s+/).map(key => {
const envKeyBase = key.toUpperCase().replace(/-/g, "_")
const name = process.env[`TEMPLATE_${envKeyBase}_NAME`] || ( key === 'all' ? 'All templates' : key)
const description = process.env[`TEMPLATE_${envKeyBase}_DESCRIPTION`] || ''
return {
name,
url: `/templates/${key}`,
description
}
})
}
export default TemplateGalleryModule