proxes 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +1 -1
  4. data/.travis.yml +0 -3
  5. data/Gemfile.ci +5 -2
  6. data/README.md +12 -9
  7. data/Rakefile +10 -5
  8. data/Vagrantfile +1 -4
  9. data/config.ru +32 -24
  10. data/lib/{proxes → ditty/components}/proxes.rb +26 -33
  11. data/lib/proxes/controllers/permissions.rb +4 -3
  12. data/lib/proxes/models/permission.rb +7 -5
  13. data/lib/proxes/policies/permission_policy.rb +4 -4
  14. data/lib/proxes/policies/request/index_policy.rb +1 -1
  15. data/lib/proxes/policies/request_policy.rb +3 -4
  16. data/lib/proxes/policies/token_policy.rb +1 -1
  17. data/lib/proxes/request/cat.rb +2 -2
  18. data/lib/proxes/request/index.rb +2 -2
  19. data/lib/proxes/request.rb +1 -1
  20. data/lib/proxes/security.rb +10 -12
  21. data/lib/proxes/version.rb +1 -1
  22. data/lib/proxes.rb +1 -3
  23. data/migrate/20170207_base_tables.rb +2 -1
  24. data/migrate/20170208_audit_log.rb +1 -0
  25. data/proxes.gemspec +15 -14
  26. data/public/js/bundle.js +44683 -23940
  27. data/public/js/vendors.js +1 -0
  28. data/views/permissions/form.haml +2 -2
  29. data/views/permissions/index.haml +14 -9
  30. metadata +69 -108
  31. data/lib/proxes/container.rb +0 -135
  32. data/lib/proxes/controllers/app.rb +0 -80
  33. data/lib/proxes/controllers/application.rb +0 -80
  34. data/lib/proxes/controllers/audit_logs.rb +0 -44
  35. data/lib/proxes/controllers/component.rb +0 -167
  36. data/lib/proxes/controllers/roles.rb +0 -16
  37. data/lib/proxes/controllers/users.rb +0 -183
  38. data/lib/proxes/db.rb +0 -18
  39. data/lib/proxes/helpers/authentication.rb +0 -58
  40. data/lib/proxes/helpers/component.rb +0 -49
  41. data/lib/proxes/helpers/pundit.rb +0 -40
  42. data/lib/proxes/helpers/views.rb +0 -42
  43. data/lib/proxes/helpers/wisper.rb +0 -15
  44. data/lib/proxes/listener.rb +0 -23
  45. data/lib/proxes/models/audit_log.rb +0 -14
  46. data/lib/proxes/models/base.rb +0 -9
  47. data/lib/proxes/models/identity.rb +0 -70
  48. data/lib/proxes/models/role.rb +0 -17
  49. data/lib/proxes/models/user.rb +0 -64
  50. data/lib/proxes/omniauth.rb +0 -4
  51. data/lib/proxes/policies/application_policy.rb +0 -21
  52. data/lib/proxes/policies/audit_log_policy.rb +0 -41
  53. data/lib/proxes/policies/identity_policy.rb +0 -25
  54. data/lib/proxes/policies/role_policy.rb +0 -37
  55. data/lib/proxes/policies/user_policy.rb +0 -43
  56. data/lib/proxes/rake_tasks.rb +0 -219
  57. data/lib/proxes/seed.rb +0 -5
  58. data/lib/proxes/services/logger.rb +0 -51
  59. data/views/404.haml +0 -1
  60. data/views/audit_logs/index.haml +0 -26
  61. data/views/error.haml +0 -4
  62. data/views/getting_started.haml +0 -16
  63. data/views/identity/login.haml +0 -19
  64. data/views/identity/register.haml +0 -14
  65. data/views/index.haml +0 -3
  66. data/views/layout.haml +0 -58
  67. data/views/partials/delete_form.haml +0 -4
  68. data/views/partials/form_control.haml +0 -20
  69. data/views/partials/navbar.haml +0 -25
  70. data/views/partials/notifications.haml +0 -24
  71. data/views/partials/pager.haml +0 -12
  72. data/views/partials/sidebar.haml +0 -54
  73. data/views/roles/display.haml +0 -38
  74. data/views/roles/edit.haml +0 -11
  75. data/views/roles/form.haml +0 -1
  76. data/views/roles/index.haml +0 -20
  77. data/views/roles/new.haml +0 -10
  78. data/views/users/display.haml +0 -69
  79. data/views/users/edit.haml +0 -11
  80. data/views/users/identity.haml +0 -3
  81. data/views/users/index.haml +0 -23
  82. data/views/users/new.haml +0 -11
  83. data/views/users/profile.haml +0 -39
  84. data/views/users/user.haml +0 -3
