Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
rainboyan committed May 30, 2024
1 parent 61024c3 commit 18e0f22
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@ dependencies {
}
```


### Creating a Policy

In `app/controllers`,

```groovy
class PostController {
def show(Long id) {
def post = postService.get(id)
authorize post
// some
}
}
```

In `app/policies`, create a `Policy` for `PostController`,

```groovy
class PostPolicy {
def show() {
record.status == 'PUBLISHED' || record.author.id == user.id || user.hasRole('ROLE_ADMIN')
}
}
```

`policy` plugin provides `authorize(record, options)` for your `Controllers`,

```groovy
// Without record (null)
authorize()
// With post, use PostPolicy, actionName is the rule
authorize(post)
// Use custom Policy and rule
authorize(post, [with: NewPostPolicy, to: 'manage'])
```

## Development

### Build from source
Expand All @@ -38,6 +80,11 @@ cd grace-policy
* Grace 2022.0.0+
* Grails 3.0+

## Roadmap

* Spring Security integration
* Support Grails Service

## License

This plugin is available as open source under the terms of the [APACHE LICENSE, VERSION 2.0](http://apache.org/Licenses/LICENSE-2.0)
Expand Down

0 comments on commit 18e0f22

Please sign in to comment.