jungle_path 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c9a76586270cb176c12b4cee2c5634f095986dd
4
- data.tar.gz: 8c5a58c3e0c272e1e1d3fa54e0043eb515153a66
3
+ metadata.gz: 162b61d2490684693fc8cd9b7ff7c814628c29cb
4
+ data.tar.gz: 61438251aa193d15755d7aa9ef73f6e58d3a22d5
5
5
  SHA512:
6
- metadata.gz: 8fac534b4b48fcb7ccc3bcb3404da09e7f5108c867523e7eafb33f553b6cbfd0267359ed52c4ea4fa205f7c7235501ce006e23fa04475d8cc3acafbafa826b30
7
- data.tar.gz: 8cbe0b457b9c522d8aadc11ec76b1dd24fef8803f052abfd78b55310770727d68596e461d773a9132274c7270e6db4256375aa3ce23d8610852febd709e96b52
6
+ metadata.gz: 6ebc40995f918fa40f4ae6bdeb1ec1ce75d94c3218e71f34a659c5608aa90fcd82703b9b4da6377600d168527e44e38cfbe600950becb76cd0d1a1d355cbf11c
7
+ data.tar.gz: ddee9e142757902d4fbf3aef70b0a74e22b7400267bf1424a6f58aaaf283eda5dd1f19576217a45e2b38a9c9ae6c4c126466d21d098deccbb1feab370124b2ff
@@ -33,7 +33,7 @@ module JunglePath
33
33
  #engine = Query::Engine.new(Schema::Base.models, current_user, apply_limit_offset_to_sql)
34
34
  node_tree = current_auth.schema_node_tree
35
35
  puts "node_tree: #{node_tree.to_str}."
36
- engine = Query::Engine.new(node_tree, current_user, apply_limit_offset_to_sql)
36
+ engine = Query::Engine.new(node_tree, current_identity, apply_limit_offset_to_sql)
37
37
  puts "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
38
38
  q = engine.get_query_from_string(query)
39
39
  result[:sql] = q.sql
@@ -161,21 +161,17 @@ module Config
161
161
  end
162
162
 
163
163
  def self.schema_filters