@@ -0,0 +1 @@
1
+ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({},{},[]);
@@ -1,4 +1,4 @@
1
- = form_control(:role_id, entity, type: 'select', options: ProxES::Role.to_hash(:id, :name))
2
- = form_control(:user_id, entity, type: 'select', options: ProxES::User.to_hash(:id, :email))
1
+ = form_control(:role_id, entity, type: 'select', options: Ditty::Role.to_hash(:id, :name))
2
+ = form_control(:user_id, entity, type: 'select', options: Ditty::User.to_hash(:id, :email))
3
3
  = form_control(:verb, entity, type: 'select', options: ProxES::Permission.verbs)
4
4
  = form_control(:pattern, entity)
@@ -8,16 +8,21 @@
8
8
  %th User
9
9
  %th Permission
10
10
  %tbody
11
- -list.each do |entity|
11
+ - if list.count > 0
12
+ - list.all.each do |entity|
13
+ %tr
14
+ %td
15
+ = entity.role ? entity.role.name : 'None'
16
+ %td
17
+ = entity.user ? entity.user.username : 'None'
18
+ %td
19
+ %a.btn-block{ href: "#{base_path}/#{entity.id}" }
20
+ = entity.verb
21
+ = entity.pattern
22
+ - else
12
23
  %tr
13
- %td
14
- = entity.role ? entity.role.name : 'None'
15
- %td
16
- = entity.user ? entity.user.username : 'None'
17
- %td
18
- %a.btn-block{ href: "#{base_path}/#{entity.id}" }
19
- = entity.verb
20
- = entity.pattern
24
+ %td.text-center{ colspan: 3 } No records
25
+
21
26
  - if policy(::ProxES::Permission).create?
22
27
  .panel-body.text-right
23
28
  %a.btn.btn-primary{ href: "#{base_path}/new" } New Permission
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.7.1
4
+ version: 0.8.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-08-09 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,105 +109,105 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: activesupport
112
+ name: ditty
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '3'
117
+ version: '0.2'
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: '3'
124
+ version: '0.2'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rake
126
+ name: activesupport
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '10.0'
131
+ version: '3'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '10.0'
138
+ version: '3'
139
139
  - !ruby/object:Gem::Dependency
140
- name: rack-contrib
140
+ name: bcrypt
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.4'
145
+ version: '3.0'
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: '1.4'
152
+ version: '3.0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: sinatra
154
+ name: elasticsearch
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - "~>"
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '1.0'
159
+ version: '2'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - "~>"
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '1.0'
166
+ version: '2'
167
167
  - !ruby/object:Gem::Dependency
168
- name: sinatra-flash
168
+ name: haml
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0.3'
173
+ version: '5.0'
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.3'
180
+ version: '5.0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: sinatra-contrib
182
+ name: highline
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '1.0'
187
+ version: '1.7'
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: '1.0'
194
+ version: '1.7'
195
195
  - !ruby/object:Gem::Dependency
196
- name: elasticsearch
196
+ name: logger
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ">="
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '2'
201
+ version: '1.0'
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: '2'
208
+ version: '1.0'
209
209
  - !ruby/object:Gem::Dependency
210
- name: logger
210
+ name: omniauth
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - "~>"
@@ -221,7 +221,7 @@ dependencies:
221
221
  - !ruby/object:Gem::Version
222
222
  version: '1.0'
223
223
  - !ruby/object:Gem::Dependency
224
- name: pundit
224
+ name: omniauth-http-basic
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - "~>"
@@ -235,35 +235,35 @@ dependencies:
235
235
  - !ruby/object:Gem::Version
236
236
  version: '1.0'
