Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed readme examples #181

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ acl.isAllowed('joed', 'blogs', 'view', function(err, res){
if(res){
console.log("User joed is allowed to view blogs")
}
}
})
```


Expand All @@ -156,16 +156,18 @@ Note that all permissions must be full filed in order to get *true*.
Sometimes is necessary to know what permissions a given user has over certain resources:

```javascript
acl.allowedPermissions('james', ['blogs','forums'], function(err, permissions){
acl.allowedPermissions('joed', ['blogs','forums'], function(err, permissions){
console.log(permissions)
})
```

It will return an array of resource:[permissions] like this:
It will return an object of resource:[permissions] like this:

```javascript
[{'blogs' : ['get','delete']},
{'forums':['get','put']}]
{
blogs: [ 'get', 'view' ],
forums: [ 'get', 'put', 'delete' ]
}
```


Expand All @@ -178,7 +180,7 @@ acl.middleware()
We can protect a resource like this:

```javascript
app.put('/blogs/:id', acl.middleware(), function(req, res, next){…}
app.put('/blogs/:id', acl.middleware(), function(req, res, next){…})
```

The middleware will protect the resource named by *req.url*, pick the user from *req.session.userId* and check the permission for *req.method*, so the above would be equivalent to something like this:
Expand All @@ -191,15 +193,15 @@ The middleware accepts 3 optional arguments, that are useful in some situations.
cannot consider the whole url as the resource:

```javascript
app.put('/blogs/:id/comments/:commentId', acl.middleware(3), function(req, res, next){…}
app.put('/blogs/:id/comments/:commentId', acl.middleware(3), function(req, res, next){…})
```

In this case the resource will be just the three first components of the url (without the ending slash).

It is also possible to add a custom userId or check for other permissions than the method:

```javascript
app.put('/blogs/:id/comments/:commentId', acl.middleware(3, 'joed', 'post'), function(req, res, next){…}
app.put('/blogs/:id/comments/:commentId', acl.middleware(3, 'joed', 'post'), function(req, res, next){…})
```

## Methods
Expand Down