Fix applying remote deletion of item in collection in read-only library

"Cannot edit item in read-only library"

I have no idea how this bug has gone undetected for so long.
This commit is contained in:
Dan Stillman 2020-05-26 08:21:38 -04:00
parent b288a278d8
commit f43df90225
3 changed files with 25 additions and 5 deletions

View file

@ -413,8 +413,8 @@ Zotero.Collection.prototype.addItems = Zotero.Promise.coroutine(function* (itemI
*
* @return {Promise}
*/
Zotero.Collection.prototype.removeItem = function (itemID) {
return this.removeItems([itemID]);
Zotero.Collection.prototype.removeItem = function (itemID, options = {}) {
return this.removeItems([itemID], options);
}
@ -424,7 +424,7 @@ Zotero.Collection.prototype.removeItem = function (itemID) {
*
* Does not require a separate save()
*/
Zotero.Collection.prototype.removeItems = Zotero.Promise.coroutine(function* (itemIDs) {
Zotero.Collection.prototype.removeItems = Zotero.Promise.coroutine(function* (itemIDs, options = {}) {
if (!itemIDs || !itemIDs.length) {
return;
}
@ -443,7 +443,8 @@ Zotero.Collection.prototype.removeItems = Zotero.Promise.coroutine(function* (it
let item = yield this.ChildObjects.getAsync(itemID);
item.removeFromCollection(this.id);
yield item.save({
skipDateModifiedUpdate: true
skipDateModifiedUpdate: true,
skipEditCheck: options.skipEditCheck
})
}
});

View file

@ -4119,7 +4119,12 @@ Zotero.Item.prototype._eraseData = Zotero.Promise.coroutine(function* (env) {
var parentCollectionIDs = this._collections;
for (let parentCollectionID of parentCollectionIDs) {
let parentCollection = yield Zotero.Collections.getAsync(parentCollectionID);
yield parentCollection.removeItem(this.id);
yield parentCollection.removeItem(
this.id,
{
skipEditCheck: env.options.skipEditCheck
}
);
}
var parentItem = this.parentKey;

View file

@ -1302,6 +1302,20 @@ describe("Zotero.Item", function () {
0
);
});
it("should remove an item in a collection in a read-only library", async function () {
var group = await createGroup();
var libraryID = group.libraryID;
var collection = await createDataObject('collection', { libraryID });
var item = await createDataObject('item', { libraryID, collections: [collection.id] });
group.editable = false;
await group.save();
await item.eraseTx({
skipEditCheck: true
});
});
});