Sync Gateway 403 Forbidden after PUT


#1

My sync gateway is running using this config:

{
  "interface": ":4984",
  "adminInterface": ":4985",
  "log": [],
  "databases": {
    "db": {
      "bucket": "main",
      "server": "http://192.168.99.100:8091",
      "users": {
        "election-api": {
          "disabled": false,
          "admin_channels": ["db.election-api"]
        }
      },
      "sync": "function (doc, oldDoc) {\r\n   if ( doc.doc_type == \"election\" || doc.doc_type == \"contest\" || doc.doc_type == \"ballot\" ) {\r\n      channel(\"db.election-api\", doc.channels);\r\n   }\r\n}"
    }
  }
}

I am testing the sync gateway with some simple curl commands. First I create a doc using POST /db/

curl -i -X POST -H "Content-type: application/json" -d '{"doc_type": "election"}' "http://192.168.99.100:4984/db/"

which gives:

{"id":"ac76656e7f25b7df215912d4648b3598","ok":true,"rev":"1-bd55ccbe2231357c4becaa85e10ca783"}

Then I get all_docs as the election-api user to make sure I can see that doc (I got the token from admin port and /sessions endpoint):

curl -i --cookie "SyncGatewaySession=59c0d10091e9063ba33a73237a5c3a0467960c40" -H "Content-type: application/json" -X GET "http://192.168.99.100:4984/db/_all_docs"

gives:

{"rows":[
{"key":"ac76656e7f25b7df215912d4648b3598","id":"ac76656e7f25b7df215912d4648b3598","value":{"rev":"1-bd55ccbe2231357c4becaa85e10ca783"}}
],
"total_rows":1,"update_seq":17} 

Now I update the doc using a PUT:

curl -X PUT -H "Content-type: application/json" -d '{"newProp": "new"}' "http://192.168.99.100:4984/db/ac76656e7f25b7df215912d4648b3598?rev=1-bd55ccbe2231357c4becaa85e10ca783"

gives:

{"id":"ac76656e7f25b7df215912d4648b3598","ok":true,"rev":"2-a2e233717adcb74245d1adfa0a1e58e1"}

The problem is that now when I run the same GET command from above ^^ I can’t see the document:

{"rows":[
],
"total_rows":0,"update_seq":18}

And if I try to find the doc by id using POST to _all_docs:

curl -i --cookie "SyncGatewaySession=59c0d10091e9063ba33a73237a5c3a0467960c40" -d '{"keys": [ "ac76656e7f25b7df215912d4648b3598" ]}' -H "Content-type: application/json" -X POST "http://192.168.99.100:4984/db/_all_docs"

I get 403 forbidden:

{"rows":[
{"key":"ac76656e7f25b7df215912d4648b3598","error":"forbidden","status":403}
],
"total_rows":1,"update_seq":18}

Please help. So confused. Thanks!


#2

Updates to the doc aren’t incremental, so when you’re updating the doc, it’s setting the document body to {"newProp": "new"}. This doesn’t get assigned to any channels (as your sync function requires the doc_type property for channeling), so the user no longer has access to the doc.


#3

Ahhhh and now its works. Thank you so much!