164
- jungle.schema_filters = lambda {|identity|
165
- filters = {
166
- allow_all_tables: {allow: [table: /./]},
167
- hide_nonpublic_tables: {allow: [{table: /./}], deny: [{table: /^utility_/}, {table: /^temp_/}]}
168
- }
164
+ jungle.schema_filters = {
165
+ allow_all_tables: {allow: [table: /./]},
166
+ hide_nonpublic_tables: {allow: [{table: /./}], deny: [{table: /^utility_/}, {table: /^temp_/}]}
169
167
  }
170
168
  end
171
169
 
172
170
  def self.role_schema_filters
173
- jungle.role_schema_filters = lambda {|identity|
174
- filters = {
175
- root: :allow_all_tables,
176
- admin: :allow_all_tables,
177
- user: :hide_nonpublic_tables
178
- }
171
+ jungle.role_schema_filters = {
172
+ root: :allow_all_tables,
173
+ admin: :allow_all_tables,
174
+ user: :hide_nonpublic_tables
179
175
  }
180
176
  end
181
177
 
@@ -71,10 +71,12 @@ module JunglePath
71
71
  idn.role = data_provider.get_role(idn, no_cache)
72
72
  idn.authorization_filter = data_provider.get_authorization_filter(idn, no_cache)
73
73
  idn.query_filters = data_provider.get_query_filters(idn, no_cache)
74
+ puts "query_filters: set!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
74
75
  else
75
76
  idn.role = nil
76
77
  idn.authorization_filter = nil
77
78
  idn.query_filters = nil
79
+ puts "query_filters: nil!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
78
80
  end
79
81
  end
80
82
  idn
@@ -1,6 +1,7 @@
1
1
  module JunglePath
2
2
  require 'jungle_path/authentication/password_hash'
3
3
  require 'jungle_path/authorization/filter'
4
+ require 'jungle_path/query/filter'
4
5
  require 'jungle_path/schema/auth'
5
6
  require 'jungle_path/sql/user'
6
7
  module Authentication
@@ -68,22 +69,51 @@ module JunglePath
68
69
  end
69
70
 
70
71
  def get_authorization_filter(identity, no_cache=false)
71
- JunglePath::Authorization::Filter.new([identity.role], @models, @role_permissions, @role_restrictions, @role_schema_filters.call(identity), @schema_filters.call(identity))
72
+ JunglePath::Authorization::Filter.new([identity.role], @models, @role_permissions, @role_restrictions, @role_schema_filters, @schema_filters)
72
73
  end
73
74
 
74
75
  def get_query_filters(identity, no_cache=false)
75
76
  filters = []
76
- @role_query_filters.call(identity).each do |key, filter|
77
- filters << filter
77
+
78
+ temp_filters = @role_query_filters.call(identity)[identity.role] || []
79
+ temp_filters.each do |filter|
80
+ filters << JunglePath::Query::Filter.new(filter[:table_name], filter[:sub_select])
78
81
  end
79
- @restriction_query_filters.call(identity).each do |key, filter|
80
- filters << filter
82
+
83
+ temp_filters = @restriction_query_filters.call(identity)
84
+ identity.authorization_filter.restrictions.each do |restriction|
85
+ temp = temp_filters[restriction] || []
86
+ temp.each do |filter|
87
+ filters << JunglePath::Query::Filter.new(filter[:table_name], filter[:sub_select])
88
+ end
81
89
  end
82
- @user_query_filters.call(identity).each do |key, filter|
83
- filters << filter
90
+
91
+ temp_filters = @user_query_filters.call(identity)
92
+ temp = temp_filters[identity.user.id] || []
93
+ temp.each do |filter|
94
+ filters << JunglePath::Query::Filter.new(filter[:table_name], filter[:sub_select])
84
95
  end
96
+
85
97
  filters
86
98
  end
99
+
100
+
101
+ # def get_query_filters(identity, no_cache=false)
102
+ # filters = []
103
+ # @role_query_filters.call(identity).each do |key, filter|
104
+ # puts "role_query_filters: key/filter: #{key}/#{filter}"
105
+ # filters << filter
106
+ # end
107
+ # @restriction_query_filters.call(identity).each do |key, filter|
108
+ # puts "restriction_query_filters: key/filter: #{key}/#{filter}"
109
+ # filters << filter
110
+ # end
111
+ # @user_query_filters.call(identity).each do |key, filter|
112
+ # puts "user_query_filters: key/filter: #{key}/#{filter}"
113
+ # filters << filter
114
+ # end
115
+ # filters
116
+ # end
87
117
  end
88
118
  end
89
119
  end
@@ -1,6 +1,7 @@
1
1
  module JunglePath
2
2
  require 'jungle_path/authentication/password_hash'
3
3
  require 'jungle_path/authorization/filter'
4
+ require 'jungle_path/query/filter'
4
5
  require 'jungle_path/schema/auth'
5
6
  module Authentication
6
7
  module DataProvider
@@ -71,37 +72,30 @@ module JunglePath
71
72
  @role_permissions[role[:name]] = role[:permissions]
72
73
  @role_restrictions[role[:name]] = role[:restrictions]
73
74
  end
74
- @role_schema_filters = lambda {|identity|
75
- filters = {
76
- root: :allow_all_tables,
77
- admin: :allow_all_tables,
78
- user: :hide_nonpublic_tables
79
- }
75
+ @role_schema_filters = {
76
+ root: :allow_all_tables,
77
+ admin: :allow_all_tables,
78
+ user: :hide_nonpublic_tables
80
79
  }
81
- @schema_filters = lambda {|identity|
82
- filters = {
83
- allow_all_tables: {allow: [table: /./]},
84
- hide_nonpublic_tables: {allow: [{table: /./}], deny: [{table: /^utility_/}, {table: /^temp_/}]}
85
- }
80
+ @schema_filters = {
81
+ allow_all_tables: {allow: [table: /./]},
82
+ hide_nonpublic_tables: {allow: [{table: /./}], deny: [{table: /^utility_/}, {table: /^temp_/}]}
86
83
  }
87
- @role_query_filters = lambda {|identity|
88
- filters = {
84
+ @role_query_filters = lambda do |identity| {
89
85
  admin: [
90
86
  {table_name: :table_i_want_to_filter, sub_select: "select id from table_i_want_to_filter where a = b"}
91
87
  ]
92
- # more...
93
88
  }
94
- }
95
- @restriction_query_filters = lambda {|identity|
96
- filters = {
89
+ end
90
+ @restriction_query_filters = lambda do |identity| {
97
91
  me_related:[
98
92
  {table_name: :user, sub_select: "select id from user where id = #{identity.user.id}"}
99
93
  ]
100
94
  }
101
- }
102
- @user_query_filters = lambda {|identity|
103
- filters = {}
104
- }
95
+ end
96
+ @user_query_filters = lambda do |identity| {
97
+ }
98
+ end
105
99
  end
106
100
 
107
101
  def get_user(user_name, password, no_cache=false)
@@ -127,20 +121,31 @@ module JunglePath
127
121
  end
128
122
 
129
123
  def get_authorization_filter(identity, no_cache=false)
130
- JunglePath::Authorization::Filter.new([identity.role], @models, @role_permissions, @role_restrictions, @role_schema_filters.call(identity), @schema_filters.call(identity))
124
+ JunglePath::Authorization::Filter.new([identity.role], @models, @role_permissions, @role_restrictions, @role_schema_filters, @schema_filters)
131
125
  end
132
126
 
133
127
  def get_query_filters(identity, no_cache=false)
134
128
  filters = []
135
- @role_query_filters.call(identity).each do |key, filter|
136
- filters << filter
129
+
130
+ temp_filters = @role_query_filters.call(identity)[identity.role] or []
131
+ temp_filters.each do |filter|
132
+ filters << JunglePath::Query::Filter.new(filter[:table_name], filter[:sub_select])
137
133
  end
138
- @restriction_query_filters.call(identity).each do |key, filter|
139
- filters << filter
134
+
135
+ temp_filters = @restriction_query_filters.call(identity)
136
+ identity.authorization_filter.restrictions.each do |restriction|
137
+ temp = temp_filters[restriction] or []
138
+ temp.each do |filter|
139
+ filters << JunglePath::Query::Filter.new(filter[:table_name], filter[:sub_select])
140
+ end
140
141
  end
141
- @user_query_filters.call(identity).each do |key, filter|
142
- filters << filter
142
+
143
+ temp_filters = @user_query_filters.call(identity)
144
+ temp = temp_filters[identity.user.id] or []
145
+ temp.each do |filter|
146
+ filters << JunglePath::Query::Filter.new(filter[:table_name], filter[:sub_select])
143
147
  end
148
+
144
149
  filters
145
150
  end
146
151
  end
@@ -13,8 +13,7 @@ module JunglePath
13
13
  user: @user,
14
14
  key: @key,
15
15
  valid: @valid,
16
- role: @roles,
17
- default_role: @default_role,
16
+ role: @role,
18
17
  authorization_filter: @authorization_filter,
19
18
  query_filters: @query_filters
20
19
  }
@@ -1,4 +1,6 @@
1
1
  module JunglePath
2
+ require 'jungle_path/gen/schema_tree'
3
+ require 'jungle_path/gen/schema_tree/filter'
2
4
  require 'jungle_path/gen/schema_tree/node'
3
5
  module Authorization
4
6
  class Filter
@@ -65,6 +67,10 @@ module JunglePath
65
67
  @root_roles
66
68
  end
67
69
 
70
+ def to_s
71
+ "roles: #{@roles}\npermissions: #{@permissions}\nrestrictions: #{@restrictions}\nschema_filter: #{@schema_filter}"
72
+ end
73
+
68
74
  private
69
75
 
70
76
  def eat_roles roles, role_permissions, role_restrictions, role_schema_filters, schema_filters
@@ -1,13 +1,14 @@
1
1
  module JunglePath
2
2
  module Gen
3
3
  module SchemaTree
4
+ require 'jungle_path/gen/schema_tree/match_tables'
4
5
  class Filter
5
6
  def initialize hash=nil
6
7
  throw "Invalid data parameter: expected a hash, but got this: #{hash}" unless hash.class == Hash or hash == nil
7
8
  allow = hash[:allow] if hash
8
9
  deny = hash[:deny] if hash
9
- @match_tables_allow = MatchTables.new allow
10
- @match_tables_deny = MatchTables.new deny
10
+ @match_tables_allow = JunglePath::Gen::SchemaTree::MatchTables.new allow
11
+ @match_tables_deny = JunglePath::Gen::SchemaTree::MatchTables.new deny
11
12
  end
12
13
  def allow? table_name, column_name=nil
13
14
  if @match_tables_allow.matched?(table_name, column_name)
@@ -1,11 +1,12 @@
1
1
  module JunglePath
2
2
  module Gen
3
3
  module SchemaTree
4
+ require 'jungle_path/gen/schema_tree/match_columns'
4
5
  class MatchTableData
5
6
  attr_reader :name, :columns, :regexp
6
7
  def initialize name, columns
7
8
  @name = name
8
- @columns = MatchColumns.new(columns)
9
+ @columns = JunglePath::Gen::SchemaTree::MatchColumns.new(columns)
9
10
  @regexp = @name if @name and @name.class == Regexp
10
11
  end
11
12
 
@@ -1,6 +1,7 @@
1
1
  module JunglePath
2
2
  module Gen
3
3
  module SchemaTree
4
+ require 'jungle_path/gen/schema_tree/match_table_data'
4
5
  class MatchTables
5
6
  def initialize data
6
7
  @hash = {}
@@ -14,7 +15,7 @@ module JunglePath
14
15
  columns = h[:columns]
15
16
  puts "columns: #{columns}."
16
17
  if table
17
- mtd = MatchTableData.new(table, columns)
18
+ mtd = JunglePath::Gen::SchemaTree::MatchTableData.new(table, columns)
18
19
  puts "mtd: #{mtd}."
19
20
  @hash[mtd.name] = mtd
20
21
  @match_data << mtd if mtd.regexp
@@ -6,12 +6,12 @@ require 'jungle_path/query'
6
6
  module JunglePath
7
7
  module Query
8
8
  class Engine
9
- attr_reader :root, :tables, :user, :apply_limit_offset_to_sql
9
+ attr_reader :root, :tables, :identity, :apply_limit_offset_to_sql
10
10
 
11
- #def initialize(tables_hash, user=nil, apply_limit_offset_to_sql=true)
12
- def initialize(node_tree, user=nil, apply_limit_offset_to_sql=true)
11
+ #def initialize(tables_hash, identity=nil, apply_limit_offset_to_sql=true)
12
+ def initialize(node_tree, identity=nil, apply_limit_offset_to_sql=true)
13
13
  @tables = node_tree.tables_hash
14
- @user = user
14
+ @identity = identity
15
15
  @apply_limit_offset_to_sql = apply_limit_offset_to_sql
16
16
  #@root = Gen.gen_node_tree(tables_hash)
17
17
  @root = node_tree
@@ -64,7 +64,7 @@ module JunglePath
64
64
  sort_ids << "#{entity.alias_}.#{field.name}".to_sym
65
65
  end
66
66
  puts "#{entity.alias_}.#{field.name} as \"#{entity.alias_}.#{field.name}\" is_secure? #{field.is_secure?}."
67
- if !field.is_secure? or (field.is_secure? and engine.user.auth.is_root? or engine.user.auth.is_user_admin?)
67
+ if !field.is_secure? or (field.is_secure? and engine.identity.authorization_filter.is_root? or engine.identity.authorization_filter.is_user_admin?)
68
68
  select << "#{entity.alias_}.#{field.name} as \"#{entity.alias_}.#{field.name}\""
69
69
  end
70
70
  end
@@ -96,8 +96,8 @@ module JunglePath
96
96
  def self.hook_in_filters(engine, select, from, where, sort, entity)
97
97
  puts "hook_in_filters QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFf"
98
98
  #binding.pry
99
- if engine.user and engine.user.query_filters
100
- engine.user.query_filters.each do |filter|
99
+ if engine.identity and engine.identity.query_filters
100
+ engine.identity.query_filters.each do |filter|
101
101
  puts "hook_in_filters: filter.table_name: #{filter.table_name}."
102
102
  from.each do |frm|
103
103
  puts "hook_in_filters: frm.table_name: #{frm.table_name}."
@@ -1,3 +1,3 @@
1
1
  module JunglePath
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jungle_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael VanZant
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-24 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler