timber 2.0.10 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/timber/integrations/rack/user_context.rb +50 -12
- data/lib/timber/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c92caecf236aae6f47636ea5646c3822a31fa51
|
4
|
+
data.tar.gz: df5d9292f27cba1fa0405a919002434eb4d91bdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d1617ab8a68cb5ceef91036f196cc1fecd97f09236a2a06319dbb69c1b3e9a9c606ba98a214dc266e73ccc5f277e454939fb2acf2e19da9e6259ad8ce8005aa
|
7
|
+
data.tar.gz: ed1da42f194b9ce03c5e07c7b073306b1de59e0715e9721f3859efdb2e1a974dcb3de76a86c7271b6f38831eed2036bec52621d4b95f050b6454913f6d3ae11d
|
@@ -8,22 +8,30 @@ module Timber
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
+
debug { "#{self.class.name} - Starting user context" }
|
11
12
|
user_hash = get_user_hash(env)
|
12
13
|
if user_hash
|
14
|
+
debug { "#{self.class.name} - User hash found: #{user_hash.inspect}" }
|
13
15
|
context = Contexts::User.new(user_hash)
|
14
16
|
CurrentContext.with(context) do
|
15
17
|
@app.call(env)
|
16
18
|
end
|
17
19
|
else
|
20
|
+
debug { "#{self.class.name} - User hash not found" }
|
18
21
|
@app.call(env)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
25
|
private
|
23
26
|
def get_user_hash(env)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
get_omniauth_user_hash(env) ||
|
28
|
+
get_warden_user_hash(env) ||
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_omniauth_user_hash(env)
|
33
|
+
if env['omniauth.auth']
|
34
|
+
debug { "#{self.class.name} - Omniauth hash present #{env['omniauth.auth'].inspect}" }
|
27
35
|
auth_hash = env['omniauth.auth']
|
28
36
|
info = auth_hash['info']
|
29
37
|
|
@@ -33,23 +41,42 @@ module Timber
|
|
33
41
|
email: info['email']
|
34
42
|
}
|
35
43
|
else
|
44
|
+
debug { "#{self.class.name} - Omniauth hash not present" }
|
36
45
|
nil
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
def get_warden_user_hash(env)
|
50
|
+
if env['warden']
|
51
|
+
debug { "#{self.class.name} - Warden object present #{env['warden'].inspect}" }
|
52
|
+
user = env['warden'].user
|
53
|
+
if user
|
54
|
+
debug { "#{self.class.name} - Warden user object #{env['warden'].user.inspect}" }
|
55
|
+
id = try_user_id(user)
|
56
|
+
name = try_user_name(user)
|
57
|
+
email = try_user_email(user)
|
58
|
+
|
59
|
+
if id || name || email
|
60
|
+
debug { "#{self.class.name} - At least one warden user attribute was present" }
|
61
|
+
{id: id, name: name, email: email}
|
62
|
+
else
|
63
|
+
debug { "#{self.class.name} - No warden user attributes were present" }
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
else
|
67
|
+
debug { "#{self.class.name} - Warden user object not present, not logged in" }
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
else
|
71
|
+
nil
|
72
|
+
end
|
46
73
|
end
|
47
74
|
|
48
|
-
def
|
75
|
+
def try_user_id(user)
|
49
76
|
user.respond_to?(:id) ? user.id : nil
|
50
77
|
end
|
51
78
|
|
52
|
-
def
|
79
|
+
def try_user_name(user)
|
53
80
|
if user.respond_to?(:name) && user.name.is_a?(String)
|
54
81
|
user.name
|
55
82
|
elsif user.respond_to?(:first_name) && user.first_name.is_a?(String) && user.respond_to?(:last_name) && user.last_name.is_a?(String)
|
@@ -59,13 +86,24 @@ module Timber
|
|
59
86
|
end
|
60
87
|
end
|
61
88
|
|
62
|
-
def
|
89
|
+
def try_user_email(user)
|
63
90
|
if user.respond_to?(:email) && user.email.is_a?(String)
|
64
91
|
user.email
|
65
92
|
else
|
66
93
|
nil
|
67
94
|
end
|
68
95
|
end
|
96
|
+
|
97
|
+
def debug_logger
|
98
|
+
Timber::Config.instance.debug_logger
|
99
|
+
end
|
100
|
+
|
101
|
+
def debug(&block)
|
102
|
+
if debug_logger
|
103
|
+
message = yield
|
104
|
+
debug_logger.debug(message)
|
105
|
+
end
|
106
|
+
end
|
69
107
|
end
|
70
108
|
end
|
71
109
|
end
|
data/lib/timber/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timber Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|