jungle_path 0.0.1 → 0.0.2

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/jungle_path.gemspec +4 -1
  4. data/lib/jungle_path/api/helpers/auth.rb +6 -10
  5. data/lib/jungle_path/api/helpers/defaults.rb +7 -6
  6. data/lib/jungle_path/api/helpers/logging.rb +7 -1
  7. data/lib/jungle_path/api/helpers.rb +2 -2
  8. data/lib/jungle_path/api/template.erb +2 -2
  9. data/lib/jungle_path/app/api/{server_base.rb → base.rb} +24 -23
  10. data/lib/jungle_path/app/api/{server_custom.rb → custom.rb} +15 -16
  11. data/lib/jungle_path/app/api/{server_gen.rb → generated.rb} +2 -2
  12. data/lib/jungle_path/app/auth/authorization.rb +15 -14
  13. data/lib/jungle_path/app/config/config.rb +8 -9
  14. data/lib/jungle_path/app/config/override.rb +2 -1
  15. data/lib/jungle_path/app/config.ru +6 -5
  16. data/lib/jungle_path/app/controllers/controller.rb +197 -0
  17. data/lib/jungle_path/app/controllers/generated.rb +13 -0
  18. data/lib/jungle_path/app/db/db.rb +13 -0
  19. data/lib/jungle_path/app/schemas/schema.rb +81 -0
  20. data/lib/jungle_path/app/services/email.rb +138 -0
  21. data/lib/jungle_path/app/services/sms.rb +17 -0
  22. data/lib/jungle_path/app/web_apps/public/index.html +10 -0
  23. data/lib/jungle_path/app/ztools/db/migrations/000_root.rb +1 -0
  24. data/lib/jungle_path/app/ztools/zbootstrapdata.rb +57 -0
  25. data/lib/jungle_path/app/ztools/zcreatedb.rb +19 -0
  26. data/lib/jungle_path/app/ztools/zgen.rb +9 -0
  27. data/lib/jungle_path/app/ztools/zgen_node_tree.rb +14 -0
  28. data/lib/jungle_path/app/ztools/zmigrate.rb +7 -0
  29. data/lib/jungle_path/app/ztools/zport_data.rb +292 -0
  30. data/lib/jungle_path/authentication/auth_provider/default.rb +36 -29
  31. data/lib/jungle_path/authentication/data_provider/default.rb +55 -109
  32. data/lib/jungle_path/authentication/data_provider/test.rb +149 -0
  33. data/lib/jungle_path/authentication/data_provider.rb +1 -0
  34. data/lib/jungle_path/authentication/identity.rb +4 -4
  35. data/lib/jungle_path/authentication/password_hash.rb +8 -8
  36. data/lib/jungle_path/authorization/filter.rb +0 -3
  37. data/lib/jungle_path/config.rb +1 -1
  38. data/lib/jungle_path/controller/template.erb +2 -2
  39. data/lib/jungle_path/db_access.rb +6 -0
  40. data/lib/jungle_path/file/file.rb +21 -0
  41. data/lib/jungle_path/file.rb +3 -0
  42. data/lib/jungle_path/gen/api.rb +3 -3
  43. data/lib/jungle_path/gen/controllers.rb +20 -0
  44. data/lib/jungle_path/gen/db.rb +77 -0
  45. data/lib/jungle_path/gen/schema.rb +2 -2
  46. data/lib/jungle_path/gen.rb +1 -1
  47. data/lib/jungle_path/migration/migration.rb +31 -0
  48. data/lib/jungle_path/migration.rb +3 -0
  49. data/lib/jungle_path/rack/json_body_parser.rb +2 -2
  50. data/lib/jungle_path/schema/auth.rb +32 -40
  51. data/lib/jungle_path/sql/key.rb +0 -22
  52. data/lib/jungle_path/sql/query_filter.rb +2 -2
  53. data/lib/jungle_path/sql/role.rb +2 -2
  54. data/lib/jungle_path/sql/user.rb +21 -2
  55. data/lib/jungle_path/time/time.rb +9 -0
  56. data/lib/jungle_path/time.rb +3 -0
  57. data/lib/jungle_path/version.rb +3 -0
  58. data/lib/jungle_path.rb +4 -0
  59. metadata +28 -6
  60. data/lib/jungle_path/gen/controller.rb +0 -0
