cul_omniauth 0.2.0 → 0.3.1

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: 12e145d88c005c6cab678e19eb93b17cff6e09e9
4
- data.tar.gz: 262436496792653e2a1cf76e3bc76be6b94ede92
3
+ metadata.gz: c2f5e75dcb59b3b93419a19e1d32b6cfb0fdf251
4
+ data.tar.gz: 90baff7e34e64d4e86343977f47389c956b1780d
5
5
  SHA512:
6
- metadata.gz: ff406c2659ce8e17f061647727f46541acf000c080eef7b13ecaf807b338c39dc012424f132d7e44c30d1b61384fcaf76770bd10d938942c835ac8201ef999ba
7
- data.tar.gz: 57078dcf843567d0dce62a6bd1bd06619a099036d59384907c2888170725b0d819b6e396b039fcfbc955e4e877bff4e33fb130fa20e70985ad207a13109ae36c
6
+ metadata.gz: c73212bcb608d24654e4188575c72925012d9a0a60807e2354acea1a246f9e147995bb47312e4118c6ddba70ec3469d4cc29f76a092eaf89be77d7552ce18589
7
+ data.tar.gz: c8761a6dfd0805bc324f3e125b98736c6bc49896c020fb4245acc11528a8ab5a512a4f916be827764edc368d4fc51a5f4ceef4dbe92b040eeb45117885812ba8
@@ -0,0 +1,50 @@
1
+ module Cul::Omniauth::AuthorizingController
2
+ extend ActiveSupport::Concern
3
+
4
+ def store_location
5
+ session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
6
+ end
7
+
8
+ def redirect_back_or_default(default)
9
+ redirect_to(session[:return_to] || default)
10
+ session[:return_to] = nil
11
+ end
12
+
13
+ def require_user
14
+ unless current_user
15
+ store_location
16
+ redirect_to_login
17
+ return false
18
+ end
19
+ end
20
+
21
+ def require_no_user
22
+ if current_user
23
+ store_location
24
+ flash[:notice] = "You must be logged out to access this page"
25
+ redirect_to root_url
26
+ return false
27
+ end
28
+ end
29
+
30
+ def authorize_action
31
+ if can? :"#{controller_name.to_s}##{params[:action].to_s}", Cul::Omniauth::AbilityProxy.new
32
+ return true
33
+ else
34
+ if current_user
35
+ access_denied
36
+ return false
37
+ end
38
+ end
39
+ store_location
40
+ redirect_to_login
41
+ return false
42
+ end
43
+
44
+ def access_denied(url=nil)
45
+ flash[:notice] = "You not permitted to access this page"
46
+ redirect_to url || root_url
47
+ return false
48
+ end
49
+
50
+ end
@@ -30,7 +30,13 @@ module Cul::Omniauth::Callbacks
30
30
  redirect_to root_url
31
31
  end
32
32
  end
33
+
33
34
  def affiliations(user, affils)
34
35
  end
36
+
37
+ def after_sign_in_path_for(resource)
38
+ session[:return_to] || super
39
+ end
40
+
35
41
  protected :find_user
36
42
  end
@@ -3,9 +3,16 @@ module Cul::Omniauth::Abilities
3
3
  EMPTY = [].freeze
4
4
  def initialize(user, opts={})
5
5
  @user = user || User.new
6
- self.class.config.select {|role,config| user.role? role }.each do |role, config|
6
+ if user
7
+ role_permissions = self.class.config.select {|role,config| user.role? role }
8
+ else
9
+ role_permissions = {:'*' => self.class.config.fetch(:*,EMPTY)}
10
+ end
11
+ puts role_permissions.inspect
12
+ role_permissions.each do |role, config|
7
13
  config.fetch(:can,EMPTY).each do |action, conditions|
8
14
  if conditions.blank?
15
+ puts "can #{action}, :all"
9
16
  can action, :all
10
17
  else
11
18
  can action, Cul::Omniauth::AbilityProxy do |proxy|
@@ -45,6 +52,7 @@ module Cul::Omniauth::Abilities
45
52
  context.eql? value
46
53
  end
47
54
  def self.in?(context, value)
55
+ puts "#{context.inspect} #{value}"
48
56
  (Array(value) & Array(context)).size > 0
49
57
  end
50
58
  end
@@ -15,7 +15,7 @@ module Cul::Omniauth::Users
15
15
  end
16
16
 
17
17
  def role? role_sym
18
- role_sym == :guest
18
+ role_sym == :*
19
19
  end
20
20
 
21
21
  def ability
@@ -1,5 +1,5 @@
1
1
  module Cul
2
2
  module Omniauth
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cul_omniauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - barmintor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -105,6 +105,7 @@ files:
105
105
  - Rakefile
106
106
  - app/assets/javascripts/cul/omniauth/application.js
107
107
  - app/assets/stylesheets/cul/omniauth/application.css
108
+ - app/controllers/concerns/cul/omniauth/authorizing_controller.rb
108
109
  - app/controllers/concerns/cul/omniauth/callbacks.rb
109
110
  - app/controllers/concerns/cul/omniauth/remote_ip_ability.rb
110
111
  - app/controllers/cul/omniauth/application_controller.rb