https://github.com/confact/lucky_can
A simple pundit policies library for Lucky Framework in Crystal
https://github.com/confact/lucky_can
Last synced: about 1 year ago
JSON representation
A simple pundit policies library for Lucky Framework in Crystal
- Host: GitHub
- URL: https://github.com/confact/lucky_can
- Owner: confact
- License: mit
- Created: 2020-03-24T16:19:16.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-24T16:41:41.000Z (about 6 years ago)
- Last Synced: 2025-04-10T14:19:14.463Z (about 1 year ago)
- Language: Crystal
- Homepage:
- Size: 2.93 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lucky_can
An little nicer way to handle authorization rules for your lucky app
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
lucky_can:
github: confact/lucky_can
```
2. Run `shards install`
## Usage
1. ```crystal
require "lucky_can"
```
2. create an `policies` directory where all your policies will be. Now you will Add an require for that directory to the app.cr file before `pages` require. Add this: `require "./policies/**"`
3. now you can create your policies in `policies` directory.
### Simple usage
```crystal
class TeamPolicy < LuckyCan::BasePolicy
can show, team, current_user do
return false if current_user.nil?
team.users.include?(current_user)
end
end
```
this generate following methods for you to use by an macro:
* `TeamPolicy.show?(team, current_user)` - for simple bool check if the user have access to the team.
* `TeamPolicy.show_not_found?(team, current_user, context)` - Return an Lucky::RouteNotFoundError if the code in the block return false.
* `TeamPolicy.show_forbidden?(team, current_user, context)` - Return an LuckyCan::ForbiddenError if the code in the block return false.
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Håkan Nylén](https://github.com/confact) - creator and maintainer