@@ -0,0 +1,149 @@
1
+ module JunglePath
2
+ require 'jungle_path/authentication/password_hash'
3
+ require 'jungle_path/authorization/filter'
4
+ require 'jungle_path/schema/auth'
5
+ module Authentication
6
+ module DataProvider
7
+ class Test
8
+ def initialize models_hash
9
+ @roles = {
10
+ root: {
11
+ id: 0,
12
+ name: :root,
13
+ description: 'root can do anything',
14
+ permissions: [:root],
15
+ restrictions: []
16
+ },
17
+ admin: {
18
+ id: 1,
19
+ name: :admin,
20
+ description: 'admin and add, edit and delete users, but not root users.',
21
+ permissions: [:admin],
22
+ restrictions: []
23
+ },
24
+ user: {
25
+ id: 2,
26
+ name: :user,
27
+ description: 'basic system user -- has read only access.',
28
+ permissions: [:read],
29
+ restrictions: [:query_only, :me_related]
30
+ }
31
+ }
32
+ @users = {
33
+ root: {
34
+ id: 0,
35
+ name: 'root',
36
+ email: nil,
37
+ phone: nil,
38
+ active: true,
39
+ user_name: :root,
40
+ #password: 'test',
41
+ hash: 'sha1:1000:/CloeFSPBOT7Ac/Jf/qQLk59iQbflhxf:H4eHZ0w51f3UdQpM+tp2DdhofDPkTf2P\n',
42
+ role: :root
43
+ },
44
+ admin: {
45
+ id: 1,
46
+ name: 'admin',
47
+ email: nil,
48
+ phone: nil,
49
+ active: true,
50
+ user_name: :admin,
51
+ #password: 'test',
52
+ hash: 'sha1:1000:/CloeFSPBOT7Ac/Jf/qQLk59iQbflhxf:H4eHZ0w51f3UdQpM+tp2DdhofDPkTf2P\n',
53
+ role: :admin
54
+ },
55
+ user: {
56
+ id: 2,
57
+ name: 'user',
58
+ email: nil,
59
+ phone: nil,
60
+ active: true,
61
+ user_name: :user,
62
+ #password: 'test',
63
+ hash: 'sha1:1000:/CloeFSPBOT7Ac/Jf/qQLk59iQbflhxf:H4eHZ0w51f3UdQpM+tp2DdhofDPkTf2P\n',
64
+ role: :user
65
+ }
66
+ }
67
+ @models = models_hash # (parameter models_hash usually from Schema::Base.models)
68
+ @role_permissions = {}
69
+ @role_restrictions = {}
70
+ @roles.each do |key, role|
71
+ @role_permissions[role[:name]] = role[:permissions]
72
+ @role_restrictions[role[:name]] = role[:restrictions]
73
+ 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
+ }
80
+ }
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
+ }
86
+ }
87
+ @role_query_filters = lambda {|identity|
88
+ filters = {
89
+ admin: [
90
+ {table_name: :table_i_want_to_filter, sub_select: "select id from table_i_want_to_filter where a = b"}
91
+ ]
92
+ # more...
93
+ }
94
+ }
95
+ @restriction_query_filters = lambda {|identity|
96
+ filters = {
97
+ me_related:[
98
+ {table_name: :user, sub_select: "select id from user where id = #{identity.user.id}"}
99
+ ]
100
+ }
101
+ }
102
+ @user_query_filters = lambda {|identity|
103
+ filters = {}
104
+ }
105
+ end
106
+
107
+ def get_user(user_name, password, no_cache=false)
108
+ lower_case_user_name = nil
109
+ lower_case_user_name = user_name.downcase.to_sym if user_name
110
+ hash = @users[lower_case_user_name]
111
+ user = ::Schema::User.new(hash, false) if hash
112
+ halt 401, "Unauthorized" unless user
113
+ halt 401, "Unauthorized: user #{user.user_name} is not marked as active." unless user.active
114
+ #user.is_valid = (user.password == password)
115
+ #user.password = password
116
+ user.is_valid = JunglePath::Authentication::PasswordHash.validate_password(password, user.hash)
117
+ user.password = password
118
+ user
119
+ end
120
+
121
+ def get_user_by_key(key, no_cache=false, password=nil)
122
+ get_user(user_name, password, no_cache)
123
+ end
124
+
125
+ def get_role(identity, no_cache=false)
126
+ @roles[@users[identity.user.user_name.to_sym][:role]]
127
+ end
128
+
129
+ 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))
131
+ end
132
+
133
+ def get_query_filters(identity, no_cache=false)
134
+ filters = []
135
+ @role_query_filters.call(identity).each do |key, filter|
136
+ filters << filter
137
+ end
138
+ @restriction_query_filters.call(identity).each do |key, filter|
139
+ filters << filter
140
+ end
141
+ @user_query_filters.call(identity).each do |key, filter|
142
+ filters << filter
143
+ end
144
+ filters
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -2,6 +2,7 @@ module JunglePath
2
2
  module Authentication
