proxes 0.4.4 → 0.5.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: 20d593cfefd6a398b5dcbc2d25708c06631353ca
4
- data.tar.gz: c76a06e2c8e63ad15d6b8870ab48a302b89126a0
3
+ metadata.gz: 4b2307d1a51918d135d69e58913c1416dc5a7e99
4
+ data.tar.gz: 6a6c9798c68eca09df64e5c06433149ff084b357
5
5
  SHA512:
6
- metadata.gz: 5216a08a4b1fa8424c000e06b911d4607b8e6f9ca79ae664d819e3f494c4fecab032794e804bea4e40f4d6c300d7290656d276d00b31b7801b7c50fd85d5471f
7
- data.tar.gz: 88d5fa844230f66b0b021895c7e110f5c8ec5293e5855493e94aaa34a02d4f19319ce2fca6b2db5a75951cb1bc1a1441d80f5d7f36ce5a254a222b8306ec9403
6
+ metadata.gz: 6df9bd467c07d6919cb6b7f9a28c32f6fb50b70baba309e294b77594e57e9b8f042c4385902773aacee6675596a3ac04cda0824db3e9c731e42b8da73b7a5429
7
+ data.tar.gz: 5dd4b6ad24059e81e1e643e712a438f5796ffa0680a56e2fa409655d252e07ce597651774ef7f816dbd212db50acec3f54fbaa4f31ee755687741ea77d50b548
data/Gemfile.ci CHANGED
@@ -1,15 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
- # Specify your gem's dependencies in proxes.gemspec
4
4
  gemspec
5
5
 
6
6
  gem 'sqlite3'
7
- gem 'simplecov'
7
+ gem 'simplecov', '~> 0.13.0'
8
8
  gem 'codeclimate-test-reporter', '~> 1.0.0'
9
+
9
10
  if RUBY_VERSION < '2.1'
11
+ gem 'sidekiq', '3.0.0'
10
12
  gem 'activesupport', '<4.0.0'
11
13
  gem 'omniauth', '~>1.4.2'
12
14
  elsif RUBY_VERSION < '2.2.0'
15
+ gem 'sidekiq', '4.0.0'
13
16
  gem 'activesupport', '<5.0.0'
14
17
  else
15
18
  gem 'activesupport'
@@ -11,6 +11,10 @@ module ProxES
11
11
  set view_location: nil
12
12
  set track_actions: false
13
13
 
14
+ before do
15
+ check_basic
16
+ end
17
+
14
18
  # List
15
19
  get '/', provides: [:html, :json] do
16
20
  authorize settings.model_class, :list
@@ -25,11 +29,12 @@ module ProxES
25
29
  locals: { list: list, title: heading(:list), actions: actions }
26
30
  end
27
31
  format.json do
32
+ # TODO: Add links defined by actions (New #{heading})
28
33
  {
29
- 'items' => list.map(&:values),
34
+ 'items' => list.map(&:for_json),
30
35
  'page' => params[:page],
31
- 'count' => params[:count],
32
- 'total' => list.to_a.size
36
+ 'count' => list.count,
37
+ 'total' => dataset.count
33
38
  }.to_json
34
39
  end
35
40
  end
@@ -82,7 +87,10 @@ module ProxES
82
87
  haml :"#{view_location}/display",
83
88
  locals: { entity: entity, title: heading, actions: actions }
84
89
  end
85
- format.json { entity.values.to_json }
90
+ format.json do
91
+ # TODO: Add links defined by actions (Edit #{heading})
92
+ entity.for_json.to_json
93
+ end
86
94
  end
87
95
  end
88
96
 
@@ -118,12 +118,25 @@ module ProxES
118
118
 
119
119
  identity = entity.identity.first
120
120
 
121
+ unless params['password'] == params['password_confirmation']
122
+ flash[:warning] = 'Password didn\'t match'
123
+ return redirect back
124
+ end
125
+
126
+ unless current_user.super_admin? || identity.authenticate(params['old_password'])
127
+ log_action("#{dehumanized}_update_password_failed".to_sym) if settings.track_actions
128
+ flash[:danger] = 'Old Password didn\'t match'
129
+ return redirect back
130
+ end
131
+
121
132
  values = permitted_attributes(Identity, :create)
122
133
  identity.set values
123
134
  if identity.valid? && identity.save
124
135
  log_action("#{dehumanized}_update_password".to_sym) if settings.track_actions
125
136
  flash[:success] = 'Password Updated'
126
137
  redirect back
138
+ elsif current_user.super_admin?
139
+ haml :"#{view_location}/display", locals: { entity: entity, identity: identity, title: heading }
127
140
  else
