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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72a97714f50f5b834978ba9287641427f33f9df6
4
- data.tar.gz: 451b38c810c615d1c92b8e7aec546c64a710b799
3
+ metadata.gz: 1de4f471176c1c86eece0c53584cd75b1ba56da9
4
+ data.tar.gz: 80bd2e824db0fb16eb38756e1ab7d4a861004a21
5
5
  SHA512:
6
- metadata.gz: c42105d13b539ef194d31d41e6a43c86ee0d1b23c6aa2162599081644c70484e486ac0587bad212222111afc626f68fca07cc7fa58b3c675ff596d14c91ad5dd
7
- data.tar.gz: 5f55f44421caf79ed0172b00b3cb8efd6306209a3dba80606d9932a4249ceebb99804040ff8adc09cd76360d69fd897a3d12578d2573626639c8c8ee85d7d4db
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
@@ -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.user(scope)
18
+ @warden.authenticated?(scope)
14
19
  end
15
20
 
16
21
  def sign_in!(user, *args)
@@ -1,3 +1,3 @@
1
1
  module Martinet
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
data/lib/martinet.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'martinet/version'
2
+ require 'martinet/configuration'
2
3
  require 'martinet/session'
4
+ require 'martinet/impersonation'
3
5
 
4
6
  module Martinet
5
7
  end
6
-
7
- require 'martinet/railtie' if defined?(Rails)
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 and omniauth. Devise-less'
13
- spec.description = 'Authorization component for warden and omniauth. Devise-less'
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.3
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-22 00:00:00.000000000 Z
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
- - !ruby/object:Gem::Dependency
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/active_record_serializer.rb
179
- - lib/martinet/railtie.rb
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 and omniauth. Devise-less
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,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1.0", ">= 4.1.15"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.0", ">= 4.2.6"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", ">= 5.0.0.beta3", "< 5.1"
6
-
7
- gemspec :path => "../"
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", :github => "rails/rails"
6
-
7
- gemspec :path => "../"
@@ -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
@@ -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