Don't remove relations in annotation item JSON

This was causing UUIDs for annotations from Mendeley imports to be
removed after a sync, resulting in annotations being duplicated on a
reimport.
This commit is contained in:
Dan Stillman 2022-04-14 06:35:32 -04:00
parent 3792c89fbd
commit 08d3880d88
2 changed files with 27 additions and 5 deletions

View file

@ -5340,10 +5340,6 @@ Zotero.Item.prototype.toJSON = function (options = {}) {
var json = this._postToJSON(env);
if (this.isAnnotation()) {
delete json.relations;
}
// TODO: Remove once we stop clearing props from the cached JSON in patch mode
if (options.skipStorageProperties) {
delete json.md5;

View file

@ -2097,11 +2097,37 @@ describe("Zotero.Item", function () {
assert.propertyVal(json, name, item[name]);
}
assert.deepEqual(json.annotationPosition, item.annotationPosition);
assert.doesNotHaveAnyKeys(json.relations);
assert.notProperty(json, 'collections');
assert.notProperty(json, 'relations');
assert.notProperty(json, 'annotationIsExternal');
});
it("should include Mendeley annotation relation", async function () {
var item = createUnsavedDataObject(
'item', { itemType: 'annotation', parentKey: attachment.key }
);
item.annotationType = 'highlight';
item.annotationText = "Foo";
item.annotationComment = "";
item.annotationColor = "#ffec00";
item.annotationPageLabel = "15";
item.annotationSortIndex = "00015|002431|00000";
item.annotationPosition = JSON.stringify({
"pageIndex": 1,
"rects": [
[231.284, 402.126, 293.107, 410.142]
]
});
item.setRelations({
'mendeleyDB:annotationUUID': '13e4ec18-f49a-47fb-93f6-fda915d3a1c2'
});
var json = item.toJSON();
assert.sameMembers(
json.relations['mendeleyDB:annotationUUID'],
item.getRelations()['mendeleyDB:annotationUUID']
);
});
describe("#annotationIsExternal", function () {
it("should be false if not set", async function () {
var item = await createAnnotation('highlight', attachment);