How to perform "Document Access Removal Behavior"

I went through this document, but unable to remove document access on the sync gateway.

FYI: I’m using Couchbase Lite 2.8.6 on the mobile (Xamarin SDK)

document:

{
  "channels": [
    "3a7c15ba2241"
  ],
  "docType": "logentry",
  "creator": "14bd9d1d7a",
  "createdOn": "2022-03-30T13:37:42.5070600-04:00",
  "subjectId": "14bd9d1d7a",
  "modifier": "14bd9d1d7a",
  "modifiedOn": "2022-03-30T13:37:42.5070600-04:00",
  "deleter": null,
  "writers": [
    "14bd9d1d7a",
    "7c15ba2241"
  ],
  "sequenceId": "0",
  "_id": "evt..14bd9d1d7a..69856d73a",
  "_rev": null,
  "_deleted": false,
  "insert_id": "evt..14bd9d1d7a..69856d73a",
  "device_id": "5E634E1C226",
  "user_id": "14bd9d1d7a",
  "event_type": "Signup",
  "origin": null,
  "time": 1648661795504
}

sync function:

if (doc.docType === "logentry") {
    channel("logevents");
    return;
}

I expected that by doing this in sync gateway, the channel is updated and the user doesn’t have the access to logentry channel so the document will be purged. But I still see the documents in the device (phone) CB Lite. Based on the documentation, an event is triggered and those documents are purged, which isn’t happening.

Based on the document here:

### Auto-purge on Channel Access Revocation
Previously (**before v3.0**) these documents remained in the local database

Prior to this relese, CBL auto-purged only in the case when the user loses access to a document by removing the doc from all of the channels belong to the user. Now, in addition to 2.x auto purge, Couchbase Lite will also auto-purges the docs when the user loses access to the doc via channel access revocation. This feature is enabled by default, but an opt-out is available.

Does it mean that the user would still have access to those document? If yes, then

  1. what is the “auto purge” really doing if its not removing access?
  2. After the app is relaunched user is not able to access those docs, is this expected?
  3. Can anyone suggest how I can remove document access and subsequently purges the document from the database?

@Ehtved
You can find more detailed description in EnableAutoPurge property in the API doc: Class ReplicatorConfiguration

@Sandy_Chuang
EnableAutoPurge isn’t available for v2.8.6 (Xamarin SDK). Is it possible to auto-purge in v2.8.x?

@Ehtved
EnableAutoPurge is the new feature added in CBL version 3.0. Not available in CBL v2.8.x or less.

Thanks! So autopurge functionality doesn’t exist in v2.8.6 ?

As Sandy mentioned, auto purge on channel access revocation is available starting 3.0. So not in 2.8.6.

3.0, as in CBL3.0 or both CBL 3.0 and sync gateway 3.0?

CBL 3.0 and SGW 3.0. Auto purge on channel access revocation includes changes to underlying sync protocol and requires both to be on min version of 3.0.

1 Like

Auto purge is available on 2.8 only for the case the the doc are removed from all of the channels that the user has access to. For the case of revoking user’s access to channels, this will be supported by CBL and SG 3.0.

To answer the original question, I would think that the user still has access to the document via other channels. If this in the dev env, you can use browser to get to the document using http://[SG URL]:[PORT]/[database]/[doc-id] and logged in with the same user. If you can see the doc, it means that the user can still access to the doc.

I am also currently upgrading from 2.x to 3.0 and I was able to confirm that if a document is removed from a channel where the user does not have access to, the document is indeed auto purged even with version 2.8 of Couchbase lite.

However this worked when the mutation was executed from Couchbase dashboard, when I try the same mutation from Couchbase lite SDK ( which will update the document and run the sync function logic to change the channel assignment), the document is not auto-purged. In both cases I was able to validate that the user and document channel assignment are as expected.

Do we need to be on Couchbase lite 3.0 to handle both cases I described above ?

Thanks
Adrian

When the mutation on the document is executed from Couchbase lite SDK, altough the next replication will trigger the sync function to run and remove the document from all channels the user has access to, the document will not be auto-purged, at least from my tests. Not sure I missed anything here.