237
237
  - !ruby/object:Gem::Dependency
238
- name: sequel
238
+ name: omniauth-identity
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
241
  - - "~>"
242
242
  - !ruby/object:Gem::Version
243
- version: '4.0'
243
+ version: '1.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: '4.0'
250
+ version: '1.0'
251
251
  - !ruby/object:Gem::Dependency
252
- name: bcrypt
252
+ name: pundit
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
255
  - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: '3.0'
257
+ version: '1.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: '3.0'
264
+ version: '1.0'
265
265
  - !ruby/object:Gem::Dependency
266
- name: omniauth
266
+ name: rack-contrib
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
269
  - - "~>"
@@ -277,49 +277,49 @@ dependencies:
277
277
  - !ruby/object:Gem::Version
278
278
  version: '1.0'
279
279
  - !ruby/object:Gem::Dependency
280
- name: omniauth-identity
280
+ name: rake
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
283
  - - "~>"
284
284
  - !ruby/object:Gem::Version
285
- version: '1.0'
285
+ version: '12.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: '1.0'
292
+ version: '12.0'
293
293
  - !ruby/object:Gem::Dependency
294
- name: omniauth-http-basic
294
+ name: sequel
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
297
  - - "~>"
298
298
  - !ruby/object:Gem::Version
299
- version: '1.0'
299
+ version: '4.0'
300
300
  type: :runtime
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - "~>"
305
305
  - !ruby/object:Gem::Version
306
- version: '1.0'
306
+ version: '4.0'
307
307
  - !ruby/object:Gem::Dependency
308
- name: haml
308
+ name: sinatra
309
309
  requirement: !ruby/object:Gem::Requirement
310
310
  requirements:
311
311
  - - "~>"
312
312
  - !ruby/object:Gem::Version
313
- version: '4.0'
313
+ version: '2.0'
314
314
  type: :runtime
315
315
  prerelease: false
316
316
  version_requirements: !ruby/object:Gem::Requirement
317
317
  requirements:
318
318
  - - "~>"
319
319
  - !ruby/object:Gem::Version
320
- version: '4.0'
320
+ version: '2.0'
321
321
  - !ruby/object:Gem::Dependency
322
- name: wisper
322
+ name: sinatra-contrib
323
323
  requirement: !ruby/object:Gem::Requirement
324
324
  requirements:
325
325
  - - "~>"
@@ -333,19 +333,19 @@ dependencies:
333
333
  - !ruby/object:Gem::Version
334
334
  version: '2.0'
335
335
  - !ruby/object:Gem::Dependency
336
- name: highline
336
+ name: sinatra-flash
337
337
  requirement: !ruby/object:Gem::Requirement
338
338
  requirements:
339
339
  - - "~>"
340
340
  - !ruby/object:Gem::Version
341
- version: '1.7'
341
+ version: '0.3'
342
342
  type: :runtime
343
343
  prerelease: false
344
344
  version_requirements: !ruby/object:Gem::Requirement
345
345
  requirements:
346
346
  - - "~>"
347
347
  - !ruby/object:Gem::Version
348
- version: '1.7'
348
+ version: '0.3'
349
349
  - !ruby/object:Gem::Dependency
350
350
  name: tilt
351
351
  requirement: !ruby/object:Gem::Requirement
@@ -360,6 +360,20 @@ dependencies:
360
360
  - - ">="
361
361
  - !ruby/object:Gem::Version
362
362
  version: '2'
363
+ - !ruby/object:Gem::Dependency
364
+ name: wisper
365
+ requirement: !ruby/object:Gem::Requirement
366
+ requirements:
367
+ - - "~>"
368
+ - !ruby/object:Gem::Version
369
+ version: '2.0'
370
+ type: :runtime
371
+ prerelease: false
372
+ version_requirements: !ruby/object:Gem::Requirement
373
+ requirements:
374
+ - - "~>"
375
+ - !ruby/object:Gem::Version
376
+ version: '2.0'
363
377
  description: Rack wrapper around Elasticsearch to provide security and management
364
378
  features
365
379
  email:
@@ -388,35 +402,13 @@ files:
388
402
  - config.ru
389
403
  - config/logger.yml
