proxes 0.3.5 → 0.3.6

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: b75db292ccba3287742672927f228a2bd4300b5c
4
- data.tar.gz: 130a8c4cee3f14a79fb52a96e97fd08f00bae383
3
+ metadata.gz: 8d84d569f0a5650fb34b6bd9aede6d9737540323
4
+ data.tar.gz: ac93f76be8bf7ccd7fdfac033e2affe8f9442999
5
5
  SHA512:
6
- metadata.gz: 5af0b16dfa99043350bb6cac773493a21c5d4819d2884fc282164f723c80fbea0ccd037a34851dc343c16d2f3e4cae381e99ee538a7c0ee8fff734f47f0bfe61
7
- data.tar.gz: 910c24347f4abee41eda9719537b320f61177d6bbae8207337e3c53975e0a53042f11f8431e43ceed4fd4f6cb930539830714ce2f49c6092249cb26c800b30e3
6
+ metadata.gz: 725746109ead14f455a36006863ad9bff880d8685b2511d4ddec6cf7c882b85b04e4250f9154e1eb71c12a523c14ef11399430200082fca0bdc85fd6e48565dc
7
+ data.tar.gz: ab5eb8ba0e65a9adf781cd6f2ff977323ae514388f206d4ef7a5e8a0748bc8c4e1241239dfa1acc5117eefc188fa397c5aea561c7fd9d7a8b7df03f475236a8d
data/Gemfile.dev.lock CHANGED
@@ -9,7 +9,8 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- proxes (0.3.2)
12
+ proxes (0.3.5)
13
+ activesupport
13
14
  bcrypt
14
15
  elasticsearch
15
16
  haml
@@ -34,7 +35,7 @@ GEM
34
35
  i18n (~> 0.7)
35
36
  minitest (~> 5.1)
36
37
  tzinfo (~> 1.1)
37
- backports (3.6.8)
38
+ backports (3.7.0)
38
39
  bcrypt (3.1.11)
39
40
  bcrypt-ruby (3.1.5)
40
41
  bcrypt (>= 3.1.3)
@@ -44,17 +45,17 @@ GEM
44
45
  database_cleaner (1.5.3)
45
46
  diff-lcs (1.2.5)
46
47
  docile (1.1.5)
47
- elasticsearch (5.0.3)
48
- elasticsearch-api (= 5.0.3)
49
- elasticsearch-transport (= 5.0.3)
50
- elasticsearch-api (5.0.3)
48
+ elasticsearch (5.0.4)
49
+ elasticsearch-api (= 5.0.4)
50
+ elasticsearch-transport (= 5.0.4)
51
+ elasticsearch-api (5.0.4)
51
52
  multi_json
52
- elasticsearch-transport (5.0.3)
53
+ elasticsearch-transport (5.0.4)
53
54
  faraday
54
55
  multi_json
55
56
  factory_girl (4.8.0)
56
57
  activesupport (>= 3.0.0)
57
- faraday (0.11.0)
58
+ faraday (0.12.0.1)
58
59
  multipart-post (>= 1.2, < 3)
59
60
  ffi (1.9.14)
60
61
  git-version-bump (0.15.1)
@@ -116,7 +117,7 @@ GEM
116
117
  rspec-support (~> 3.5.0)
117
118
  rspec-support (3.5.0)
118
119
  ruby_dep (1.5.0)
119
- sequel (4.44.0)
120
+ sequel (4.45.0)
120
121
  simplecov (0.12.0)
121
122
  docile (~> 1.1.0)
122
123
  json (>= 1.8, < 3)
@@ -7,6 +7,10 @@ module ProxES
7
7
  class AuditLogs < Component
8
8
  set model_class: AuditLog
9
9
 
10
+ def list
11
+ super.order(:created_at).reverse
12
+ end
13
+
10
14
  get '/new' do
11
15
  halt 404
12
16
  end
data/lib/proxes/db.rb CHANGED
@@ -6,7 +6,7 @@ require 'proxes/services/logger'
6
6
  # passed to subprocesses. DATABASE_URL may contain passwords.
7
7
  DB = Sequel.connect(ENV['RACK_ENV'] == 'production' ? ENV.delete('DATABASE_URL') : ENV['DATABASE_URL'])