128
141
  haml :"#{view_location}/profile", locals: { entity: entity, identity: identity, title: heading }
129
142
  end
@@ -15,6 +15,13 @@ module ProxES
15
15
  full_path = source_request.fullpath == '' ? URI.parse(env['REQUEST_URI']).request_uri : source_request.fullpath
16
16
  target_request = Net::HTTP.const_get(source_request.request_method.capitalize).new(full_path)
17
17
 
18
+ if target_request.request_body_permitted? && source_request.body
19
+ target_request.body_stream = source_request.body
20
+ target_request.content_length = source_request.content_length.to_i
21
+ target_request.content_type = source_request.content_type if source_request.content_type
22
+ target_request.body_stream.rewind
23
+ end
24
+
18
25
  http = Net::HTTP.new(backend.host, backend.port)
19
26
  target_response = http.request(target_request)
20
27
 
@@ -35,7 +35,7 @@ module ProxES
35
35
  return unless auth.provided?
36
36
  return unless auth.basic?
37
37
 
38
- identity = ProxES::Identity.find(username: auth.credentials[0])
38
+ identity = ::ProxES::Identity.find(username: auth.credentials[0])
39
39
  raise NotAuthenticated unless identity
40
40
  self.current_user = identity.user if identity.authenticate(auth.credentials[1])
41
41
  end
@@ -40,9 +40,6 @@ module ProxES
40
40
  end
41
41
 
42
42
  def view_location
43
- p settings.model_class
44
- p 'asd'
45
- p settings.view_location
46
43
  settings.view_location || underscore(pluralize(demodulize(settings.model_class)))
47
44
  end
48
45
  end
@@ -8,6 +8,7 @@ module ProxES
8
8
 
9
9
  def method_missing(method, *args)
10
10
  vals = { action: method }
11
+ return unless args[0].is_a? Hash
11
12
  vals[:user] = args[0][:user] if args[0] && args[0].key?(:user)
12
13
  vals[:details] = args[0][:details] if args[0] && args[0].key?(:details)
13
14
  @mutex.synchronize { AuditLog.create vals }
@@ -3,7 +3,8 @@
3
3
  require 'proxes/models/base'
4
4
 
5
5
  module ProxES
6
- class AuditLog < Base
6
+ class AuditLog < Sequel::Model
7
+ include ProxES::Base
7
8
  many_to_one :user
8
9
 
9
10
  def validate
@@ -1,3 +1,9 @@
1
1
  require 'sequel'
2
2
 
3
- ProxES::Base = Class.new(Sequel::Model)
3
+ module ProxES
4
+ module Base
5
+ def for_json
6
+ values
7
+ end
8
+ end
9
+ end
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'bcrypt'
3
4
  require 'proxes/models/base'
4
5
  require 'omniauth-identity'
5
6
  require 'active_support'
6
7
  require 'active_support/core_ext/object/blank'
7
8
 
8
9
  module ProxES
9
- class Identity < Base
10
+ class Identity < Sequel::Model
11
+ include ProxES::Base
10
12
  many_to_one :user
11
13
 
12
14
  attr_accessor :password, :password_confirmation
@@ -3,7 +3,9 @@
3
3
  require 'proxes/models/base'
4
4
 
5
5
  module ProxES
6
- class Permission < Base
6
+ class Permission < Sequel::Model
7
+ include ProxES::Base
8
+
7
9
  many_to_one :role
8
10
  many_to_one :user
9
11
 
@@ -3,7 +3,9 @@
3
3
  require 'proxes/models/base'
4
4
 
5
5
  module ProxES
6
- class Role < Base
6
+ class Role < Sequel::Model
7
+ include ProxES::Base
8
+
7
9
  many_to_many :users
8
10
  one_to_many :permissions
9
11
 
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'proxes/models/base'
4
- require 'bcrypt'
5
4
  require 'digest/md5'
6
5
  require 'active_support'
7
6
  require 'active_support/core_ext/object/blank'
8
7
 
9
8
  # Why not store this in Elasticsearch?
10
9
  module ProxES
11
- class User < Base
10
+ class User < Sequel::Model
11
+ include ProxES::Base
12
+
12
13
  one_to_many :identity
13
14
  many_to_many :roles
14
15
  one_to_many :permissions
@@ -39,7 +39,7 @@ module ProxES
39
39
  if user && user.super_admin?
40
40
  scope
41
41
  else
42
- scope.where(id: -1)
42
+ scope.where(id: user.id)
43
43
  end
44
44
  end
45
45
  end
@@ -23,7 +23,7 @@ module ProxES
23
23
  end
24
24
 
25
25
  def error(message, code = 500)