390
404
  - gulpfile.js
405
+ - lib/ditty/components/proxes.rb
391
406
  - lib/proxes.rb
392
- - lib/proxes/container.rb
393
- - lib/proxes/controllers/app.rb
394
- - lib/proxes/controllers/application.rb
395
- - lib/proxes/controllers/audit_logs.rb
396
- - lib/proxes/controllers/component.rb
397
407
  - lib/proxes/controllers/permissions.rb
398
- - lib/proxes/controllers/roles.rb
399
- - lib/proxes/controllers/users.rb
400
- - lib/proxes/db.rb
401
408
  - lib/proxes/forwarder.rb
402
- - lib/proxes/helpers/authentication.rb
403
- - lib/proxes/helpers/component.rb
404
409
  - lib/proxes/helpers/indices.rb
405
- - lib/proxes/helpers/pundit.rb
406
- - lib/proxes/helpers/views.rb
407
- - lib/proxes/helpers/wisper.rb
408
- - lib/proxes/listener.rb
409
410
  - lib/proxes/loggers/elasticsearch.rb
410
- - lib/proxes/models/audit_log.rb
411
- - lib/proxes/models/base.rb
412
- - lib/proxes/models/identity.rb
413
411
  - lib/proxes/models/permission.rb
414
- - lib/proxes/models/role.rb
415
- - lib/proxes/models/user.rb
416
- - lib/proxes/omniauth.rb
417
- - lib/proxes/policies/application_policy.rb
418
- - lib/proxes/policies/audit_log_policy.rb
419
- - lib/proxes/policies/identity_policy.rb
420
412
  - lib/proxes/policies/permission_policy.rb
421
413
  - lib/proxes/policies/request/cat_policy.rb
422
414
  - lib/proxes/policies/request/create_policy.rb
@@ -426,11 +418,7 @@ files:
426
418
  - lib/proxes/policies/request/snapshot_policy.rb
427
419
  - lib/proxes/policies/request/stats_policy.rb
428
420
  - lib/proxes/policies/request_policy.rb
429
- - lib/proxes/policies/role_policy.rb
430
421
  - lib/proxes/policies/token_policy.rb
431
- - lib/proxes/policies/user_policy.rb
432
- - lib/proxes/proxes.rb
433
- - lib/proxes/rake_tasks.rb
434
422
  - lib/proxes/request.rb
435
423
  - lib/proxes/request/cat.rb
436
424
  - lib/proxes/request/create.rb
@@ -440,8 +428,6 @@ files:
440
428
  - lib/proxes/request/snapshot.rb
441
429
  - lib/proxes/request/stats.rb
442
430
  - lib/proxes/security.rb
443
- - lib/proxes/seed.rb
444
- - lib/proxes/services/logger.rb
445
431
  - lib/proxes/version.rb
446
432
  - migrate/20170207_base_tables.rb
447
433
  - migrate/20170208_audit_log.rb
@@ -459,42 +445,17 @@ files:
459
445
  - public/images/mstile-150x150.png
460
446
  - public/images/safari-pinned-tab.svg
461
447
  - public/js/bundle.js
448
+ - public/js/vendors.js
462
449
  - public/manifest.json
463
450
  - src/scripts/app.js
464
- - views/404.haml
465
- - views/audit_logs/index.haml
466
- - views/error.haml
467
- - views/getting_started.haml
468
- - views/identity/login.haml
469
- - views/identity/register.haml
470
- - views/index.haml
471
- - views/layout.haml
472
- - views/partials/delete_form.haml
473
- - views/partials/form_control.haml
474
- - views/partials/navbar.haml
475
- - views/partials/notifications.haml
476
- - views/partials/pager.haml
477
- - views/partials/sidebar.haml
478
451
  - views/permissions/display.haml
479
452
  - views/permissions/edit.haml
480
453
  - views/permissions/form.haml
481
454
  - views/permissions/index.haml
482
455
  - views/permissions/new.haml