8
8
 
9
- DB.loggers << ProxES::Services::Logger.instance
9
+ DB.loggers << ProxES::Services::Logger.instance
10
10
 
11
11
  DB.extension(:pagination)
12
12
 
@@ -5,6 +5,7 @@ module ProxES
5
5
  def method_missing(method, *args, &block)
6
6
  vals = { action: method }
7
7
  vals[:user] = args[0][:user] if (args[0] && args[0].has_key?(:user))
8
+ vals[:details] = args[0][:details] if (args[0] && args[0].has_key?(:details))
8
9
  AuditLog.create vals
9
10
  end
10
11
 
@@ -4,9 +4,18 @@ require 'proxes/models/base'
4
4
  module ProxES
5
5
  class Permission < Base
6
6
  many_to_one :role
7
+ many_to_one :user
8
+
9
+ dataset_module do
10
+ def for_user(a_user, action)
11
+ where(verb: action).where{Sequel.|({role: a_user.roles}, {user_id: a_user.id})}
12
+ end
13
+ end
7
14
 
8
15
  def validate
9
- validates_presence [:role_id, :verb, :pattern]
16
+ validates_presence [:verb, :pattern]
17
+ validates_presence :role_id unless user_id
18
+ validates_presence :user_id unless role_id
10
19
  validates_includes self.class.verbs, :verb
11
20
  end
12
21
 
@@ -53,5 +53,9 @@ module ProxES
53
53
  def index_prefix
54
54
  email
55
55
  end
56
+
57
+ def username
58
+ identity_dataset.first.username
59
+ end
56
60
  end
57
61
  end
@@ -24,7 +24,7 @@ module ProxES
24
24
  end
25
25
 
26
26
  def permitted_attributes
27
- [:action]
27
+ [:action, :details]
28
28
  end
29
29
 
30
30
  class Scope < ApplicationPolicy::Scope
@@ -24,7 +24,7 @@ module ProxES
24
24
  end
25
25
 
26
26
  def permitted_attributes
27
- [:verb, :pattern, :role_id]
27
+ [:verb, :pattern, :role_id, :user_id]
28
28
  end
29
29
 
30
30
  class Scope < ApplicationPolicy::Scope
@@ -4,7 +4,7 @@ module ProxES
4
4
  class SearchPolicy < RequestPolicy
5
5
  class Scope < RequestPolicy::Scope
6
6
  def resolve
7
- patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
7
+ patterns = Permission.for_user(user, 'INDEX').map do |permission|
8
8
  permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
9
9
  end
10
10
  filter scope.index, patterns
@@ -4,7 +4,7 @@ module ProxES
4
4
  class StatsPolicy < RequestPolicy
5
5
  class Scope < RequestPolicy::Scope
6
6
  def resolve
7
- patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
7
+ patterns = Permission.for_user(user, 'INDEX').map do |permission|
8
8
  permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
9
9
  end
10
10
  filter scope.index, patterns
@@ -20,15 +20,9 @@ module ProxES
20
20
  return false if user.nil?
21
21
 
22
22
  if record.indices?
23
- patterns = Permission.where(verb: 'INDEX', role: user.roles).map do |permission|
24
- permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
25
- end
26
- return filter(record.index, patterns).count.positive?
23
+ return true if index_allowed?
27
24
  else