26
- [code, { 'Content-Type' => 'application/json' }, ['{"error":"' + message + '}']]
26
+ [code, { 'Content-Type' => 'application/json' }, ['{"error":"' + message + '"}']]
27
27
  end
28
28
 
29
29
  def call(env)
@@ -52,7 +52,10 @@ module ProxES
52
52
  logger.debug '================================================================================'
53
53
 
54
54
  begin
55
- @app.call request.env
55
+ start = Time.now.to_f
56
+ result = @app.call request.env
57
+ broadcast(:call_completed, endpoint: request.endpoint, duration: Time.now.to_f - start)
58
+ result
56
59
  rescue Errno::EHOSTUNREACH
57
60
  error 'Could not reach Elasticsearch at ' + ENV['ELASTICSEARCH_URL']
58
61
  rescue Errno::ECONNREFUSED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ProxES
4
- VERSION = '0.4.4'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  end
@@ -28,21 +28,22 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'factory_girl'
29
29
  spec.add_development_dependency 'timecop'
30
30
 
31
- spec.add_dependency 'activesupport'
31
+ spec.add_dependency 'activesupport', '>= 3'
32
32
  spec.add_dependency 'rake', '~> 10.0'
33
- spec.add_dependency 'rack-contrib'
33
+ spec.add_dependency 'rack-contrib', '~> 1.4'
34
34
  spec.add_dependency 'sinatra', '~> 1.0'
35
- spec.add_dependency 'sinatra-flash'
36
- spec.add_dependency 'sinatra-contrib'
37
- spec.add_dependency 'elasticsearch'
38
- spec.add_dependency 'logger'
39
- spec.add_dependency 'pundit'
40
- spec.add_dependency 'sequel'
41
- spec.add_dependency 'bcrypt'
42
- spec.add_dependency 'omniauth'
43
- spec.add_dependency 'omniauth-identity'
35
+ spec.add_dependency 'sinatra-flash', '~> 0.3'
36
+ spec.add_dependency 'sinatra-contrib', '~> 1.0'
37
+ spec.add_dependency 'elasticsearch', '>= 2'
38
+ spec.add_dependency 'logger', '~> 1.0'
39
+ spec.add_dependency 'pundit', '~> 1.0'
40
+ spec.add_dependency 'sequel', '~> 4.0'
41
+ spec.add_dependency 'bcrypt', '~> 3.0'
42
+ spec.add_dependency 'omniauth', '~> 1.0'
43
+ spec.add_dependency 'omniauth-identity', '~> 1.0'
44
+ spec.add_dependency 'omniauth-http-basic', '~> 1.0'
44
45
  spec.add_dependency 'haml', '~> 4.0'
45
- spec.add_dependency 'wisper'
46
- spec.add_dependency 'highline'
46
+ spec.add_dependency 'wisper', '~> 2.0'
47
+ spec.add_dependency 'highline', '~> 1.7'
47
48
  spec.add_dependency 'tilt', '>= 2'
48
49
  end
@@ -22,6 +22,7 @@
22
22
  /[if lt IE 9] <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
23
23
  /[if lt IE 9] <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
24
24
 
25
+ %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js' }
25
26
  %body
26
27
  #wrapper
27
28
  = haml :'partials/navbar', locals: { title: (defined?(title) ? title : 'ProxES') }
@@ -43,9 +44,9 @@
43
44
 
44
45
 
45
46
  / Placed at the end of the document so the pages load faster
46
- %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js' }
47
47
  %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/startbootstrap-sb-admin-2/3.3.7+1/js/sb-admin-2.min.js' }
48
48
  %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/metisMenu/2.5.2/metisMenu.min.js' }
