I found the cause in the sg_info.log:
2019-08-25T21:01:11.319+02:00 [INF] Sync fn rejected: new=map[priceInHundredths:0 _id:unpRV3yhobVQL1mUBVSQ5xYuQu63::shoppingListItem::tj8mpspvmpun::d2b395dd7933 type:shoppingListItem _revisions:map[start:12 ids:[4ae923180d02ed8ed7a1e7e96543b3ad c845fa34c27492a2bffc022df41e2c90]] qtyInThousandths:0 note: _rev:12-4ae923180d02ed8ed7a1e7e96543b3ad unit:map[id:GENERAL name:] sortOrder:157 name:Gerolsteiner Medium id:d2b395dd7933 category:map[id:GENERAL name: sortOrder:0] isCheckedOff:0 channels:unpRV3yhobVQL1mUBVSQ5xYuQu63 shoppingListId:tj8mpspvmpun isDeal:0 isImportant:0 hasPicture:0] old={} --> 403 missing channel access
2019-08-25T21:01:11.319+02:00 [INF] BulkDocs: Doc "unpRV3yhobVQL1mUBVSQ5xYuQu63::shoppingListItem::tj8mpspvmpun::d2b395dd7933" --> 403 missing channel access (403 missing channel access)
Right at the end of the first line it shows that the old doc has {}
as body. Hence the channel is missing and the document gets rejected.
The part of the SG fn is:
else if (doc.type === 'shoppingListItem') {
if (oldDoc && !oldDoc._deleted) {
if (isPropertyMissing(doc)) {
throw ({
forbidden: doc
});
}
if (hasWrongValue(doc)) {
throw ({
forbidden: doc
});
}
requireAccess(oldDoc.channels); // <-- Change this?
channel(doc.channels);
} else if (oldDoc && oldDoc._deleted) {
if (isPropertyMissing(doc)) {
throw ({
forbidden: doc
});
}
if (hasWrongValue(doc)) {
throw ({
forbidden: doc
});
}
channel(doc.channels);
} else if (!oldDoc) {
if (isPropertyMissing(doc)) {
throw ({
forbidden: doc
});
}
if (hasWrongValue(doc)) {
throw ({
forbidden: doc
});
}
channel(doc.channels);
}
}
I think in this line requireAccess(oldDoc.channels); // <-- Change this?
the document is rejected as the oldDoc is empty and hence doesn’t have a channel. Would the below code work and is it recommended to do this?
function isEmpty(obj) {
for(var key in obj) {
if(obj.hasOwnProperty(key))
return false;
}
return true;
}
// ...
if (!isEmpty(oldDoc)) {
requireAccess(oldDoc.channels); // <-- Change this?
}
channel(doc.channels);
// ...
Thanks!