3
3
  module DataProvider
4
4
  require 'jungle_path/authentication/data_provider/default'
5
+ require 'jungle_path/authentication/data_provider/test'
5
6
  end
6
7
  end
7
8
  end
@@ -1,9 +1,9 @@
1
1
  module JunglePath
2
2
  module Authentication
3
3
  class Identity
4
- attr_accessor :remote_user, :remote_password, :user_name, :user, :key, :valid, :roles, :default_role, :auth, :query_filters
4
+ attr_accessor :remote_user, :remote_password, :user_name, :user, :key, :valid, :role, :authorization_filter, :query_filters
5
5
  def to_s
6
- "JunglePath::Authentication::Identity: {\n remote_user: #{@remote_user},\n remote_password: #{@remote_password},\n user_name: #{@user_name},\n user: #{@user},\n key: #{@key},\n valid: #{@valid},\n roles: #{@roles},\n auth: #{@auth}\n,query_filters: #{@query_filters}\n}"
6
+ "JunglePath::Authentication::Identity: {\n remote_user: #{@remote_user},\n remote_password: #{@remote_password},\n user_name: #{@user_name},\n user: #{@user},\n key: #{@key},\n valid: #{@valid},\n role: #{@role},\n authorization_filter: #{@authorization_filter}\n,query_filters: #{@query_filters}\n}"
7
7
  end
8
8
  def to_h
9
9
  {
@@ -13,9 +13,9 @@ module JunglePath
13
13
  user: @user,
14
14
  key: @key,
15
15
  valid: @valid,
16
- roles: @roles,
16
+ role: @roles,
17
17
  default_role: @default_role,
18
- auth: @auth,
18
+ authorization_filter: @authorization_filter,
19
19
  query_filters: @query_filters
20
20
  }
21
21
  end
@@ -51,7 +51,7 @@ module JunglePath
51
51
  HASH_INDEX = 3
52
52
 
53
53
  # Returns a salted PBKDF2 hash of the password.
54
- def self.createHash( password )
54
+ def self.create_hash( password )
55
55
  salt = SecureRandom.base64( SALT_BYTE_SIZE )
