Class xataface.Permissions
Defined in: Permissions.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Class to help obtain permissions information about a specific record.
|
| Method Attributes | Method Name and Description |
|---|---|
|
checkPermission(perm)
Checks to see if the given permission is granted.
|
|
|
Returns an associative array of granted permissions.
|
|
|
getQuery()
Gets the query that was used to get these permissions.
|
|
|
load(callback)
Loads the permissions for the current query from the server.
|
|
|
ready()
Runs a callback function after the permissions object is ready.
|
|
|
setQuery(q)
Sets the query to be used.
|
Class Detail
xataface.Permissions(o)
Class to help obtain permissions information about a specific record.
//require <xataface/Permissions.js>
var Permissions = XataJax.load('xataface.Permissions');
var myperms = new Permissions({
query: {
'-table': 'users',
'user_id': 10
}
});
myperms.ready(function(){
// We can't call any thing until the permissions are ready
if ( myperms.checkPermission('view') ){
alert('We have view permission');
}
});
- Parameters:
- {Object} o
- The config parameters.
- {Object} o.query
- The query parameters following Xataface URL conventions.
Method Detail
{Boolean}
checkPermission(perm)
Checks to see if the given permission is granted. This method
should be run after the Permissions object is ready.
- Parameters:
- {String} perm
- The permission to check.
- Returns:
- {Boolean} True if the permission is granted. False otherwise.
{Object}
getPermissions()
Returns an associative array of granted permissions.
This should only be run after the Permissions object is ready.
- Returns:
- {Object}
{Object}
getQuery()
Gets the query that was used to get these permissions.
- Returns:
- {Object}
load(callback)
Loads the permissions for the current query from the server.
- Parameters:
- {Function} callback
- Callback function called when loading is complete. This function is run in the context of this Permissions object.
ready()
Runs a callback function after the permissions object is ready. All methods
for checking permissions should be run inside this object.
{void}
setQuery(q)
Sets the query to be used. This will clear out the current
permissions cache and cause the object to need to reload the permissions.
- Parameters:
- {Object} q
- The query.
- Returns:
- {void}