Don't copy/import/delete note images if library files aren't editable
#2364
This commit is contained in:
parent
9ca617a6a9
commit
04fa89ffc8
3 changed files with 31 additions and 24 deletions
|
@ -1632,7 +1632,9 @@ var CollectionTree = class CollectionTree extends LibraryTree {
|
|||
await newItem.addLinkedItem(item);
|
||||
|
||||
if (item.isNote()) {
|
||||
await Zotero.Notes.copyEmbeddedImages(item, newItem);
|
||||
if (Zotero.Libraries.get(newItem.libraryID).filesEditable) {
|
||||
await Zotero.Notes.copyEmbeddedImages(item, newItem);
|
||||
}
|
||||
return newItemID;
|
||||
}
|
||||
|
||||
|
@ -1648,8 +1650,10 @@ var CollectionTree = class CollectionTree extends LibraryTree {
|
|||
await newNote.save({
|
||||
skipSelect: true
|
||||
})
|
||||
|
||||
await Zotero.Notes.copyEmbeddedImages(note, newNote);
|
||||
|
||||
if (Zotero.Libraries.get(newNote.libraryID).filesEditable) {
|
||||
await Zotero.Notes.copyEmbeddedImages(note, newNote);
|
||||
}
|
||||
await newNote.addLinkedItem(note);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ class EditorInstance {
|
|||
this._reloaded = options.reloaded;
|
||||
this._viewMode = options.viewMode;
|
||||
this._readOnly = options.readOnly || this._isReadOnly();
|
||||
this._filesReadOnly = !Zotero.Libraries.get(this._item.libraryID).filesEditable;
|
||||
this._disableUI = options.disableUI;
|
||||
this._onReturn = options.onReturn;
|
||||
this._iframeWindow = options.iframeWindow;
|
||||
|
@ -131,7 +132,7 @@ class EditorInstance {
|
|||
this._iframeWindow.removeEventListener('message', this._messageHandler);
|
||||
this.saveSync();
|
||||
await Zotero.Notes.unregisterEditorInstance(this);
|
||||
if (!this._item.isAttachment()) {
|
||||
if (!this._item.isAttachment() && !this._filesReadOnly) {
|
||||
await Zotero.Notes.deleteUnusedEmbeddedImages(this._item);
|
||||
}
|
||||
}
|
||||
|
@ -370,7 +371,7 @@ class EditorInstance {
|
|||
}
|
||||
|
||||
// Image
|
||||
if (annotation.image) {
|
||||
if (annotation.image && !this._filesReadOnly) {
|
||||
// We assume that annotation.image is always PNG
|
||||
let imageAttachmentKey = await this._importImage(annotation.image);
|
||||
delete annotation.image;
|
||||
|
@ -517,26 +518,28 @@ class EditorInstance {
|
|||
}
|
||||
|
||||
// Clone all note image attachments and replace keys in the new note
|
||||
let attachments = Zotero.Items.get(item.getAttachments());
|
||||
for (let attachment of attachments) {
|
||||
if (!await attachment.fileExists()) {
|
||||
continue;
|
||||
}
|
||||
await Zotero.DB.executeTransaction(async () => {
|
||||
let copiedAttachment = await Zotero.Attachments.copyEmbeddedImage({
|
||||
attachment,
|
||||
note: this._item,
|
||||
saveOptions: {
|
||||
notifierData: {
|
||||
noteEditorID: this.instanceID
|
||||
if (!this._filesReadOnly) {
|
||||
let attachments = Zotero.Items.get(item.getAttachments());
|
||||
for (let attachment of attachments) {
|
||||
if (!await attachment.fileExists()) {
|
||||
continue;
|
||||
}
|
||||
await Zotero.DB.executeTransaction(async () => {
|
||||
let copiedAttachment = await Zotero.Attachments.copyEmbeddedImage({
|
||||
attachment,
|
||||
note: this._item,
|
||||
saveOptions: {
|
||||
notifierData: {
|
||||
noteEditorID: this.instanceID
|
||||
}
|
||||
}
|
||||
});
|
||||
let node = doc.querySelector(`img[data-attachment-key="${attachment.key}"]`);
|
||||
if (node) {
|
||||
node.setAttribute('data-attachment-key', copiedAttachment.key);
|
||||
}
|
||||
});
|
||||
let node = doc.querySelector(`img[data-attachment-key="${attachment.key}"]`);
|
||||
if (node) {
|
||||
node.setAttribute('data-attachment-key', copiedAttachment.key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
html += `<p></p>${doc.body.innerHTML}<p></p>`;
|
||||
|
@ -736,7 +739,7 @@ class EditorInstance {
|
|||
}
|
||||
case 'importImages': {
|
||||
let { images } = message;
|
||||
if (this._readOnly) {
|
||||
if (this._readOnly || this._filesReadOnly) {
|
||||
return;
|
||||
}
|
||||
if (this._item.isAttachment()) {
|
||||
|
|
|
@ -1665,7 +1665,7 @@ var ZoteroPane = new function()
|
|||
newItem.setCollections([self.getCollectionTreeRow().ref.id]);
|
||||
}
|
||||
yield newItem.save();
|
||||
if (item.isNote()) {
|
||||
if (item.isNote() && Zotero.Libraries.get(newItem.libraryID).filesEditable) {
|
||||
yield Zotero.Notes.copyEmbeddedImages(item, newItem);
|
||||
}
|
||||
for (let relItemKey of item.relatedItems) {
|
||||
|
|
Loading…
Reference in a new issue