28
- # Give me all the user's permissions that match the verb
29
- Permission.where(verb: method_sym[0..-2].upcase, role: user.roles).each do |permission|
30
- return true if record.path =~ %r{#{permission.pattern}}
31
- end
25
+ return true if action_allowed? method_sym[0..-2].upcase
32
26
  end
33
27
  false
34
28
  else
@@ -36,6 +30,21 @@ module ProxES
36
30
  end
37
31
  end
38
32
 
33
+ def index_allowed?
34
+ patterns = Permission.for_user(user, 'INDEX').map do |permission|
35
+ permission.pattern.gsub(/\{user.(.*)\}/) { |match| user.send(Regexp.last_match[1].to_sym) }
36
+ end
37
+ return filter(record.index, patterns).count.positive?
38
+ end
39
+
40
+ def action_allowed?(action)
41
+ # Give me all the user's permissions that match the verb
42
+ Permission.for_user(user, action).each do |permission|
43
+ return true if record.path =~ %r{#{permission.pattern}}
44
+ end
45
+ false
46
+ end
47
+
39
48
  def respond_to_missing?(name, _include_private = false)
40
49
  name[-1] == '?'
41
50
  end
@@ -36,7 +36,7 @@ module ProxES
36
36
  namespace :migrate do
37
37
  require_relative './db'
38
38
  Sequel.extension :migration
39
- folder = File.expand_path(File.dirname(__FILE__) + '/../../migrate')
39
+ folder = 'migrations'
40
40
 
41
41
  desc 'Check if the migration is current'
42
42
  task :check do
@@ -4,6 +4,7 @@ require 'proxes/request'
4
4
  require 'proxes/policies/request_policy'
5
5
  require 'proxes/helpers/pundit'
6
6
  require 'proxes/helpers/authentication'
7
+ require 'proxes/helpers/wisper'
7
8
  require 'proxes/services/logger'
8
9
 
9
10
  module ProxES
@@ -12,6 +13,8 @@ module ProxES
12
13
 
13
14
  include Helpers::Authentication
14
15
  include Helpers::Pundit
16
+ include Helpers::Wisper
17
+ include Wisper::Publisher
15
18
 
16
19
  def initialize(app, logger = nil)
17
20
  @app = app
@@ -36,6 +39,7 @@ module ProxES
36
39
  check_basic
37
40
  authorize request
38
41
  rescue StandardError => e
42
+ log_action(:es_request_denied, details: "#{request.request_method.upcase} #{request.fullpath} (#{request.class.name})")
39
43
  logger.debug "Access denied by security layer: #{e.message}"
40
44
  return error 'Forbidden', 403
41
45
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ProxES
3
- VERSION = '0.3.5'
3
+ VERSION = '0.3.6'
4
4
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Sequel.migration do
4
+ change do
5
+ alter_table :audit_logs do
6
+ add_column :details, String, text: true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ Sequel.migration do
4
+ change do
5
+ alter_table :permissions do
6
+ add_foreign_key :user_id, :users
7
+ end
8
+ end
9
+ end
data/proxes.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'database_cleaner'
28
28
  spec.add_development_dependency 'factory_girl'
29
29
 
30
+ spec.add_dependency 'activesupport'
30
31
  spec.add_dependency 'rake', '~> 10.0'
31
32
  spec.add_dependency 'rack-contrib'
32
33
  spec.add_dependency 'sinatra'
@@ -6,6 +6,7 @@
6
6
  %tr
7
7
  %th User email
8
8
  %th Action
9
+ %th Details
9
10
  %th Created at
10
11
  %tbody
11
12
  -list.each do |entity|
@@ -17,5 +18,7 @@
17
18
  None
18
19
  %td
19
20
  = entity.action
21
+ %td
22
+ = entity.details
20
23
  %td
21
24
  = entity.created_at.strftime('%Y-%m-%d %H:%M:%S')
@@ -5,7 +5,10 @@
5
5
  .panel-body
6
6
  %p.description
7
7
  %label Role:
8
- = entity.role.name
8
+ = entity.role ? entity.role.name : 'None'
9
+ %p.description
10
+ %label User:
11
+ = entity.user ? entity.user.username : 'None'
9
12
  %p.description
10
13
  %label Verb:
11
14
  = entity.verb
@@ -1,3 +1,4 @@
1
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))
2
3
  = form_control(:verb, entity, type: 'select', options: ProxES::Permission.verbs)
3
4
  = form_control(:pattern, entity)
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.3.5
4
+ version: 0.3.6
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-04-12 00:00:00.000000000 Z
11
+ date: 2017-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -384,6 +398,8 @@ files:
384
398
  - lib/proxes/version.rb
385
399
  - migrate/20170207_01_base_tables.rb
386
400
  - migrate/20170207_02_audit_log.rb
401
+ - migrate/20170416_audit_log_details.rb
402
+ - migrate/20170416_user_specific_permissions.rb
387
403
  - package.json
388
404
  - proxes.gemspec
389
405
  - public/js/bundle.js