56
56
  pbkdf2 = OpenSSL::PKCS5::pbkdf2_hmac_sha1(
57
57
  password,
@@ -63,8 +63,8 @@ module JunglePath
63
63
  end
64
64
 
65
65
  # Checks if a password is correct given a hash of the correct one.
66
- # correctHash must be a hash string generated with createHash.
67
- def self.validatePassword( password, correctHash )
66
+ # correctHash must be a hash string generated with create_hash.
67
+ def self.validate_password( password, correctHash )
68
68
  params = correctHash.split( SECTION_DELIMITER )
69
69
  return false if params.length != HASH_SECTIONS
70
70
 
@@ -83,20 +83,20 @@ module JunglePath
83
83
  # Returns true if all tests succeed, false if not.
84
84
  def self.runSelfTests
85
85
  puts "Sample hashes:"
86
- 3.times { puts createHash("password") }
86
+ 3.times { puts create_hash("password") }
87
87
 
88
88
  puts "\nRunning self tests..."
89
89
  @@allPass = true
90
90
 
91
91
  correctPassword = 'aaaaaaaaaa'
92
92
  wrongPassword = 'aaaaaaaaab'
93
- hash = createHash(correctPassword)
93
+ hash = create_hash(correctPassword)
94
94
 
95
- assert( validatePassword( correctPassword, hash ) == true, "correct password" )
96
- assert( validatePassword( wrongPassword, hash ) == false, "wrong password" )
95
+ assert( validate_password( correctPassword, hash ) == true, "correct password" )
96
+ assert( validate_password( wrongPassword, hash ) == false, "wrong password" )
97
97
 
98
98
  h1 = hash.split( SECTION_DELIMITER )
99
- h2 = createHash( correctPassword ).split( SECTION_DELIMITER )
99
+ h2 = create_hash( correctPassword ).split( SECTION_DELIMITER )
100
100
  assert( h1[HASH_INDEX] != h2[HASH_INDEX], "different hashes" )
101
101
  assert( h1[SALT_INDEX] != h2[SALT_INDEX], "different salt" )
102
102
 
@@ -1,9 +1,6 @@
1
1
  module JunglePath
2
2
  require 'jungle_path/gen/schema_tree/node'
3
3
  module Authorization
4
- # will need to assign roles to user keys or nothing will show up in keys? Yes.
5
- # Look at created at datetime for keys?...
6
- # *** add any new accounts to bootstrap data with hard coded key values, etc.!
7
4
  class Filter
8
5
  def initialize roles, schema_models_hash, role_permissions={}, role_restrictions={}, role_schema_filters={}, schema_filters={}
9
6
  @schema_models_hash = schema_models_hash
@@ -56,7 +56,7 @@ module JunglePath
56
56
  #def configatron
57
57
  # Config::ConfigurationRoot.instance
58
58
  #end
59
- def config_jungle
59
+ def jungle
60
60
  Config::ConfigurationRoot.instance
61
61
  end
62
62
  end
@@ -1,7 +1,7 @@
1
1
  <% #controller_template.erb %>
2
2
  <%= "#This file was generated using the jungle_path/controller/controller_template.erb. Do not modify directly." %>
3
- require_relative 'jungle_path/controller'
4
- require_relative 'jungle_path/schema'
3
+ require 'jungle_path/controller'
4
+ require_relative '<%= schema_require_relative %>'
5
5
 
6
6
  module <%= controller_name_space %>
7
7
  <% for table in tables %>
@@ -0,0 +1,6 @@
1
+ module JunglePath
2
+ module DBAccess
3
+ require 'jungle_path/db_access/import'
4
+ require 'jungle_path/db_access/io'
5
+ end
6
+ end
@@ -0,0 +1,21 @@
1
+ require 'jungle_path/time'
2
+
3
+ module JunglePath
4
+ module File
5
+ def self.add_timestamp_to_file_name file_name, post_fix=true
6
+ stamp = JunglePath::Time.utc_timestamp
7
+
8
+ path_parts = file_name.split('/')
9
+
10
+ parts = path_parts[-1].split('.')
11
+ if post_fix
12
+ parts[0] = "#{parts[0]}_#{stamp}"
13
+ else
14
+ parts[0] = "#{stamp}_#{parts[0]}"
15
+ end
16
+
17
+ path_parts[-1] = parts.join('.')
18
+ path_parts.join('/')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module JunglePath
2
+ require 'jungle_path/file/file'
3
+ end
@@ -33,14 +33,14 @@ end
33
33
 
34
34
  module JunglePath
35
35
  module Gen
36
- def self.api(app_root_path, tables, output_file='./api/api_gen.rb', name_space='ServerAPI', controller_name_space='Controller', template_file=nil)
36
+ def self.api(app_root_path, tables, output_file='./api/generated.rb', name_space='Server', controller_name_space='Controller', class_name='API', base_class_name='Base', template_file=nil)
37
37
  if template_file
38
38
  template_file = ::File.expand_path(template_file, app_root_path)
39
39
  else
40
- template_file = ::File.expand_path('./api_template.erb', ::File.dirname(__FILE__))
40
+ template_file = ::File.expand_path('../api/template.erb', ::File.dirname(__FILE__))
41
41
  end
42
42
 
43
- # template uses name_space and controller_name_space vars:``
43
+ # template uses name_space,controller_name_space, class_name and base_class_name vars:``
44
44
  template = ERB.new(File.read(template_file))
45
45
 
46
46
  output_file = ::File.expand_path(output_file, app_root_path)
@@ -0,0 +1,20 @@
1
+ # gen_controller.rb
2
+ require 'erb'
3
+
4
+ module Gen
5
+ def self.controllers(app_root_path, tables, output_file='./controllers/generated.rb', controller_name_space='Controller', schema_require_relative='../schemas/schema', template_file=nil)
6
+ if template_file
7
+ template_file = ::File.expand_path(template_file, app_root_path)
8
+ else
9
+ template_file = ::File.expand_path('../controller/template.erb', ::File.dirname(__FILE__))
10
+ end
11
+
12
+ # template uses name_space and controller_name_space vars:``
13
+ template = ERB.new(File.read(template_file))
14
+
15
+ output_file = ::File.expand_path(output_file, app_root_path)
16
+ result = template.result(binding)
17
+ puts result
18
+ File.write(output_file, result)
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ # gen_db.rb -- drops and creates a postgresql database from the commandline dropdb/createdb commands.
2
+ require 'jungle_path/db_access/io'
3
+
4
+ module JunglePath
5
+ module Gen
6
+ module DB
7
+ def self.create(config)
8
+ puts "Gen::DB.create: #{config.name}."
9
+ db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
10
+ sql = "create database #{config.name}"
11
+ db.run sql
12
+ end
13
+
14
+ def self.drop!(config)
15
+ puts "Gen::DB.drop: #{config.name}."
16
+ kill_connections! config
17
+ db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
18
+ sql = "drop database #{config.name}"
19
+ db.run sql
20
+ end
21
+
22
+ def self.drop?(config)
23
+ if exists?(config)
24
+ drop! config
25
+ end
26
+ end
27
+
28
+ def self.reset!(config)
29
+ drop? config
30
+ create config
31
+ end
32
+
33
+ def self.exists?(config) # todo: fix to also work for ms sql server.
34
+ puts "Gen::DB.exists? #{config.name}."
35
+ exists = false
36
+ db = JunglePath::DBAccess::IO.connection_from_config_unknown_database(config)
37
+ sql = sql_query_db_existence(config)
38
+ db.fetch(sql) do |row|
39
+ exists = true
40
+ end
41
+ exists
42
+ end
43
+
44
+ def self.rename(config_from, to_name)
45
+ puts "GenDB.rename: #{config_from.name} to #{to_name}."
46
+ kill_connections! config_from
47
+ db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config_from)
48
+ sql = "alter database #{config_from.name} rename to #{to_name}"
49
+ db.run sql
50
+ end
51
+
52
+ def self.rename?(config_from, to_name)
53
+ if exists?(config_from)
54
+ rename config_from, to_name
55
+ end
56
+ end
57
+
58
+ def self.kill_connections!(config)
59
+ db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config)
60
+ sql = "select pg_terminate_backend(pid) from pg_stat_activity where datname = '#{config.name}'"
61
+ db.run sql
62
+ end
63
+
64
+ private
65
+
66
+ def self.sql_query_db_existence(config)
67
+ if config.type == 'postgres'
68
+ "select datname from pg_database where datname = '#{config.name}'"
69
+ elsif config.type == 'tinytds'
70
+ "select * from master.sys.databases where name = '#{config.name}'"
71
+ else
72
+ throw "Unknown database type: #{config.type}."
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -10,7 +10,7 @@ module JunglePath
10
10
  module Schema
