User and documents are not assigned to any channel


#1

For each user (username and password) i have a document like this:

{
  "_sync": {
    "rev": "1-6851cb37477b9077081cdf869a23c255",
    "sequence": 3,
    "recent_sequences": [
      3
    ],
    "history": {
      "revs": [
        "1-6851cb37477b9077081cdf869a23c255"
      ],
      "parents": [
        -1
      ],
      "channels": [
        null
      ]
    },
    "time_saved": "2016-06-20T16:10:47.5939745+02:00"
  },
  "courses": [
    "AdvancedProgramming",
    "SoftwareEngineering"
  ],
  "name": "loris",
  "type": "STUDENT"
}

The user must be able to access to this document. So my sync function is like this:

function(doc){
	if(doc.type == "STUDENT") {
		channel(doc.name)
		access(doc.name, doc.name)
	}
}

I created the user “loris”, BUT:

curl http://localhost:4985/university-notes/_user/loris
{"name":"loris","all_channels":["!"]}

Note: i created the document before writing the sync_function. If i’ve understood correctly, the sync_function is called only when a document is created/deleted/modified. So probably i have to delete this document and recreate it.


#2

@loristefano

You can run a _resync, which will pass all documents through the sync function again.

If you are using SG 1.2 or later, take the DB offline first:

$ curl -X POST http://localhost:4985/university-notes/_offline

For all versions of SG:

$ curl -X POST http://localhost:4985/university-notes/_resync

If you are using SG 1.2 or later, take the DB online again:

$ curl -X POST http://localhost:4985/university-notes/_online

User lorus should now have access to the “lorus” channel


#3

This is… GOLD! Thank you!