Don't copy/import/delete note images if library files aren't editable

#2364
This commit is contained in:
Martynas Bagdonas 2022-02-21 17:13:59 +02:00
parent 9ca617a6a9
commit 04fa89ffc8
3 changed files with 31 additions and 24 deletions

View file

@ -1632,7 +1632,9 @@ var CollectionTree = class CollectionTree extends LibraryTree {
await newItem.addLinkedItem(item); await newItem.addLinkedItem(item);
if (item.isNote()) { if (item.isNote()) {
if (Zotero.Libraries.get(newItem.libraryID).filesEditable) {
await Zotero.Notes.copyEmbeddedImages(item, newItem); await Zotero.Notes.copyEmbeddedImages(item, newItem);
}
return newItemID; return newItemID;
} }
@ -1649,7 +1651,9 @@ var CollectionTree = class CollectionTree extends LibraryTree {
skipSelect: true skipSelect: true
}) })
if (Zotero.Libraries.get(newNote.libraryID).filesEditable) {
await Zotero.Notes.copyEmbeddedImages(note, newNote); await Zotero.Notes.copyEmbeddedImages(note, newNote);
}
await newNote.addLinkedItem(note); await newNote.addLinkedItem(note);
} }
} }

View file

@ -59,6 +59,7 @@ class EditorInstance {
this._reloaded = options.reloaded; this._reloaded = options.reloaded;
this._viewMode = options.viewMode; this._viewMode = options.viewMode;
this._readOnly = options.readOnly || this._isReadOnly(); this._readOnly = options.readOnly || this._isReadOnly();
this._filesReadOnly = !Zotero.Libraries.get(this._item.libraryID).filesEditable;
this._disableUI = options.disableUI; this._disableUI = options.disableUI;
this._onReturn = options.onReturn; this._onReturn = options.onReturn;
this._iframeWindow = options.iframeWindow; this._iframeWindow = options.iframeWindow;
@ -131,7 +132,7 @@ class EditorInstance {
this._iframeWindow.removeEventListener('message', this._messageHandler); this._iframeWindow.removeEventListener('message', this._messageHandler);
this.saveSync(); this.saveSync();
await Zotero.Notes.unregisterEditorInstance(this); await Zotero.Notes.unregisterEditorInstance(this);
if (!this._item.isAttachment()) { if (!this._item.isAttachment() && !this._filesReadOnly) {
await Zotero.Notes.deleteUnusedEmbeddedImages(this._item); await Zotero.Notes.deleteUnusedEmbeddedImages(this._item);
} }
} }
@ -370,7 +371,7 @@ class EditorInstance {
} }
// Image // Image
if (annotation.image) { if (annotation.image && !this._filesReadOnly) {
// We assume that annotation.image is always PNG // We assume that annotation.image is always PNG
let imageAttachmentKey = await this._importImage(annotation.image); let imageAttachmentKey = await this._importImage(annotation.image);
delete annotation.image; delete annotation.image;
@ -517,6 +518,7 @@ class EditorInstance {
} }
// Clone all note image attachments and replace keys in the new note // Clone all note image attachments and replace keys in the new note
if (!this._filesReadOnly) {
let attachments = Zotero.Items.get(item.getAttachments()); let attachments = Zotero.Items.get(item.getAttachments());
for (let attachment of attachments) { for (let attachment of attachments) {
if (!await attachment.fileExists()) { if (!await attachment.fileExists()) {
@ -538,6 +540,7 @@ class EditorInstance {
} }
}); });
} }
}
html += `<p></p>${doc.body.innerHTML}<p></p>`; html += `<p></p>${doc.body.innerHTML}<p></p>`;
} }
@ -736,7 +739,7 @@ class EditorInstance {
} }
case 'importImages': { case 'importImages': {
let { images } = message; let { images } = message;
if (this._readOnly) { if (this._readOnly || this._filesReadOnly) {
return; return;
} }
if (this._item.isAttachment()) { if (this._item.isAttachment()) {

View file

@ -1665,7 +1665,7 @@ var ZoteroPane = new function()
newItem.setCollections([self.getCollectionTreeRow().ref.id]); newItem.setCollections([self.getCollectionTreeRow().ref.id]);
} }
yield newItem.save(); yield newItem.save();
if (item.isNote()) { if (item.isNote() && Zotero.Libraries.get(newItem.libraryID).filesEditable) {
yield Zotero.Notes.copyEmbeddedImages(item, newItem); yield Zotero.Notes.copyEmbeddedImages(item, newItem);
} }
for (let relItemKey of item.relatedItems) { for (let relItemKey of item.relatedItems) {