11
11
  def self.create(table_subclasses, db_config, logger=$stdout)
12
12
  puts "Gen::Schema.create..."
13
- db = JunglePath::DBAccess.connection_from_config(db_config)
13
+ db = JunglePath::DBAccess::IO.connection_from_config(db_config)
14
14
  db.loggers << Logger.new(logger)
15
15
  schema = JunglePath::DBModel::Schema.new(db)
16
16
  table_subclasses.each do |table|
@@ -21,7 +21,7 @@ module JunglePath
21
21
 
22
22
  def self.set_version schema_info_class, db_config, schema_initial_version
23
23
  # set starting version numnber
24
- db = JunglePath::DBAccess::DB.new(db_config)
24
+ db = JunglePath::DBAccess::IO::DB.new(db_config)
25
25
  db.schema.create_table schema_info_class
26
26
  if schema_initial_version
27
27
  schema_info = schema_info_class.new({version: schema_initial_version})
@@ -1,7 +1,7 @@
1
1
  module JunglePath
2
2
  module Gen
3
3
  require 'jungle_path/api'
4
- require 'jungle_path/controller'
4
+ require 'jungle_path/controllers'
5
5
  require 'jungle_path/db'
6
6
  require 'jungle_path/schema'
7
7
  require 'jungle_path/schema_tree'
