martinet 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -14
- data/lib/martinet/configuration.rb +25 -0
- data/lib/martinet/impersonation.rb +19 -0
- data/lib/martinet/session.rb +6 -1
- data/lib/martinet/version.rb +1 -1
- data/lib/martinet.rb +2 -2
- data/martinet.gemspec +2 -5
- metadata +6 -59
- data/Appraisals +0 -15
- data/gemfiles/activerecord_4_1.gemfile +0 -7
- data/gemfiles/activerecord_4_2.gemfile +0 -7
- data/gemfiles/activerecord_5_0.gemfile +0 -7
- data/gemfiles/activerecord_head.gemfile +0 -7
- data/lib/martinet/active_record_serializer.rb +0 -32
- data/lib/martinet/railtie.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1de4f471176c1c86eece0c53584cd75b1ba56da9
|
4
|
+
data.tar.gz: 80bd2e824db0fb16eb38756e1ab7d4a861004a21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63ad172d0fbfbc13c83dc1c9793fcb56f301787d30089971f7f7198cf5af35bb5a1dcf9ca597e50d2e4502dca51bb41f01cec69b8ac2d316bb50a7f78d7af14e
|
7
|
+
data.tar.gz: fc8a7dce2c1298b2999dbead463fc25138bd7641e311e5b6ba11c7868f2fe87bc53f38b733d779df02d785dbfb09c7647b21bc63638e68f6db27909b302846de
|
data/.travis.yml
CHANGED
@@ -11,20 +11,6 @@ before_install:
|
|
11
11
|
- gem update bundler
|
12
12
|
- gem cleanup bundler
|
13
13
|
|
14
|
-
gemfile:
|
15
|
-
- gemfiles/activerecord_4_1.gemfile
|
16
|
-
- gemfiles/activerecord_4_2.gemfile
|
17
|
-
- gemfiles/activerecord_5_0.gemfile
|
18
|
-
- gemfiles/activerecord_head.gemfile
|
19
|
-
|
20
|
-
matrix:
|
21
|
-
fast_finish: true
|
22
|
-
exclude:
|
23
|
-
- gemfile: gemfiles/activerecord_head.gemfile
|
24
|
-
rvm: 2.1.10
|
25
|
-
- gemfile: gemfiles/activerecord_5_0.gemfile
|
26
|
-
rvm: 2.1.10
|
27
|
-
|
28
14
|
branches:
|
29
15
|
only:
|
30
16
|
- master
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Martinet
|
2
|
+
class << self
|
3
|
+
attr_writer :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.reset
|
11
|
+
@configuration = Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :enable_impersonation
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@enable_impersonation = false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Martinet
|
2
|
+
module Impersonation
|
3
|
+
def impersonate!(user, impersonator_scope: nil)
|
4
|
+
impersonator = current_user(scope: impersonator_scope)
|
5
|
+
sign_in!(impersonator, scope: :impersonator)
|
6
|
+
sign_in!(user)
|
7
|
+
end
|
8
|
+
|
9
|
+
def impersonating?
|
10
|
+
signed_in?(scope: :impersonator)
|
11
|
+
end
|
12
|
+
|
13
|
+
def unmask!
|
14
|
+
impersonator = current_user(scope: :impersonator)
|
15
|
+
sign_out!
|
16
|
+
sign_in!(impersonator)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/martinet/session.rb
CHANGED
@@ -2,6 +2,11 @@ module Martinet
|
|
2
2
|
# HTTP/Warden session-specific behavior.
|
3
3
|
class Session
|
4
4
|
def initialize(warden)
|
5
|
+
# TODO: Move this to Martinet::Impersonation class
|
6
|
+
if Martinet.configuration.enable_impersonation
|
7
|
+
class << self; include Impersonation; end
|
8
|
+
end
|
9
|
+
|
5
10
|
@warden = warden
|
6
11
|
end
|
7
12
|
|
@@ -10,7 +15,7 @@ module Martinet
|
|
10
15
|
end
|
11
16
|
|
12
17
|
def signed_in?(scope: nil)
|
13
|
-
@warden.
|
18
|
+
@warden.authenticated?(scope)
|
14
19
|
end
|
15
20
|
|
16
21
|
def sign_in!(user, *args)
|
data/lib/martinet/version.rb
CHANGED
data/lib/martinet.rb
CHANGED
data/martinet.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Tang Rufus']
|
10
10
|
spec.email = ['tangrufus@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = 'Authorization component for warden
|
13
|
-
spec.description = 'Authorization component for warden
|
12
|
+
spec.summary = 'Authorization component for warden'
|
13
|
+
spec.description = 'Authorization component for warden'
|
14
14
|
spec.homepage = 'https://github.com/TangRufus/martinet'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
@@ -25,9 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.11', '>= 1.11.2'
|
27
27
|
spec.add_development_dependency 'rake', '~> 11.1', '>= 11.1.2'
|
28
|
-
spec.add_development_dependency 'appraisal', '~> 2.1.0'
|
29
28
|
spec.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.4'
|
30
29
|
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5.0'
|
31
|
-
spec.add_development_dependency 'activerecord', '>= 4.0.13'
|
32
|
-
spec.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.11'
|
33
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: martinet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tang Rufus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: warden
|
@@ -70,20 +70,6 @@ dependencies:
|
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: 11.1.2
|
73
|
-
- !ruby/object:Gem::Dependency
|
74
|
-
name: appraisal
|
75
|
-
requirement: !ruby/object:Gem::Requirement
|
76
|
-
requirements:
|
77
|
-
- - "~>"
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: 2.1.0
|
80
|
-
type: :development
|
81
|
-
prerelease: false
|
82
|
-
version_requirements: !ruby/object:Gem::Requirement
|
83
|
-
requirements:
|
84
|
-
- - "~>"
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: 2.1.0
|
87
73
|
- !ruby/object:Gem::Dependency
|
88
74
|
name: minitest
|
89
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,41 +104,7 @@ dependencies:
|
|
118
104
|
- - "~>"
|
119
105
|
- !ruby/object:Gem::Version
|
120
106
|
version: 0.5.0
|
121
|
-
|
122
|
-
name: activerecord
|
123
|
-
requirement: !ruby/object:Gem::Requirement
|
124
|
-
requirements:
|
125
|
-
- - ">="
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
version: 4.0.13
|
128
|
-
type: :development
|
129
|
-
prerelease: false
|
130
|
-
version_requirements: !ruby/object:Gem::Requirement
|
131
|
-
requirements:
|
132
|
-
- - ">="
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: 4.0.13
|
135
|
-
- !ruby/object:Gem::Dependency
|
136
|
-
name: sqlite3
|
137
|
-
requirement: !ruby/object:Gem::Requirement
|
138
|
-
requirements:
|
139
|
-
- - "~>"
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version: '1.3'
|
142
|
-
- - ">="
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: 1.3.11
|
145
|
-
type: :development
|
146
|
-
prerelease: false
|
147
|
-
version_requirements: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '1.3'
|
152
|
-
- - ">="
|
153
|
-
- !ruby/object:Gem::Version
|
154
|
-
version: 1.3.11
|
155
|
-
description: Authorization component for warden and omniauth. Devise-less
|
107
|
+
description: Authorization component for warden
|
156
108
|
email:
|
157
109
|
- tangrufus@gmail.com
|
158
110
|
executables: []
|
@@ -164,19 +116,14 @@ files:
|
|
164
116
|
- ".hound.yml"
|
165
117
|
- ".rubocop.yml"
|
166
118
|
- ".travis.yml"
|
167
|
-
- Appraisals
|
168
119
|
- CODE_OF_CONDUCT.md
|
169
120
|
- Gemfile
|
170
121
|
- LICENSE.txt
|
171
122
|
- README.md
|
172
123
|
- Rakefile
|
173
|
-
- gemfiles/activerecord_4_1.gemfile
|
174
|
-
- gemfiles/activerecord_4_2.gemfile
|
175
|
-
- gemfiles/activerecord_5_0.gemfile
|
176
|
-
- gemfiles/activerecord_head.gemfile
|
177
124
|
- lib/martinet.rb
|
178
|
-
- lib/martinet/
|
179
|
-
- lib/martinet/
|
125
|
+
- lib/martinet/configuration.rb
|
126
|
+
- lib/martinet/impersonation.rb
|
180
127
|
- lib/martinet/session.rb
|
181
128
|
- lib/martinet/version.rb
|
182
129
|
- martinet.gemspec
|
@@ -204,5 +151,5 @@ rubyforge_project:
|
|
204
151
|
rubygems_version: 2.6.3
|
205
152
|
signing_key:
|
206
153
|
specification_version: 4
|
207
|
-
summary: Authorization component for warden
|
154
|
+
summary: Authorization component for warden
|
208
155
|
test_files: []
|
data/Appraisals
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
appraise 'activerecord-4-1' do
|
2
|
-
gem 'activerecord', '~> 4.1.0', '>= 4.1.15'
|
3
|
-
end
|
4
|
-
|
5
|
-
appraise 'activerecord-4-2' do
|
6
|
-
gem 'activerecord', '~> 4.2.0', '>= 4.2.6'
|
7
|
-
end
|
8
|
-
|
9
|
-
appraise 'activerecord-5-0' do
|
10
|
-
gem 'activerecord', '>= 5.0.0.beta3', '< 5.1'
|
11
|
-
end
|
12
|
-
|
13
|
-
appraise 'activerecord-head' do
|
14
|
-
gem 'activerecord', github: 'rails/rails'
|
15
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Martinet
|
2
|
-
class ActiveRecordSerializer
|
3
|
-
def self.serialize(record:)
|
4
|
-
return record unless serializable?(record: record)
|
5
|
-
{ klass: record.class.name, record_id: record.id }
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.deserialize(object_hash:)
|
9
|
-
record_for(object_hash: object_hash) || object_hash
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.record_for(object_hash:)
|
13
|
-
return unless deserializable?(object_hash: object_hash)
|
14
|
-
|
15
|
-
record_klass = object_hash[:klass].safe_constantize
|
16
|
-
record_klass.find_by(id: object_hash[:record_id])
|
17
|
-
end
|
18
|
-
|
19
|
-
# FIXME: Refactor this method
|
20
|
-
def self.serializable?(record:)
|
21
|
-
record.respond_to?(:id) && record.id.presence && record.class.respond_to?(:find_by)
|
22
|
-
end
|
23
|
-
|
24
|
-
# FIXME: Refactor this method, maybe a rescue block?
|
25
|
-
def self.deserializable?(object_hash:)
|
26
|
-
valid = [:klass, :record_id].all? do |k|
|
27
|
-
object_hash.respond_to?(:key) && object_hash.key?(k) && object_hash[k].presence
|
28
|
-
end
|
29
|
-
valid && object_hash[:klass].safe_constantize.respond_to?(:find_by)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/martinet/railtie.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'warden'
|
2
|
-
require 'martinet/active_record_serializer'
|
3
|
-
|
4
|
-
module Martinet
|
5
|
-
class Railtie < Rails::Railtie
|
6
|
-
# TODO: Test me
|
7
|
-
initializer 'martinet.setup_warden-manager' do |app|
|
8
|
-
app.middleware.use Warden::Manager do |config|
|
9
|
-
config.serialize_into_session do |user|
|
10
|
-
ActiveRecordSerializer.serialize(record: user)
|
11
|
-
end
|
12
|
-
|
13
|
-
config.serialize_from_session do |object_hash|
|
14
|
-
ActiveRecordSerializer.deserialize(object_hash: object_hash)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|