You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add `ng-acl` to your app module's dependencies & setup the `AclService` in `run()` block.
35
+
```js
36
+
angular.module('myApp', ['ng-acl']);
37
+
38
+
app.run(['AclService', function (AclService) {
39
+
//All these actions you also can do in the middle of app execution
40
+
AclService.addRole('guest');
41
+
AclService.addRole('user', 'guest');
42
+
AclService.addRole('admin', 'user');
43
+
44
+
AclService.addResource('Post');
45
+
AclService.addResource('Users');
46
+
AclService.addResource('AdminPanel');
47
+
48
+
AclService.allow('guest', 'Post', 'view');
49
+
50
+
//Users can edit edit their own posts & view it because user inherits all guest permissions
51
+
AclService.allow('user', 'Post', 'edit', function (role, resource, privilege) {
52
+
returnresource.authorId===role.id;
53
+
});
54
+
55
+
//Full access to all actions that available for Post
56
+
AclService.allow('admin', 'Post');
57
+
AclService.allow('admin', 'AdminPanel');
58
+
59
+
//Let's assume that you have some user object that implements AclRoleInterface. This is optional feature.
60
+
var user = {
61
+
id:1,
62
+
name:'Duck',
63
+
getRoles:function () {
64
+
return ['user'];
65
+
},
66
+
};
67
+
AclService.setUserIdentity(user);
68
+
}]);
69
+
```
70
+
71
+
#### Protect a route
72
+
73
+
If the current user tries to go to the `/admin_panel` route, they will be redirected because the current user is a `user`, and `AdminPanel` is not one of a member role's abilities.
74
+
75
+
However, when the user goes to `/posts/2`, route will work as normal, since the user has permission.
76
+
77
+
```js
78
+
app.config(['$routeProvider', function ($routeProvider) {
The edit link in the template below will be shown, because the current user is a `user`, and `Post` which was created by our user is one of a his role's abilities.
119
+
120
+
###### Controller
121
+
122
+
```js
123
+
app.controller('DemoCtrl', ['$scope', 'AclService', function ($scope, AclService) {
0 commit comments