@@ -0,0 +1,31 @@
1
+ require 'logger'
2
+ require 'sequel'
3
+ require 'jungle_path/gen/db'
4
+
5
+ module Migration
6
+ def self.run schema_module, db, version=nil
7
+ Sequel.extension :migration
8
+
9
+ db.base.loggers << Logger.new($stdout)
10
+ db.base.identifier_input_method = :downcase
11
+ version = schema_module.version unless version
12
+ path = schema_module.migrations_path
13
+ display_version = version || "'latest available'"
14
+
15
+ puts "Migrating database to version: #{display_version} on #{db.config.host}.#{db.config.name}:#{db.config.port}."
16
+ puts "Using migration files at: #{path}"
17
+
18
+ if JunglePath::Gen::DB.exists? db.config # todo: fix for sql server!
19
+ # migrate to current or passed version.
20
+ if version
21
+ Sequel::Migrator.run(db.base, path, target: version)
22
+ else
23
+ Sequel::Migrator.run(db.base, path)
24
+ end
25
+ else
26
+ # create from scratch and set the version in the new db.
27
+ puts "Database does not exist, run zcreatedb.rb and then zbootstrapdata.rb..."
28
+ puts "Write some code to create the schema_info table with integer column version and set the version! This table should always have only one row."
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module JunglePath
2
+ require 'jungle_path/migration/migration'
3
+ end
@@ -4,7 +4,7 @@
4
4
  #rescue LoadError => e
5
5
  # require 'json/pure'
6
6
  #end
7
- #require 'rack'
7
+ require 'rack'
8
8
 
9
9
  module JunglePath
10
10
  require 'jungle_path/json'
@@ -28,7 +28,7 @@ module JunglePath
28
28
  end
29
29
 