483
- - views/roles/display.haml
484
- - views/roles/edit.haml
485
- - views/roles/form.haml
486
- - views/roles/index.haml
487
- - views/roles/new.haml
488
- - views/users/display.haml
489
- - views/users/edit.haml
490
- - views/users/identity.haml
491
- - views/users/index.haml
492
- - views/users/new.haml
493
- - views/users/profile.haml
494
- - views/users/user.haml
495
456
  homepage: https://github.com/eagerelk/proxes
496
457
  licenses:
497
- - LGPLv3
458
+ - LGPL-3.0
498
459
  metadata: {}
499
460
  post_install_message:
500
461
  rdoc_options: []
@@ -512,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
512
473
  version: '0'
513
474
  requirements: []
514
475
  rubyforge_project:
515
- rubygems_version: 2.6.11
476
+ rubygems_version: 2.6.13
516
477
  signing_key:
517
478
  specification_version: 4
518
479
  summary: Rack wrapper around Elasticsearch to provide security and management features
@@ -1,135 +0,0 @@
1
- module ProxES
2
- class Container
3
- class ContainerError < StandardError; end
4
-
5
- # A thread safe cache class, offering only #[] and #[]= methods,
6
- # each protected by a mutex.
7
- # Ripped off from Roda - https://github.com/jeremyevans/roda
8
- class PluginCache
9
- # Create a new thread safe cache.
10
- def initialize
11
- @mutex = Mutex.new
12
- @hash = {}
13
- end
14
-
15
- # Make getting value from underlying hash thread safe.
16
- def [](key)
17
- @mutex.synchronize { @hash[key] }
18
- end
19
-
20
- # Make setting value in underlying hash thread safe.
21
- def []=(key, value)
22
- @mutex.synchronize { @hash[key] = value }
23
- end
24
-
25
- def map(&block)
26
- @mutex.synchronize { @hash.map(&block) }
27
- end
28
-
29
- def inject(memo, &block)
30
- @mutex.synchronize { @hash.inject(memo, &block) }
31
- end
32
- end
33
-
34
- # Ripped off from Roda - https://github.com/jeremyevans/roda
35
- module Plugins
36
- # Stores registered plugins
37
- @plugins = PluginCache.new
38
-
39
- # If the registered plugin already exists, use it. Otherwise,
40
- # require it and return it. This raises a LoadError if such a
41
- # plugin doesn't exist, or a ContainerError if it exists but it does
42
- # not register itself correctly.
43
- def self.load_plugin(name)
44
- h = @plugins
45
- unless plugin = h[name]
46
- require "proxes/plugins/#{name}"
47
- raise ContainerError, "Plugin #{name} did not register itself correctly in ProxES::Container::Plugins" unless plugin = h[name]
48
- end
49
- plugin
50
- end
51
-
52
- # Register the given plugin with Container, so that it can be loaded using #plugin
53
- # with a symbol. Should be used by plugin files. Example:
54
- #
55
- # ProxES::Container::Plugins.register_plugin(:plugin_name, PluginModule)
56
- def self.register_plugin(name, mod)
57
- @plugins[name] = mod
58
- end
59
-
60
- def self.plugins
61
- @plugins
62
- end
63
-
64
- module Base
65
- module ClassMethods
66
- # Load a new plugin into the current class. A plugin can be a module
67
- # which is used directly, or a symbol represented a registered plugin
68
- # which will be required and then used. Returns nil.
69
- #
70
- # Container.plugin PluginModule
71
- # Container.plugin :csrf
72
- def plugin(plugin, *args, &block)
73
- raise ContainerError, 'Cannot add a plugin to a frozen Container class' if frozen?
74
- plugin = Plugins.load_plugin(plugin) if plugin.is_a?(Symbol)
75
- plugin.load_dependencies(self, *args, &block) if plugin.respond_to?(:load_dependencies)
76
- include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods)
77
- extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)
78
- plugin.configure(self, *args, &block) if plugin.respond_to?(:configure)
79
-
80
- # One option is to add controllers / nav on registration:
81
- @controllers.merge(plugin.controllers) if plugin.respond_to?(:controllers)
82
- @navigation << plugin.navigation if plugin.respond_to?(:navigation)
83
-
84
- nil
85
- end
86
-
87
- # Return a hash of controllers with their routes as keys: `{ '/users' => ProxES::Controllers::Users }`
88
- def routes
89
- Plugins.plugins.inject({}) do |memo, plugin|
90
- memo.merge!(plugin[1].route_mappings) if plugin[1].respond_to?(:route_mappings)
91
- end
92
- end
93
-
94
- # Return an ordered list of navigation items:
95
- # `[{order:0, link:'/users/', text:'Users'}, {order:1, link:'/roles/', text:'Roles'}]
96
- def navigation
97
- Plugins.plugins.map do |_key, plugin|
98
- plugin.nav_items if plugin.respond_to?(:nav_items)
99
- end.compact.flatten.sort_by { |h| h[:order] }
100
- end
101
-
102
- def migrations
103
- Plugins.plugins.map do |_key, plugin|
104
- plugin.migration_folder if plugin.respond_to?(:migration_folder)
105
- end.compact
106
- end
107
-
108
- def public
109
- Plugins.plugins.map do |_key, plugin|
110
- plugin.public_folder if plugin.respond_to?(:public_folder)
111
- end.compact
112
- end
113
-
114
- def seeders
115
- Plugins.plugins.map do |_key, plugin|
116
- plugin.seeder if plugin.respond_to?(:seeder)
117
- end.compact
118
- end
119
-
120
- def workers
121
- Plugins.plugins.map do |_key, plugin|
122
- plugin.run_workers if plugin.respond_to?(:run_workers)
123
- end.compact
124
- end
125
- end
126
-
127
- module InstanceMethods
128
- end
129
- end
130
- end
131
-
132
- extend Plugins::Base::ClassMethods
133
- plugin Plugins::Base
134
- end
135
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'proxes/controllers/application'
4
-
5
- module ProxES
6
- class App < Application
7
- def find_template(views, name, engine, &block)
8
- super(views, name, engine, &block) # Root
9
- super(::ProxES::ProxES.view_folder, name, engine, &block) # Basic Plugin
10
- end
11
-
12
- # Home Page
13
- get '/' do
14
- authenticate!
15
- haml :index, locals: { title: 'Home' }
16
- end
17
-
18
- # OmniAuth Identity Stuff
19
- # Log in Page
20
- get '/auth/identity' do
21
- haml :'identity/login', locals: { title: 'Log In' }
22
- end
23
-
24
- post '/auth/identity/callback' do
25
- if env['omniauth.auth']
26
- # Successful Login
27
- user = User.find(email: env['omniauth.auth']['info']['email'])
28
- self.current_user = user
29
- log_action(:identity_login, user: user)
30
- flash[:success] = 'Logged In'
31
- redirect '/_proxes'
32
- else
33
- # Failed Login
34
- broadcast(:identity_failed_login)
35
- flash[:warning] = 'Invalid credentials. Please try again.'
36
- redirect '/_proxes/auth/identity'
37
- end
38
- end
39
-
40
- # Register Page
41
- get '/auth/identity/register' do
42
- identity = Identity.new
43
- haml :'identity/register', locals: { title: 'Register', identity: identity }
44
- end
45
-
46
- # Register Action
47
- post '/auth/identity/new' do
48
- identity = Identity.new(params['identity'])
49
- if identity.valid? && identity.save
50
- user = User.find_or_create(email: identity.username)
51
- user.add_identity identity
52
-
53
- # Create the SA user if none is present
54
- sa = Role.find_or_create(name: 'super_admin')
55
- user.add_role sa if User.where(roles: sa).count == 0
56
-
57
- log_action(:identity_register, user: user)
58
- flash[:info] = 'Successfully Registered. Please log in'
59
- redirect '/_proxes/auth/identity'
60
- else
61
- flash.now[:warning] = 'Could not complete the registration. Please try again.'
62
- haml :'identity/register', locals: { identity: identity }
63
- end
64
- end
65
-
66
- # Logout Action
67
- delete '/auth/identity' do
68
- log_action(:identity_logout)
69
- logout
70
- flash[:info] = 'Logged Out'
71
-
72
- redirect '/_proxes'
73
- end
74
-
75
- # Unauthenticated
76
- get '/unauthenticated' do
77
- redirect '/_proxes/auth/identity'
78
- end
79
- end
80
- end