Hi All,
I’m writing an app for my company that allows users to create books (of documents) and share those books to others. Each user has a GUID for a unique ID, and each book also has a GUID.
I’ve created a “channel” property in each book that contains the owner’s GUID, which therefore gives that user access. A book owner can then share that document to others, and the app adds the recipients GUID to the book’s channel property.
So far, so good. This works (sync gateway is really awesome). Both users can see the books and documents and make changes.
Now I want to allow users to ‘unlink’ to a document - that is I want to allow the recipient above to remove their own access to that document leaving only the owner. I was hoping that would be as simple as removing their own GUID from the channels property, right?
Unfortunately… it doesn’t seem like that is the case…
Below is a dump of a books object from Couchbase after:
a) book create by owner: D48F785B-18D4-45B1-8E92-A7A00E1C7EF1
b) owner shares with user: 05110569-52D4-41CE-9305-21D4023540A1
c) user 05110569-52D4-41CE-9305-21D4023540A1 then unlinks (i.e. removes their ID from the channels property).
Might be a little hard to see, but it seems like there are 3 channel properties:
- my one at the top level of the book. That now correctly only has D48…E71
- another in the history property (which shows the history of the channels)
- another in the _sync property.
This last one doesn’t seem to update properly?
In any case - after removing the 0511…0A1 user from the channels property, they still have access to the book. I’ve tried deleting all local data then pulling down a fresh copy, and the book is still included.
NOTE: I have read that the right approach to remove the local property is to purge the doc - the problem is that the purge seems to happen before the change to channels syncs up to the server. So no channels changes go up.
So here is my questions:
a) Am I using the right approach for setting the channel for a document?
(or is it better for me to use a sync function (I’ve tried both. The docs imply either should work)
b) What is the right way for a user to remove their own access to a document - is it to simply remove their GUID from the channels array? If so… when do I purge the doc locally?
I appreciate any advice you can give.
Cheers.
Paul
{
"_sync": {
"rev": "5-3e6363d7aa53e2f2a48ce4a776aedae6",
"sequence": 64,
"recent_sequences": [
41,
46,
53,
60,
64
],
"history": {
"revs": [
"5-3e6363d7aa53e2f2a48ce4a776aedae6",
"3-0f3fab2e99abcc95ff3d52164db49c80",
"4-3b263198ad7386f7d65398b2f2d52910",
"1-85731b3571c156ea402421ff6854478c",
"2-2dda576fde32e70ea086967931d7c982"
],
"parents": [
2,
4,
1,
-1,
3
],
"channels": [
[
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1"
],
[
"05110569-52D4-41CE-9305-21D4023540A1",
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1"
],
[
"05110569-52D4-41CE-9305-21D4023540A1",
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1"
],
[
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1"
],
[
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1"
]
]
},
"channels": {
"05110569-52D4-41CE-9305-21D4023540A1": {
"seq": 64,
"rev": "5-3e6363d7aa53e2f2a48ce4a776aedae6"
},
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1": null
},
"time_saved": "2016-05-23T15:33:54.273112245+12:00"
},
"bid": "EABF380C-8FBE-482B-892A-E3DAEA7797EB",
"channels": [
"D48F785B-18D4-45B1-8E92-A7A00E1C7EF1"
],
"owner_id": "D48F785B-18D4-45B1-8E92-A7A00E1C7EF1",
"owner_name": "John Doe",
"title": "Shared Book",
"type": "book",
"version": 2
}