From aabac2576cd822038e779c671f8bdca3c20ceea2 Mon Sep 17 00:00:00 2001 From: Tom Najdek Date: Tue, 27 Jan 2026 19:25:12 +0100 Subject: [PATCH] Ensure automatic file renaming is enabled for group libraries (#5750) --- chrome/content/zotero/renameFiles.mjs | 4 ++-- chrome/content/zotero/xpcom/attachments.js | 23 +++++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/renameFiles.mjs b/chrome/content/zotero/renameFiles.mjs index 1a15cd1fb5..f5cbd737d1 100644 --- a/chrome/content/zotero/renameFiles.mjs +++ b/chrome/content/zotero/renameFiles.mjs @@ -76,8 +76,8 @@ export async function renameFilesFromParent({ userLibrary = true, groupLibrary = let shouldRename = userLibrary && library.libraryType === 'user'; if (!shouldRename) { - // for group libraries, check `autoRenameFiles` synced setting - shouldRename = groupLibrary && Zotero.SyncedSettings.get(library.libraryID, 'autoRenameFiles'); + // for group libraries, this checks `autoRenameFiles` synced setting + shouldRename = groupLibrary && Zotero.Attachments.isAutoRenameFilesEnabledForLibrary(library.libraryID); } if (shouldRename) { diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index c24433a499..14dc4624af 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -2640,16 +2640,29 @@ Zotero.Attachments = new function () { return ext; }; + this.isAutoRenameFilesEnabledForLibrary = function (libraryID) { + // For user library, check preference + if (libraryID === Zotero.Libraries.userLibraryID) { + return Zotero.Prefs.get('autoRenameFiles'); + } + // For other libraries, check synced setting + const syncedSettingValue = Zotero.SyncedSettings.get(libraryID, 'autoRenameFiles'); + + // To preserve automatic file renaming ON by default in 8.0, where it is controlled by a synced setting, return true if the synced setting is unset + if (syncedSettingValue === null) { + return true; + } + + return syncedSettingValue; + }; + this.shouldAutoRenameFile = function (isLink, libraryID = null) { if (libraryID === null) { Zotero.debug('Calling Zotero.Attachments.shouldAutoRenameFile without a libraryID is deprecated. Assuming user library.'); libraryID = Zotero.Libraries.userLibraryID; } - if (libraryID === Zotero.Libraries.userLibraryID && !Zotero.Prefs.get('autoRenameFiles')) { - return false; - } - - if (libraryID !== Zotero.Libraries.userLibraryID && !Zotero.SyncedSettings.get(libraryID, 'autoRenameFiles')) { + + if (!this.isAutoRenameFilesEnabledForLibrary(libraryID)) { return false; }