Channel() function not tagging docs

Hi.
I use the the channel function as follows:
“sync”:function(doc) {channel("vjch");}
but does not seem to work.
But it works if i set the user’s admin_channels: ["*"]

What am i doing wrong?

@alterecho you also have to give users access to a channel for them to be able to access the documents tagged with that channel name.

To do that you need to add the channel to the users admin channels:

admin_channels: ["vjch"]

Or dynamically assign the channel in the sync function by using the access() method e.g.

access(userName, "vjch");

Andy

I tried both the techniques, but they don’t work.
This is my config:

{
        "log":["CRUD+", "REST+", "Changes+", "Attach+"],
        "databases": {
                "contacts":{
                        "server":"http://localhost:8091",
                         "bucket":"shd_contacts",
                         "sync":`function(doc) {channel("vjch");}`,
                        "users":{
                                "GUEST" : {
                                        "disabled": true
                                },
                                "vj" : {
                                        "admin_channels":["all"]
                                }
                        },
                        "shadow":{
                                "server":"http://localhost:8091",
                                "bucket":"contacts"
                        }
                }
        }
}

I register a user using:

curl -X PUT -H "Content-type:application/json" -d '{"name":"vj", "password":"1234", "admin_channels":["vj"]}' http://localhost:4985/contacts/_user/vj

I then run:

curl -X GET http://localhost:4985/contacts/_user/vj

I get:

{"name":"vj","admin_channels":["vjch"],"all_channels":["!","vjch"]}

There seems to be a crossover on the admin_channels property of ‘vj’ and ‘vjch’ between user account creation and the user account query.

Can you update the post the actual values being used, otherwise it will be hard to diagnose the issue.

Sorry, that was a mistake i guess (I’m not able to reproduce it!).

I’ve rerun the test on a different machine, and now, the issue is that the documents seems to be posted for all channels!

"sync":`function(doc) {channel("channel1");}`,
 "users":{
        "GUEST" : {
               "disabled": true
           }
   }

and the user access reads:

{"name":"vj","admin_channels":["vjch"],"all_channels":["!","vjch"]}

Yet, the user “vj” is able to replicate documents posted on channel “channel1”, though the acces rights reads as “vjch”.
What am i doing wrong?

Make sure you are using the public API port 4984 and not the Admin port 4985, the admin port will see all channels.

Andy

I re-verified again. It’s 4984.

http://localhost:4984/contacts

Anything else, i need to check (I’ve done most everything)?

Hi Andy,

I am too facing the same issue. Steps I did are

  1. Created a user “U” in Sync Gateway, with admin_channel “X” .
  2. Created a document “D” having channels property set to “X”.
    {
    "_id": “D”,
    “channels”: “X”,
    “message”: “We’re having winter”,
    “temperature”: “4”
    }
  3. I have not changed sync function so it must be using Default Channel function
    function (doc) {
    channel(doc.channels);
    }
  4. Now when I try to read the same document with Authorization for the above user
    but getting forbidden status code.
    Request
    http://localhost:4984/sync_gateway/X
    Authorization Basic Base64encode(username:password)
    Response
    {
    “error”: “Forbidden”
    “reason”: “forbidden”
    }

Please let me know if I am doing anything wrong.