guachiman 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -12
- data/lib/guachiman/rails/permissible.rb +11 -3
- data/lib/guachiman/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e6fd56b0aa9fdbd47edc2287ce0a09e82796663
|
4
|
+
data.tar.gz: 7bb8f254b756e24f05e60b37075ee10b7bf70226
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecbda870fdeefee6d215a52b74407e05d0f40b35dc494426095cb6899e55fc076f7af5ec4d853dcb6f7163f4ba18ddf6126fdcd3a77d4ac39c22e1012180f304
|
7
|
+
data.tar.gz: b9df6b3ecacdcc7060c17284b83dbbe5a56ea5bbe2b8c8f2a873c42c94a34f78e9167066cbafa2d16d539e36ad705bd025c15cf7cbc003a9ce95ab2edec08ff6
|
data/README.md
CHANGED
@@ -9,27 +9,25 @@ Installation
|
|
9
9
|
|
10
10
|
Add this line to your application's Gemfile:
|
11
11
|
|
12
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'guachiman'
|
14
|
+
```
|
13
15
|
|
14
16
|
And then execute:
|
15
17
|
|
16
|
-
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
17
21
|
|
18
22
|
Or install it yourself as:
|
19
23
|
|
20
|
-
|
24
|
+
```bash
|
25
|
+
$ gem install guachiman
|
26
|
+
```
|
21
27
|
|
22
28
|
Usage
|
23
29
|
-----
|
24
30
|
|
25
|
-
Include it in your `Gemfile`
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
gem 'guachiman'
|
29
|
-
```
|
30
|
-
|
31
|
-
Run `bundle install`
|
32
|
-
|
33
31
|
Run `rails g guachiman:install`
|
34
32
|
|
35
33
|
This will generate a `Permission.rb` file in `app/models`.
|
@@ -44,6 +42,19 @@ def current_user
|
|
44
42
|
end
|
45
43
|
```
|
46
44
|
|
45
|
+
You can also override these methods to handle failed authorizations:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
def not_authorized
|
49
|
+
redirect_to root_path, alert: t('flashes.not_authorized')
|
50
|
+
end
|
51
|
+
|
52
|
+
def not_signed_in
|
53
|
+
session[:next] = request.url
|
54
|
+
redirect_to sign_in_path, alert: t('flashes.please_login')
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
47
58
|
That's it, now you can describe your permissions in this way:
|
48
59
|
|
49
60
|
```ruby
|
@@ -87,4 +98,6 @@ class Permission
|
|
87
98
|
end
|
88
99
|
```
|
89
100
|
|
90
|
-
|
101
|
+
* `allow` takes a controller params key and an array of actions.
|
102
|
+
* `allow_param` takes a model params key and an array of attributes.
|
103
|
+
* `allow_all!` is a convinience method to allow all controlles, actions and parameteres.
|
@@ -24,13 +24,21 @@ module Guachiman
|
|
24
24
|
if current_permission.allow? controller_name, action_name, current_resource
|
25
25
|
current_permission.permit_params! params
|
26
26
|
else
|
27
|
-
|
27
|
+
if current_user
|
28
|
+
not_authorized
|
29
|
+
else
|
30
|
+
not_signed_in
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def not_authorized
|
32
|
-
|
33
|
-
|
36
|
+
redirect_to root_path, alert: t('flashes.not_authorized')
|
37
|
+
end
|
38
|
+
|
39
|
+
def not_signed_in
|
40
|
+
session[:next] = request.url
|
41
|
+
redirect_to sign_in_path, alert: t('flashes.please_sign_in')
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/guachiman/version.rb
CHANGED