-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Circles Examples
Tim Elfelt edited this page Sep 24, 2016
·
2 revisions
First, add permissions array to model of package you want to protect. You may optionally set a default
permissions: {
type: Array,
default: ['authenticated']
}
// where package is your package name
module.exports = function(package, app, circles, database) {
var Package = mongoose.model('Package');
return {
all: function(req, res) {
var query;
if(!req.user || req.acl.user.allowed.indexOf('admin') === -1) {
query = req.acl.query('Package'); // non admins only see items from their circles
} else {
query = Package; // admins see all
}
query.find().sort('-created')
....
....
}
}
this will filter the results to return all items that the user has permission to access.
lock down a route for admins only
var requiresAdmin = circles.controller.hasCircle('admin');
app.route('/api/whatever')
.get(requiresAdmin , whatever.all)
You can also check roles like this req.user.roles.indexOf('admin') > -1
$stateProvider.state('yourState', {
url: '/yourState',
templateUrl: 'yourpackage/views/yourState.html',
requiredCircles : {
circles: ['authenticated'],
denyState: 'auth.login'
}
}
You will also want to add circles as a dependency of you mean.json and package.json files, and inject circles into your custom package declaration, passing it along into server routes/controller files module.exports = function(package, app, circles, database) {
mean.json
{
"name": "package",
"version": "0.1.2",
"mean": "0.6.0",
"dependencies": {
"circles": "0.1.x"
}
}
package.json
"dependencies": {
"meanio-circles": "0.1.x",
You might find more examples in the gitter.im chatroom
- Getting Started Guides
- Deployment
- Testing
- System Deep Dives
Aggregation- Packages
- Database
- Menus
- Circles (roles/permissions) High Level Overview
- Circles code examples
- User Auth withJWT
- Contributing