guachiman-rails 1.0.0.pre → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -3
- data/lib/generators/guachiman/install/install_generator.rb +12 -0
- data/lib/generators/guachiman/{rails/install → install}/templates/authorization.rb +0 -0
- data/lib/guachiman-rails.rb +2 -0
- data/lib/guachiman/rails/authorizable.rb +3 -2
- data/lib/guachiman/rails/railtie.rb +0 -1
- data/lib/guachiman/rails/version.rb +1 -1
- data/test/generators/install_generator_test.rb +4 -4
- metadata +5 -5
- data/lib/generators/guachiman/rails/install/install_generator.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca694ac3fec1d1179952e41b68a276118b4764e1
|
4
|
+
data.tar.gz: 27de1eaba78fcfc39d17acb22f274d02462e9941
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fb2084f06f27022c2d3872179c677a9bcc25d89731d32d676e724c6abcc8790c1fa13d8569374cb4f0cdc6a0fe82a4455afa6438260a4096b55f65e640f628e
|
7
|
+
data.tar.gz: 4d1a43dfc5090efbbefe9994c63c74891f761493d9c565b67085341c36c28073adfe62a1ba85352560327946f8cdc69d58921f5442e558a2bf09a21d92c57984
|
data/README.md
CHANGED
@@ -32,6 +32,11 @@ Or install it directly:
|
|
32
32
|
$ gem install guachiman-rails
|
33
33
|
```
|
34
34
|
|
35
|
+
Upgrade Notice
|
36
|
+
--------------
|
37
|
+
|
38
|
+
**Version 1.0.0 is incompatible with version =< 0.3.2.**
|
39
|
+
|
35
40
|
Usage
|
36
41
|
-----
|
37
42
|
|
@@ -65,21 +70,23 @@ end
|
|
65
70
|
|
66
71
|
### To handle what happens after the authorization takes place
|
67
72
|
|
68
|
-
This is the default implementation.
|
73
|
+
This is the default implementation. You can modify it or break it up if you need to authorise
|
74
|
+
parameters, redirect to a different page or use a different flash key (for example).
|
69
75
|
|
70
76
|
```ruby
|
71
77
|
def after_authorization(authorized)
|
72
78
|
return true if authorized
|
73
79
|
|
74
80
|
if request.get? && !request.xhr?
|
75
|
-
|
81
|
+
session[:next] = request.url
|
82
|
+
redirect_to root_path, alert: t(:unauthorized)
|
76
83
|
else
|
77
84
|
render nothing: true, status: :unauthorized
|
78
85
|
end
|
79
86
|
end
|
80
87
|
```
|
81
88
|
|
82
|
-
|
89
|
+
Now you can describe your authorization object in this way:
|
83
90
|
|
84
91
|
```ruby
|
85
92
|
class Authorization
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Guachiman
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
desc 'Create Authorization model'
|
5
|
+
source_root File.expand_path '../templates', __FILE__
|
6
|
+
|
7
|
+
def copy_authorization_model
|
8
|
+
template 'authorization.rb', 'app/models/authorization.rb'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
data/lib/guachiman-rails.rb
CHANGED
@@ -23,7 +23,7 @@ module Guachiman
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def authorize
|
26
|
-
authorized = authorization.allow?(controller_name, action_name, current_resource)
|
26
|
+
authorized = authorization.allow?(controller_name.to_sym, action_name.to_sym, current_resource)
|
27
27
|
|
28
28
|
after_authorization(authorized)
|
29
29
|
end
|
@@ -32,7 +32,8 @@ module Guachiman
|
|
32
32
|
return true if authorized
|
33
33
|
|
34
34
|
if request.get? && !request.xhr?
|
35
|
-
|
35
|
+
session[:next] = request.url
|
36
|
+
redirect_to root_path, alert: t(:unauthorized)
|
36
37
|
else
|
37
38
|
render nothing: true, status: :unauthorized
|
38
39
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'rails/generators/test_case'
|
3
|
-
require 'generators/guachiman/
|
3
|
+
require 'generators/guachiman/install/install_generator'
|
4
4
|
|
5
5
|
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
6
|
DESTINATION = File.expand_path File.join(File.dirname(__FILE__), '..', '..', 'tmp')
|
7
|
-
FileUtils.mkdir_p
|
7
|
+
FileUtils.mkdir_p(DESTINATION) unless Dir.exist?(DESTINATION)
|
8
8
|
|
9
9
|
destination DESTINATION
|
10
10
|
|
11
|
-
tests Guachiman::
|
11
|
+
tests Guachiman::Generators::InstallGenerator
|
12
12
|
setup :prepare_destination
|
13
13
|
|
14
14
|
def prepare_destination
|
@@ -23,7 +23,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
|
|
23
23
|
run_generator
|
24
24
|
|
25
25
|
assert_file 'app/models/authorization.rb' do |f|
|
26
|
-
assert_match
|
26
|
+
assert_match(/include Guachiman/, f)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guachiman-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesco Rodriguez
|
@@ -126,8 +126,8 @@ files:
|
|
126
126
|
- README.md
|
127
127
|
- Rakefile
|
128
128
|
- guachiman-rails.gemspec
|
129
|
-
- lib/generators/guachiman/
|
130
|
-
- lib/generators/guachiman/
|
129
|
+
- lib/generators/guachiman/install/install_generator.rb
|
130
|
+
- lib/generators/guachiman/install/templates/authorization.rb
|
131
131
|
- lib/guachiman-rails.rb
|
132
132
|
- lib/guachiman/rails/authorizable.rb
|
133
133
|
- lib/guachiman/rails/railtie.rb
|
@@ -149,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- - "
|
152
|
+
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
154
|
+
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
157
|
rubygems_version: 2.4.1
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Guachiman
|
2
|
-
module Rails
|
3
|
-
module Generators
|
4
|
-
class InstallGenerator < ::Rails::Generators::Base
|
5
|
-
desc 'Create Authorization model'
|
6
|
-
source_root File.expand_path '../templates', __FILE__
|
7
|
-
|
8
|
-
def copy_authorization_model
|
9
|
-
template 'authorization.rb', 'app/models/authorization.rb'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|