30
30
  def call(env)
31
- if Rack::Request.new(env).media_type == APPLICATION_JSON && (body = env[POST_BODY].read).length != 0
31
+ if ::Rack::Request.new(env).media_type == APPLICATION_JSON && (body = env[POST_BODY].read).length != 0
32
32
  puts "rack body: #{body}."
33
33
  env[POST_BODY].rewind # somebody might try to read this stream
34
34
  #env.update(FORM_HASH => JSON.parse(body, :symbolize_names=>@symbolize_names), FORM_INPUT => env[POST_BODY])
@@ -5,51 +5,41 @@ module Schema
5
5
  define(
6
6
  [:id, :primary_key],
7
7
  [:key, :string, :unique, :secure, :not_null],
8
- [:name, :string, :not_null],
9
- [:user_id, :foreign_key, :user, :not_null, :unique_index, [:user_id, :name]],
8
+ [:user_id, :foreign_key, :user, :not_null, :index],
10
9
  [:expires_at, :timestamp, :not_null],
11
- [:is_default, :boolean, :default, false],
12
- [:audit_key]
10
+ [:audit_user]
13
11
  )
14
12
  end
15
13
 
16
- class UserQueryFilter < Schema::Base
17
- self.description = "Links users to query_filters -- will be used to restrict certain users to only be able to query entities (such as products, etc.) as restricted by the related query_filter."
18
- define(
19
- [:user_id, :foreign_key, :user, :primary_key],
20
- [:query_filter_id, :foreign_key, :query_filter, :primary_key],
21
- [:audit_key]
22
- )
23
- end
24
-
25
- class KeyRole < Schema::Base
26
- define(
27
- [:user_id, :foreign_key, :user, :primary_key],
28
- [:role_id, :foreign_key, :role, :primary_key],
29
- [:audit_key]
30
- )
31
- end
14
+ #class UserQueryFilter < Schema::Base
15
+ # self.description = "Links users to query_filters -- will be used to restrict certain users to only be able to query entities (such as products, etc.) as restricted by the related query_filter."
16
+ # define(
17
+ # [:user_id, :foreign_key, :user, :primary_key],
18
+ # [:query_filter_id, :foreign_key, :query_filter, :primary_key],
19
+ # [:audit_key]
20
+ # )
21
+ #end
32
22
 
33
- class QueryFilter < Schema::Base
34
- self.description = "misc. filters to apply against product/or other entities of the form: select product.id from product join table_x on table_x.product_id = product.id where table_x.some_column = 'abc'"
35
- define(
36
- [:id, :primary_key],
37
- [:name, :string, :desc, "Give this filter a name so you know who it should apply to."],
38
- [:base_table_name, :string, :desc, "Should be the name of the base table you are filtering on such as 'product'. Your filter will be applied to any queries containing tables which relate to the base table."],
39
- [:sub_select, :string, :desc, "Your sub_select query should select a set of ids from your base table. You can join to any other related tables and add where clause conditions. Do not use table aliases, instead use the full table names to avoid naming collisions as your sub_select will be hooked into queries generated by API users."],
40
- [:use_not_in, :boolean, :desc, "use a query like 'id not in (list....)' instead of 'id in (list...)'."],
41
- [:audit_key]
42
- )
43
- end
23
+ #class QueryFilter < Schema::Base
24
+ # self.description = "misc. filters to apply against product/or other entities of the form: select product.id from product join table_x on table_x.product_id = product.id where table_x.some_column = 'abc'"
25
+ # define(
26
+ # [:id, :primary_key],
27
+ # [:name, :string, :desc, "Give this filter a name so you know who it should apply to."],
28
+ # [:base_table_name, :string, :desc, "Should be the name of the base table you are filtering on such as 'product'. Your filter will be applied to any queries containing tables which relate to the base table."],
29
+ # [:sub_select, :string, :desc, "Your sub_select query should select a set of ids from your base table. You can join to any other related tables and add where clause conditions. Do not use table aliases, instead use the full table names to avoid naming collisions as your sub_select will be hooked into queries generated by API users."],
30
+ # [:use_not_in, :boolean, :desc, "use a query like 'id not in (list....)' instead of 'id in (list...)'."],
31
+ # [:audit_key]
32
+ # )
33
+ #end
44
34
 
