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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ff0bc3ea49cd25fa5316275c91f4294ecd2a204
4
- data.tar.gz: 587e98a3eebbb0bc1c0bc3e5053e83a93e77626b
3
+ metadata.gz: ca694ac3fec1d1179952e41b68a276118b4764e1
4
+ data.tar.gz: 27de1eaba78fcfc39d17acb22f274d02462e9941
5
5
  SHA512:
6
- metadata.gz: 7a45afbcae201def6c8e3292fa4d16d65d6e42179b2550041d191af5757ca62ae34e8a2572020efd2800c146c081b7c9ec203598635dd20b082c71b80e97a9fb
7
- data.tar.gz: c66a6871dfbabf18fff46c89b4dca4fd3150b2e7b7c91c1a19ccbc9db82ed77183bb4f2541861c5f723142f3904b37df5d4a62226b2d5f132d3a49c09b95756a
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
- redirect_to root_path, alert: t(:not_authorized)
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
- That's it, now you can describe your authorization object in this way:
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
@@ -1,2 +1,4 @@
1
+ require 'guachiman'
1
2
  require 'guachiman/rails/version'
2
3
  require 'guachiman/rails/railtie'
4
+ require 'guachiman/rails/authorizable'
@@ -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
- redirect_to root_path, alert: t(:not_authorized)
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,5 +1,4 @@
1
1
  require 'rails'
2
- require 'authorizable'
3
2
 
4
3
  module Guachiman
5
4
  module Rails
@@ -1,5 +1,5 @@
1
1
  module Guachiman
2
2
  module Rails
3
- VERSION = '1.0.0.pre'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -1,14 +1,14 @@
1
1
  require 'test_helper'
2
2
  require 'rails/generators/test_case'
3
- require 'generators/guachiman/rails/install/install_generator'
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 DESTINATION unless Dir.exist? DESTINATION
7
+ FileUtils.mkdir_p(DESTINATION) unless Dir.exist?(DESTINATION)
8
8
 
9
9
  destination DESTINATION
10
10
 
11
- tests Guachiman::Rails::Generators::InstallGenerator
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 /include Guachiman/, f
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.pre
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/rails/install/install_generator.rb
130
- - lib/generators/guachiman/rails/install/templates/authorization.rb
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: 1.3.1
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