guachiman 0.1.0 → 0.1.2

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.
data/guachiman.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Francesco Rodriguez', 'Gustavo Beathyate']
10
10
  spec.email = ['lrodriguezsanc@gmail.com', 'gustavo@epiclabs.pe']
11
11
  spec.summary = 'Basic authorization library'
12
- spec.description = spec.summary << ' inspired in Ryan Bates code'
12
+ spec.description = "#{spec.summary} based on Ryan Bates' Railscasts #385 and #386"
13
13
  spec.homepage = 'https://github.com/epiclabs/guachiman'
14
14
  spec.license = 'MIT'
15
15
 
@@ -1,6 +1,6 @@
1
1
  class Permission
2
2
  include Guachiman::Permissions
3
- # include Guachiman::Params
3
+ include Guachiman::Params
4
4
 
5
5
  def initialize user
6
6
  if user.nil?
data/lib/guachiman.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'guachiman/version'
2
2
  require 'guachiman/permissions'
3
3
  require 'guachiman/params'
4
- require 'active_record'
5
- require 'strong_parameters'
6
4
 
7
5
  if defined? Rails
8
6
  require 'guachiman/rails/railtie'
9
7
  require 'guachiman/rails/permissible'
8
+ require 'strong_parameters'
9
+ require 'active_record'
10
10
 
11
11
  ActiveRecord::Base.send :include, ActiveModel::ForbiddenAttributesProtection
12
12
  end
@@ -40,7 +40,7 @@ module Guachiman
40
40
  params.permit!
41
41
  elsif write_allowed_params
42
42
  write_allowed_params.each do |resource, attributes|
43
- params[resource] = params[resource].permit(*attributes) if params[resource]
43
+ params[resource] = params[resource].permit(*attributes) if params[resource].respond_to? :permit
44
44
  end
45
45
  end
46
46
  end
@@ -4,6 +4,12 @@ module Guachiman
4
4
 
5
5
  included do
6
6
  before_filter :authorize
7
+ helper_method :current_user
8
+ helper_method :current_permission
9
+ end
10
+
11
+ def current_user
12
+ raise 'This method must be implemented'
7
13
  end
8
14
 
9
15
  def current_permission
@@ -14,12 +20,8 @@ module Guachiman
14
20
  nil
15
21
  end
16
22
 
17
- def current_user
18
- raise 'This method must be implemented'
19
- end
20
-
21
23
  def authorize
22
- if current_permission.allow? params[:controller], params[:action], current_resource
24
+ if current_permission.allow? controller_name, action_name, current_resource
23
25
  current_permission.permit_params! params
24
26
  else
25
27
  not_authorized
@@ -27,11 +29,8 @@ module Guachiman
27
29
  end
28
30
 
29
31
  def not_authorized
30
- if current_user
31
- redirect_to root_path, alert: t(:not_authorized)
32
- else
33
- redirect_to login_path, alert: t(:please_login)
34
- end
32
+ session[:next] = request.url unless current_user
33
+ redirect_to root_path, alert: t(current_user ? 'flashes.not_authorized' : 'flashes.please_login')
35
34
  end
36
35
  end
37
36
  end
@@ -1,3 +1,3 @@
1
1
  module Guachiman
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.2'
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.0
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-04 00:00:00.000000000 Z
13
+ date: 2013-06-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -124,7 +124,8 @@ dependencies:
124
124
  - - ! '>='
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
- description: Basic authorization library inspired in Ryan Bates code
127
+ description: ! 'Basic authorization library based on Ryan Bates'' Railscasts #385
128
+ and #386'
128
129
  email:
129
130
  - lrodriguezsanc@gmail.com
130
131
  - gustavo@epiclabs.pe
@@ -172,7 +173,7 @@ rubyforge_project:
172
173
  rubygems_version: 1.8.23
173
174
  signing_key:
174
175
  specification_version: 3
175
- summary: Basic authorization library inspired in Ryan Bates code
176
+ summary: Basic authorization library
176
177
  test_files:
177
178
  - test/generators/install_generator_test.rb
178
179
  - test/test_helper.rb