45
- class Role < Schema::Base # use roles to group privileges and restrictions
46
- define(
47
- [:id, :primary_key],
48
- [:name, :string, :unique_index, [:name], :not_null],
49
- [:description, :string],
50
- [:audit_key]
51
- )
52
- end
35
+ #class Role < Schema::Base # use roles to group privileges and restrictions
36
+ # define(
37
+ # [:id, :primary_key],
38
+ # [:name, :string, :unique_index, [:name], :not_null],
39
+ # [:description, :string],
40
+ # [:audit_key]
41
+ # )
42
+ #end
53
43
 
54
44
  class User < Schema::Base
55
45
  self.description = "User of system."
@@ -63,6 +53,7 @@ module Schema
63
53
  [:notes, :string, :desc, "For any misc. notes about this user including addition email addresses, phone numbers, etc."],
64
54
  [:active, :boolean, :default, true],
65
55
  [:is_valid, :boolean, :calculated],
56
+ [:role, :string, :not_null],
66
57
  [:audit_user]
67
58
  )
68
59
  end
@@ -70,7 +61,8 @@ module Schema
70
61
  class User
71
62
  @auth
72
63
  @query_filters
73
- attr_accessor :auth, :query_filters
64
+ @password
65
+ attr_accessor :auth, :query_filters, :password
74
66
  end
75
67
 
76
68
  class Key
@@ -61,28 +61,6 @@ module JunglePath
61
61
  ds.all
62
62
  end
63
63
 
64
- def self.by_user_id(db, user_id)
65
- sql = JunglePath::SQL::Helpers.sql("
66
- #{base_sql}
67
- where a.user_id = ?
68
- order by a.id
69
- ")
70
- ds = db.base[sql, user_id]
71
- ds.all
72
- end
73
-
74
- def self.default_by_user_id(db, user_id)
75
- sql = JunglePath::SQL::Helpers.sql("
76
- #{base_sql}
77
- where a.user_id = ?
78
- and a.is_default = true
79
- order by a.id
80
- ")
81
- #puts "sql:\n#{sql}."
82
- ds = db.base[sql, user_id]
83
- ds.all
84
- end
85
-
86
64
  private
87
65
 
88
66
  def self.base_sql
@@ -3,7 +3,7 @@ require 'jungle_path/sql/helpers'
3
3
  module JunglePath
4
4
  module SQL
5
5
  module QueryFilter
6
- def self.by_user db, key
6
+ def self.by_user db, user
7
7
  sql = JunglePath::SQL::Helpers.sql("
8
8
  select
9
9
  a.id,
@@ -15,7 +15,7 @@ module JunglePath
15
15
  where b.user_id = ?
16
16
  ")
17
17
 
18
- ds = db.base[sql, key.id]
18
+ ds = db.base[sql, user.id]
19
19
  result = ds.all
20
20
  array = []
21
21
  result.each do |row|
@@ -3,7 +3,7 @@ require 'jungle_path/sql/helpers'
3
3
  module JunglePath
4
4
  module SQL
5
5
  module Role
6
- def self.by_user db, key
6
+ def self.by_user db, user
7
7
  sql = JunglePath::SQL::Helpers.sql("
8
8
  select
9
9
  a.id,
@@ -14,7 +14,7 @@ module JunglePath
14
14
  where b.user_id = ?
15
15
  ")
16
16
 
17
- ds = db.base[sql, key.id]
17
+ ds = db.base[sql, user.id]
18
18
  result = ds.all
19
19
  array = []
20
20
  result.each do |row|