Access to documents for a specific user is performed in the synchronization function. This is a function written in JavaScript that is located in the Sync Gateway configuration file.
Methods available in the synchronization function:
channel(channelname): route the document to the channel.access(username, channelname): provide access to the username for the channel (the ability to provide the role to the channel too, and as a result, all users with this role will gain access to the channel).role(username, rolename): Assign a user with a role.requireAccess(channelname): throws an error if the user in the context does not yet have access to the channel.requireUser(username): throws an error if the user in the context is not the username.requireRole(rolename): Throws and errors if the user in the context does not have the role of rolename.throw({forbidden: "error message"}): Throw an exception for user verification.
Here is an example configuration file with inline comments:
{
"log": ["REST", "CRUD"],
"users": {
"foo1": {"password": "letmein", "admin_roles": ["admin"]},
"foo2": {"password": "letmein"}
},
"databases": {
"quizz": {
"sync": `function(doc, oldDoc) {
if (doc.owner != oldDoc.owner) {
throw({forbidden: "Can't change the owner field on existing documents"});
}
switch(doc.type) {
case "list":
requireRole("admin");
break;
case "todo":
require(doc.owner);
break;
}
}`
}
}
}
. , , ( ) (.. /http, ). , .
. docs .