49
49
  %script{ type: 'text/javascript', src: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js' }
50
50
  %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/react/15.4.1/react.min.js' }
51
+ %script{ type: 'text/javascript', src: 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js' }
51
52
  %script{ type: 'text/javascript', src: '/_proxes/js/bundle.js' }
@@ -31,7 +31,8 @@
31
31
  .panel-body
32
32
  %form.form-horizontal{ method: 'post', action: "#{base_path}/#{entity.id}/identity" }
33
33
  %input{ name: '_method', value: 'PUT', type: 'hidden' }
34
- = form_control(:password, identity, type: 'password', placeholder: 'Your password')
34
+ = form_control(:old_password, identity, type: 'password', placeholder: 'Your current password')
35
+ = form_control(:password, identity, type: 'password', placeholder: 'Your new password')
35
36
  = form_control(:password_confirmation, identity, type: 'password', label: 'Confirm Password', placeholder: 'Confirm your password')
36
37
  %button.btn.btn-primary{ type: 'submit' }
37
38
  Change Password
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgens du Toit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2017-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '3'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '3'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: rack-contrib
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '1.4'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '1.4'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: sinatra
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -168,128 +168,142 @@ dependencies:
168
168
  name: sinatra-flash
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: '0.3'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: '0.3'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: sinatra-contrib
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ">="
185
+ - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '0'
187
+ version: '1.0'
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ">="
192
+ - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '0'
194
+ version: '1.0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: elasticsearch
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - ">="
200
200
  - !ruby/object:Gem::Version
201
- version: '0'
201
+ version: '2'
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: '2'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: logger
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ">="
213
+ - - "~>"
214
214
  - !ruby/object:Gem::Version
215
- version: '0'
215
+ version: '1.0'
216
216
  type: :runtime
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - ">="
220
+ - - "~>"
221
221
  - !ruby/object:Gem::Version
222
- version: '0'
222
+ version: '1.0'
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: pundit
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
- - - ">="
227
+ - - "~>"
228
228
  - !ruby/object:Gem::Version
229
- version: '0'
229
+ version: '1.0'
230
230
  type: :runtime
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - ">="
234
+ - - "~>"
235
235
  - !ruby/object:Gem::Version
236
- version: '0'
236
+ version: '1.0'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: sequel
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
- - - ">="
241
+ - - "~>"
242
242
  - !ruby/object:Gem::Version
243
- version: '0'
243
+ version: '4.0'
244
244
  type: :runtime
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - ">="
248
+ - - "~>"
249
249
  - !ruby/object:Gem::Version
250
- version: '0'
250
+ version: '4.0'
251
251
  - !ruby/object:Gem::Dependency
252
252
  name: bcrypt
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
- - - ">="
255
+ - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: '0'
257
+ version: '3.0'
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - ">="
262
+ - - "~>"
263
263
  - !ruby/object:Gem::Version
264
- version: '0'
264
+ version: '3.0'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: omniauth
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
- - - ">="
269
+ - - "~>"
270
270
  - !ruby/object:Gem::Version
271
- version: '0'
271
+ version: '1.0'
272
272
  type: :runtime
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
- - - ">="
276
+ - - "~>"
277
277
  - !ruby/object:Gem::Version
278
- version: '0'
278
+ version: '1.0'
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: omniauth-identity
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
- - - ">="
283
+ - - "~>"
284
284
  - !ruby/object:Gem::Version
285
- version: '0'
285
+ version: '1.0'
286
286
  type: :runtime
287
287
  prerelease: false
288
288
  version_requirements: !ruby/object:Gem::Requirement
289
289
  requirements:
290
- - - ">="
290
+ - - "~>"
291
291
  - !ruby/object:Gem::Version
292
- version: '0'
292
+ version: '1.0'
293
+ - !ruby/object:Gem::Dependency
294
+ name: omniauth-http-basic
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - "~>"
298
+ - !ruby/object:Gem::Version
299
+ version: '1.0'
300
+ type: :runtime
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - "~>"
305
+ - !ruby/object:Gem::Version
306
+ version: '1.0'
293
307
  - !ruby/object:Gem::Dependency
294
308
  name: haml
295
309
  requirement: !ruby/object:Gem::Requirement
@@ -308,30 +322,30 @@ dependencies:
308
322
  name: wisper
309
323
  requirement: !ruby/object:Gem::Requirement
310
324
  requirements:
311
- - - ">="
325
+ - - "~>"
312
326
  - !ruby/object:Gem::Version
313
- version: '0'
327
+ version: '2.0'
314
328
  type: :runtime
315
329
  prerelease: false
316
330
  version_requirements: !ruby/object:Gem::Requirement
317
331
  requirements:
318
- - - ">="
332
+ - - "~>"
319
333
  - !ruby/object:Gem::Version
320
- version: '0'
334
+ version: '2.0'
321
335
  - !ruby/object:Gem::Dependency
322
336
  name: highline
323
337
  requirement: !ruby/object:Gem::Requirement
324
338
  requirements:
325
- - - ">="
339
+ - - "~>"
326
340
  - !ruby/object:Gem::Version
327
- version: '0'
341
+ version: '1.7'
328
342
  type: :runtime
329
343
  prerelease: false
330
344
  version_requirements: !ruby/object:Gem::Requirement
331
345
  requirements:
332
- - - ">="
346
+ - - "~>"
333
347
  - !ruby/object:Gem::Version
334
- version: '0'
348
+ version: '1.7'
335
349
  - !ruby/object:Gem::Dependency
336
350
  name: tilt
337
351
  requirement: !ruby/object:Gem::Requirement