Fix error adding group item before syncing in Zotero 6

Fixes #2440
This commit is contained in:
Dan Stillman 2022-03-21 22:48:39 -04:00
parent 8763190328
commit 174f1aadde
2 changed files with 44 additions and 9 deletions

View file

@ -1374,15 +1374,37 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
//}
}
if (createdByUserID || lastModifiedByUserID) {
let sql = "REPLACE INTO groupItems VALUES (?, ?, ?)";
yield Zotero.DB.queryAsync(
sql,
[
itemID,
createdByUserID || null,
lastModifiedByUserID || null
]
);
try {
let sql = "REPLACE INTO groupItems VALUES (?, ?, ?)";
yield Zotero.DB.queryAsync(
sql,
[
itemID,
createdByUserID || null,
lastModifiedByUserID || null
]
);
}
// TODO: Use schema update step to add username to users table if group library
// and no current name
catch (e) {
let username = yield Zotero.DB.valueQueryAsync(
"SELECT value FROM settings WHERE setting='account' AND key='username'"
);
if (username) {
yield Zotero.Users.setCurrentName(username);
let sql = "REPLACE INTO groupItems VALUES (?, ?, ?)";
yield Zotero.DB.queryAsync(
sql,
[
itemID,
createdByUserID || null,
lastModifiedByUserID || null
]
);
}
}
}
}

View file

@ -1750,6 +1750,19 @@ describe("Zotero.Item", function () {
);
assert.lengthOf(annotationIDs, 1);
});
it("should set username as name if not set for library item", async function () {
await Zotero.Users.setCurrentUserID(1);
var username = Zotero.Utilities.randomString();
await Zotero.Users.setCurrentUsername(username);
await Zotero.DB.queryAsync("DELETE FROM users");
var group = await createGroup();
var libraryID = group.libraryID;
var item = await createDataObject('item', { libraryID });
assert.equal(Zotero.Users.getCurrentName(), username);
});
})