Ensure automatic file renaming is enabled for group libraries (#5750)

This commit is contained in:
Tom Najdek 2026-01-27 19:25:12 +01:00 • committed by GitHub
parent 56de1abb79
commit aabac2576c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 7 deletions

View file

@ -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) {

View file

@ -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;
}