cul_omniauth 0.3.2 → 0.4.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: a955dd2cc9270430db92c8b03bec61389433d945
4
- data.tar.gz: 631f84ab0137bb08cba79631be673df44cb57f06
3
+ metadata.gz: d5c1805d9d83aa9df667abb8df5e5aed6c1a3421
4
+ data.tar.gz: a0d99e89e40921bff1d81724109fc97c84e336dc
5
5
  SHA512:
6
- metadata.gz: 7acc0a7d9c0fac857d28e5a9ef63894502dcbf9e8ade213cc387f254c7d31c75b3c2ed7fe65be36f3e46c2203eae239a5429b2b1e35770c0fffc94465c7bb050
7
- data.tar.gz: 11feb2c0e5c9065a59a370f73134cf08400ee213975a36a9a1183c65095b7498d8190f18014ec428debb7f5fadc955ff87e6effcb33eba1dd490717bb44949f8
6
+ metadata.gz: 5567910040ad0349764cac904e5f921afb7ff104862cfbfe77c79037aae0b76f675a50b11aa73c410f0dbfdc34b874840b1a7d8361b45560ee87514c3b9d5473
7
+ data.tar.gz: da1a4d534b2af97a107e8a3aef97ae126544c1fc56e5cb79711031aa93728ca96bee2b6b1e6ea9d4a3bc8a3e41c165f47f11393628066c9722ec014ff3567af8
@@ -18,7 +18,7 @@ module Cul::Omniauth::Callbacks
18
18
  find_method = "find_for_#{auth_type.downcase}".to_sym
19
19
  current_user ||= User.send(find_method,request.env["omniauth.auth"], current_user)
20
20
  affils = ["#{request.env["omniauth.auth"].uid}:users.cul.columbia.edu"]
21
- affils << "staff:cul.columbia.edu" if current_user.cul_staff?
21
+ affils << "staff:cul.columbia.edu" if current_user.respond_to?(:cul_staff?) and current_user.cul_staff?
22
22
  affils += (request.env["omniauth.auth"].extra.affiliations || [])
23
23
  affiliations(current_user,affils)
24
24
  session["devise.roles"] = affils
@@ -1,6 +1,6 @@
1
1
  module Cul::Omniauth::RemoteIpAbility
2
2
  extend ActiveSupport::Concern
3
3
  def current_ability
4
- @current_ability ||= Ability.new(current_user, remote_ip:request.remote_ip)
4
+ @current_ability ||= Ability.new(current_user, roles: session["devise.roles"], remote_ip:request.remote_ip)
5
5
  end
6
6
  end
@@ -1,26 +1,31 @@
1
1
  module Cul::Omniauth::Abilities
2
2
  extend ActiveSupport::Concern
3
- EMPTY = [].freeze
3
+ module Empty
4
+ HASH = {}.freeze
5
+ ARRAY = [].freeze
6
+ end
4
7
  def initialize(user=nil, opts={})
5
8
  @user = user || User.new
9
+ roles = opts[:roles] || Empty::HASH
6
10
  if user
7
- role_permissions = self.class.config.select {|role,config| user.role? role }
11
+ role_permissions = self.class.config.select do |role,config|
12
+ roles.include?(role) or user.role?(role)
13
+ end
14
+ role_permissions[:'*'] = self.class.config.fetch(:*,Empty::HASH)
8
15
  opts = {user_id: user.login}.merge(opts)
9
16
  else
10
- role_permissions = {:'*' => self.class.config.fetch(:*,EMPTY)}
17
+ role_permissions = {:'*' => self.class.config.fetch(:*,Empty::HASH)}
11
18
  end
12
- puts role_permissions.inspect
13
19
  role_permissions.each do |role, config|
14
- config.fetch(:can,EMPTY).each do |action, conditions|
20
+ config.fetch(:can,Empty::HASH).each do |action, conditions|
15
21
  if conditions.blank?
16
- puts "can #{action}, :all"
17
22
  can action, :all
18
23
  else
19
24
  can action, Cul::Omniauth::AbilityProxy do |proxy|
20
25
  combine_with = conditions.fetch(:combine_with,:and).to_sym
21
26
  r = (combine_with == :and)
22
27
  if !!proxy
23
- conditions.fetch(:if,EMPTY).each do |property, comparisons|
28
+ conditions.fetch(:if,Empty::HASH).each do |property, comparisons|
24
29
  p = value_for_property(proxy, property, opts)
25
30
  if combine_with == :and
26
31
  r &= !!p
@@ -29,7 +34,7 @@ module Cul::Omniauth::Abilities
29
34
  r ||= comparisons.detect {|c,v| Comparisons.send(c, p, v)}
30
35
  end
31
36
  end
32
- conditions.fetch(:unless,EMPTY).each do |property, comparisons|
37
+ conditions.fetch(:unless,Empty::HASH).each do |property, comparisons|
33
38
  p = value_for_property(proxy, property, opts)
34
39
  if p
35
40
  if combine_with == :and
@@ -51,7 +56,7 @@ module Cul::Omniauth::Abilities
51
56
  if proxy.respond_to? property_handle.to_sym
52
57
  property = proxy.send property_handle
53
58
  end
54
- property = opts.fetch(property_handle,EMPTY) if property.blank? || property.empty?
59
+ property = opts.fetch(property_handle,Empty::ARRAY) if property.blank? || property.empty?
55
60
  property
56
61
  end
57
62
  module Comparisons
@@ -59,11 +64,9 @@ module Cul::Omniauth::Abilities
59
64
  context.include? value
60
65
  end
61
66
  def self.eql?(context, value)
62
- puts "eql? #{context.inspect} #{value}"
63
67
  context.eql? value
64
68
  end
65
69
  def self.in?(context, value)
66
- puts "in? #{context.inspect} #{value}"
67
70
  (Array(value) & Array(context)).size > 0
68
71
  end
69
72
  end
@@ -1,5 +1,5 @@
1
1
  module Cul
2
2
  module Omniauth
3
- VERSION = "0.3.2"
3
+ VERSION = "0.4.0"
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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - barmintor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails