Skip to content

Conversation

@Musicminion
Copy link
Member

@Musicminion Musicminion commented Jan 29, 2026

In this pr we will Introduce Template Manage to Overleaf-Pro #6 (from CEP)

  • filestore, add a DEL router for delete templates files
  • modules/template: add templates system for overleaf

Todo

  • Translation update. We don't want to change i18 files, so we should keep them English.
  • Add submit botton for new-designed Editor
  • Test on Cloud Environment
  • Add document on overleaf-pro.ayaka.space

Description

Related issues / Pull Requests

Contributor Agreement

- filestore, add a DEL router for delete templates files
- modules/template: add templates system for overleaf
- Todo: translation update. We don't want to change i18 files, so we should keep them English.
@Musicminion
Copy link
Member Author

Musicminion commented Jan 29, 2026

Just wait before auto CI finished.

@Musicminion Musicminion self-assigned this Jan 29, 2026
@Musicminion
Copy link
Member Author

We have intergrated all template system files in webmodules, without any any other files. Also we add a public download router, from which we can download zip templates from overleaf pro cloud system.

Next, we need to finish some i18 chores, we want to remove no needed i18 UI, for we want to keep it simple for i18 resource translations update from upstream in the future.

@Musicminion
Copy link
Member Author

Musicminion commented Jan 30, 2026

Just fixed Manage Template display in new Editor.

image

@Musicminion
Copy link
Member Author

@codex

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0bbe53fdf3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +48 to +50
async function deleteTemplate({ templateId, version }) {
await deleteTemplateAssets(templateId, version, true)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce ownership/admin check before deleting templates

Deletion also accepts only templateId/version and performs the delete without any ownership/admin verification. Combined with the route’s login-only guard, any authenticated user can delete any template if they know the id. Please check that the requester is the owner or an admin before calling deleteTemplateAssets.

Useful? React with 👍 / 👎.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 72 to 76
try {
userIsAdmin = (await UserGetter.promises.getUser(userId, { isAdmin: 1 })).isAdmin
} catch {
logger.error({ error, userId }, 'Logged in user does not exist, strange...')
userIsAdmin = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid ReferenceError in canUserOverrideTemplate catch

The catch { ... } block references error, but no binding is declared in the catch clause. In runtimes that support optional catch bindings, error will be undefined here, causing a ReferenceError and masking the original UserGetter failure. This means a missing user record will crash the override check instead of falling back to userIsAdmin = false.

Useful? React with 👍 / 👎.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@Musicminion
Copy link
Member Author

We still have some problems:

image

This is due to out-of-date extracted-translations.json, we need to manully updatet this is ci.

@Musicminion
Copy link
Member Author

Another problem: No search result should be replaced.

image

@ayaka-lab
Copy link
Contributor

I will do a check for buggy display in Menu (user setting/templates), I will test this on overleaf-v6.1.0 ce.

@ayaka-lab
Copy link
Contributor

Another problem: No search result should be replaced.

image

Fixed.

@ayaka-lab
Copy link
Contributor

We still have some problems:

image This is due to out-of-date `extracted-translations.json`, we need to manully updatet this is ci.

Fixed

- permission check while edit templates
- catch error in try block (TemplateGalleryHelper.mjs)
- some comments in router.js (templates)
@Musicminion
Copy link
Member Author

@codex please review again.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75417b3eb8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +8 to +10
async function ensureUserCanManageTemplates(req, res, next) {
const user = SessionManager.getSessionUser(req.session)
const userId = SessionManager.getLoggedInUserId(req.session)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Import SessionManager before using it

ensureUserCanManageTemplates calls SessionManager.getSessionUser/getLoggedInUserId, but SessionManager is never imported in this module. At runtime, any request that hits this middleware will throw a ReferenceError before the permission check runs, so template management endpoints will 500 for all users. Please add the missing import (or pass the session helper in) so the middleware can execute.

Useful? React with 👍 / 👎.

Comment on lines +112 to +116

req.requestLogger.addFields({ key, bucket })
req.requestLogger.setMessage('deleting file')

FileHandler.deleteFile(bucket, key, function (err) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid calling non-existent FileHandler.deleteFile

FileController.deleteFile invokes FileHandler.deleteFile, but FileHandler only exports insertFile, getFile, getRedirectUrl, and getFileSize (see services/filestore/app/js/FileHandler.js). Because deleteFile is not defined, the new DELETE endpoint will throw TypeError: FileHandler.deleteFile is not a function on every request. Add a delete implementation to FileHandler or call the correct helper to prevent the endpoint from crashing.

Useful? React with 👍 / 👎.

@ayaka-lab
Copy link
Contributor

@codex I have fixed, what about now?

@chatgpt-codex-connector
Copy link

To use Codex here, create a Codex account and connect to github.

@Musicminion
Copy link
Member Author

@codex, I have fixed, what about now?

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3fc26ee583

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +10 to +13
const user = SessionManager.getSessionUser(req.session)
const userId = SessionManager.getLoggedInUserId(req.session)
const isAdminOrTemplateOwner = hasAdminAccess(user) || Settings.templates?.user_id === userId

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor nonAdminCanManage in template permissions

The permissions check only allows admins or the configured Settings.templates.user_id. Because Settings.templates.nonAdminCanManage (set from OVERLEAF_NON_ADMIN_CAN_PUBLISH_TEMPLATES) is never consulted here, enabling that env flag still returns 403 for non‑admin users who should be allowed to manage templates. This makes the deployment toggle ineffective and blocks intended users.

Useful? React with 👍 / 👎.

Comment on lines +193 to +196
try {
await Template.deleteOne({ _id: templateId }).exec()
} catch (error) {
logger.error({ err, templateId }, 'Failed to delete template from MongoDB')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid ReferenceError when template delete fails

In the MongoDB delete error path, the logger references err, but the caught variable is error. If the delete fails (e.g., transient DB issue), this throws a ReferenceError and masks the real failure, returning an unexpected 500 instead of the underlying error. Logging error avoids introducing a new exception.

Useful? React with 👍 / 👎.

Comment on lines +18 to +21
export function updateTemplate({
editedTemplate,
template
}: UpdateTemplateOptions): Promise<Template | null> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Fix updateTemplate options type mismatch

updateTemplate destructures editedTemplate, but UpdateTemplateOptions does not define that property. This produces a TypeScript error at the function signature and makes it impossible for callers to satisfy the declared type, breaking builds that run type checking.

Useful? React with 👍 / 👎.

@ayaka-lab
Copy link
Contributor

ayaka-lab commented Jan 31, 2026

Ok, I will stop ask for codex, Now test with cloud VM.

We will get ready for Merge this feature!

@Musicminion Musicminion merged commit d57eee4 into server-pro Jan 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants