guachiman 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24c4933a403cafbadec8a89d9d4c97fcc60363a1
4
- data.tar.gz: f7105a30e32169f70009ba9e7035859ae35440c9
3
+ metadata.gz: 7e6fd56b0aa9fdbd47edc2287ce0a09e82796663
4
+ data.tar.gz: 7bb8f254b756e24f05e60b37075ee10b7bf70226
5
5
  SHA512:
6
- metadata.gz: 700a5be51edeec2700bc4c584856e65e9a9ac5696c6ae1dcdc6f4ed3b0f8467eb55d83402a74d903685c9a70ea0b950c515d3b49df03de45dc3304e6606cafa0
7
- data.tar.gz: c91922b1e2b61f69a3b10a4789f74371d02023b0d58597417c95f4f5c3df019f1560101352bb266f2ed9a6aec319b52d0ce8e5417823567458ac7c67dde336de
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
- gem 'guachiman'
12
+ ```ruby
13
+ gem 'guachiman'
14
+ ```
13
15
 
14
16
  And then execute:
15
17
 
16
- $ bundle
18
+ ```bash
19
+ $ bundle
20
+ ```
17
21
 
18
22
  Or install it yourself as:
19
23
 
20
- $ gem install guachiman
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
- The method `allow` takes a controller params key and an array of actions. The method `allow_param` takes a model params key and an array of attributes. The method `allow_all!` is a convinience method to allow all controlles, actions and parameteres.
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
- not_authorized
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
- session[:next] = request.url unless current_user
33
- redirect_to root_path, alert: t(current_user ? 'flashes.not_authorized' : 'flashes.please_login')
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
@@ -1,3 +1,3 @@
1
1
  module Guachiman
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guachiman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodriguez