jungle_path 0.0.0

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 (129) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +22 -0
  6. data/README.md +5 -0
  7. data/jungle_path.gemspec +43 -0
  8. data/lib/jungle_path/api/helpers/auth.rb +45 -0
  9. data/lib/jungle_path/api/helpers/auth_local_user.rb +284 -0
  10. data/lib/jungle_path/api/helpers/auth_old.rb +232 -0
  11. data/lib/jungle_path/api/helpers/data_cache.rb +20 -0
  12. data/lib/jungle_path/api/helpers/defaults.rb +83 -0
  13. data/lib/jungle_path/api/helpers/logging.rb +36 -0
  14. data/lib/jungle_path/api/helpers/query_filters.rb +15 -0
  15. data/lib/jungle_path/api/helpers/rescues.rb +15 -0
  16. data/lib/jungle_path/api/helpers/result.rb +16 -0
  17. data/lib/jungle_path/api/helpers/standard_apis.rb +280 -0
  18. data/lib/jungle_path/api/helpers.rb +16 -0
  19. data/lib/jungle_path/api/template.erb +35 -0
  20. data/lib/jungle_path/api.rb +5 -0
  21. data/lib/jungle_path/app/a.gitignore +1 -0
  22. data/lib/jungle_path/app/api/server_base.rb +95 -0
  23. data/lib/jungle_path/app/api/server_custom.rb +121 -0
  24. data/lib/jungle_path/app/api/server_gen.rb +11 -0
  25. data/lib/jungle_path/app/auth/authorization.rb +96 -0
  26. data/lib/jungle_path/app/config/a.gitignore +1 -0
  27. data/lib/jungle_path/app/config/config.rb +240 -0
  28. data/lib/jungle_path/app/config/override.rb +3 -0
  29. data/lib/jungle_path/app/config.ru +28 -0
  30. data/lib/jungle_path/app/logs/log_files_go_here +0 -0
  31. data/lib/jungle_path/app/run.sh +4 -0
  32. data/lib/jungle_path/app/schemas/schema.rb +21 -0
  33. data/lib/jungle_path/app/schemas/schema_all_in_one.rb +181 -0
  34. data/lib/jungle_path/app.rb +8 -0
  35. data/lib/jungle_path/authentication/auth_provider/default.rb +83 -0
  36. data/lib/jungle_path/authentication/auth_provider.rb +7 -0
  37. data/lib/jungle_path/authentication/data_provider/default.rb +144 -0
  38. data/lib/jungle_path/authentication/data_provider.rb +7 -0
  39. data/lib/jungle_path/authentication/helpers.rb +19 -0
  40. data/lib/jungle_path/authentication/identity.rb +30 -0
  41. data/lib/jungle_path/authentication/password_hash.rb +124 -0
  42. data/lib/jungle_path/authentication.rb +9 -0
  43. data/lib/jungle_path/authorization/filter.rb +106 -0
  44. data/lib/jungle_path/authorization/paths.rb +71 -0
  45. data/lib/jungle_path/authorization.rb +5 -0
  46. data/lib/jungle_path/cache.rb +36 -0
  47. data/lib/jungle_path/config.rb +65 -0
  48. data/lib/jungle_path/controller/authentication.rb +129 -0
  49. data/lib/jungle_path/controller/base.rb +193 -0
  50. data/lib/jungle_path/controller/helpers.rb +47 -0
  51. data/lib/jungle_path/controller/template.erb +14 -0
  52. data/lib/jungle_path/controller.rb +7 -0
  53. data/lib/jungle_path/db_access/import/db_dir.rb +74 -0
  54. data/lib/jungle_path/db_access/import/delete.rb +30 -0
  55. data/lib/jungle_path/db_access/import/insert.rb +168 -0
  56. data/lib/jungle_path/db_access/import/schema.rb +34 -0
  57. data/lib/jungle_path/db_access/import/select.rb +68 -0
  58. data/lib/jungle_path/db_access/import.rb +15 -0
  59. data/lib/jungle_path/db_access/io/chunked_file_reader.rb +62 -0
  60. data/lib/jungle_path/db_access/io/config.rb +19 -0
  61. data/lib/jungle_path/db_access/io/copy.rb +73 -0
  62. data/lib/jungle_path/db_access/io/db.rb +82 -0
  63. data/lib/jungle_path/db_access/io/delete.rb +23 -0
  64. data/lib/jungle_path/db_access/io/init_db.rb +39 -0
  65. data/lib/jungle_path/db_access/io/insert.rb +24 -0
  66. data/lib/jungle_path/db_access/io/schema.rb +21 -0
  67. data/lib/jungle_path/db_access/io/select.rb +44 -0
  68. data/lib/jungle_path/db_access/io/update.rb +36 -0
  69. data/lib/jungle_path/db_access/io.rb +104 -0
  70. data/lib/jungle_path/db_model/column.rb +186 -0
  71. data/lib/jungle_path/db_model/params.rb +60 -0
  72. data/lib/jungle_path/db_model/schema.rb +100 -0
  73. data/lib/jungle_path/db_model/string.rb +9 -0
  74. data/lib/jungle_path/db_model/table.rb +307 -0
  75. data/lib/jungle_path/db_model.rb +34 -0
  76. data/lib/jungle_path/exceptions.rb +10 -0
  77. data/lib/jungle_path/gen/api.rb +52 -0
  78. data/lib/jungle_path/gen/controller.rb +0 -0
  79. data/lib/jungle_path/gen/db.rb +0 -0
  80. data/lib/jungle_path/gen/schema.rb +47 -0
  81. data/lib/jungle_path/gen/schema_tree/filter.rb +33 -0
  82. data/lib/jungle_path/gen/schema_tree/match_columns.rb +54 -0
  83. data/lib/jungle_path/gen/schema_tree/match_table_data.rb +22 -0
  84. data/lib/jungle_path/gen/schema_tree/match_tables.rb +70 -0
  85. data/lib/jungle_path/gen/schema_tree/node.rb +39 -0
  86. data/lib/jungle_path/gen/schema_tree.rb +105 -0
  87. data/lib/jungle_path/gen.rb +9 -0
  88. data/lib/jungle_path/json/base.rb +29 -0
  89. data/lib/jungle_path/json/time.rb +8 -0
  90. data/lib/jungle_path/json.rb +6 -0
  91. data/lib/jungle_path/logging.rb +23 -0
  92. data/lib/jungle_path/query/alias_info.rb +16 -0
  93. data/lib/jungle_path/query/engine.rb +878 -0
  94. data/lib/jungle_path/query/entity.rb +141 -0
  95. data/lib/jungle_path/query/field.rb +28 -0
  96. data/lib/jungle_path/query/field_primary_key.rb +27 -0
  97. data/lib/jungle_path/query/filter.rb +34 -0
  98. data/lib/jungle_path/query/float_value.rb +16 -0
  99. data/lib/jungle_path/query/from.rb +33 -0
  100. data/lib/jungle_path/query/int_value.rb +16 -0
  101. data/lib/jungle_path/query/limit.rb +19 -0
  102. data/lib/jungle_path/query/nested_hash_sorter.rb +94 -0
  103. data/lib/jungle_path/query/operator.rb +17 -0
  104. data/lib/jungle_path/query/query.rb +23 -0
  105. data/lib/jungle_path/query/sort_field.rb +34 -0
  106. data/lib/jungle_path/query/sql_string.rb +145 -0
  107. data/lib/jungle_path/query/string_value.rb +16 -0
  108. data/lib/jungle_path/query.rb +19 -0
  109. data/lib/jungle_path/rack/basic_credentials.rb +70 -0
  110. data/lib/jungle_path/rack/json_body_parser.rb +41 -0
  111. data/lib/jungle_path/rack.rb +6 -0
  112. data/lib/jungle_path/schema/auth.rb +83 -0
  113. data/lib/jungle_path/schema/base.rb +6 -0
  114. data/lib/jungle_path/schema/db.rb +10 -0
  115. data/lib/jungle_path/schema/version.rb +19 -0
  116. data/lib/jungle_path/schema.rb +8 -0
  117. data/lib/jungle_path/sql/auth_local_user.rb +5 -0
  118. data/lib/jungle_path/sql/general.rb +10 -0
  119. data/lib/jungle_path/sql/helpers.rb +11 -0
  120. data/lib/jungle_path/sql/key.rb +107 -0
  121. data/lib/jungle_path/sql/query_filter.rb +5 -0
  122. data/lib/jungle_path/sql/role.rb +5 -0
  123. data/lib/jungle_path/sql/user.rb +35 -0
  124. data/lib/jungle_path/sql/user_role.rb +5 -0
  125. data/lib/jungle_path/sql.rb +12 -0
  126. data/lib/jungle_path.rb +13 -0
  127. data/test.rb +33 -0
  128. data/test2.rb +15 -0
  129. metadata +200 -0
@@ -0,0 +1,121 @@
1
+ #require 'pry-byebug'
2
+ require 'time'
3
+ require 'date'
4
+ require 'pp'
5
+
6
+ require_relative '../config/base_config'
7
+ require_relative '../../lib/query'
8
+ require_relative '../../lib/controller'
9
+ require_relative '../../lib/key_helpers'
10
+ require_relative '../../lib/gen_node_tree'
11
+ #require_relative 'pubnub_rs'
12
+ require_relative '../db/db'
13
+ require_relative '../schemas/schema'
14
+ require_relative 'server_base'
15
+ require_relative '../utils/utils'
16
+ require_relative '../controllers/controller'
17
+ require_relative '../services/email'
18
+
19
+ module Server
20
+ class API < Server::BaseAPI
21
+ get '/' do
22
+ # default page:
23
+ #if request.env['X_MOBILE_DEVICE']
24
+ # #{}"<html><head></head><body>This is mobile!</body></html>"
25
+ # send_file File.join(settings.public_folder, 'index_mobile.html')
26
+ #else
27
+ #send_file File.join(settings.public_folder, 'src/pages/app/app.html')
28
+ #"you are here"
29
+ send_file File.join(settings.public_folder, 'index.html')
30
+ #end
31
+ end
32
+
33
+ get '/app' do
34
+ #"<html><head></head><body>zzzIs this mobile? mobile: #{request.env['X_MOBILE_DEVICE']}</body></html>"
35
+ #send_file File.join(settings.public_folder, 'src/pages/app/app.html')
36
+ send_file File.join(settings.public_folder, 'lib/pages/app/app.html')
37
+ #"admin #{settings.public_folder}"
38
+ end
39
+
40
+ get '/admin' do
41
+ #"<html><head></head><body>zzzIs this mobile? mobile: #{request.env['X_MOBILE_DEVICE']}</body></html>"
42
+ #send_file File.join(settings.public_folder, 'src/pages/app/app.html')
43
+ send_file File.join(settings.public_folder, 'src/pages/app/app.html')
44
+ #"admin #{settings.public_folder}"
45
+ end
46
+
47
+ get '/query' do
48
+ send_file File.join(settings.public_folder, 'query/query.html')
49
+ #file = File.join(settings.public_folder, 'query/query.html')
50
+ #"query #{settings.public_folder}<br>file: #{file}"
51
+ end
52
+
53
+ get '/query/doc' do
54
+ file = File.join(configatron.application.public_dir, 'query/documents/query_api_documentation.txt')
55
+ send_file File.join(file)
56
+ end
57
+
58
+ get '/query/schema_tree' do
59
+ #root = Gen.gen_node_tree(Schema::Base.models)
60
+ template_file = File.join(configatron.application.public_dir, 'query/documents/schema_tree_template.txt')
61
+ template = File.read(template_file)
62
+
63
+ node_tree = current_auth.schema_node_tree
64
+ #template_output = "#{template}\n\n#{root.to_str}"
65
+ template_output = "#{template}\n\n#{node_tree.to_str}"
66
+
67
+ #output_file = File.join(configatron.application.public_dir, 'query/documents/schema_tree.txt')
68
+ #File.write(output_file, template_output)
69
+ #send_file File.join(output_file)
70
+ template_output
71
+ end
72
+
73
+ get '/db/version' do
74
+ ds = db.base['select version from schema_info']
75
+ handle_result(ds.all)
76
+ end
77
+
78
+ get '/cachetest/:key' do
79
+ key = params[:key]
80
+ value = LocalCache[key]
81
+ handle_result({key: "#{key}", value: "#{value}"})
82
+ end
83
+
84
+ get '/cachetest/:key/:value' do
85
+ key = params[:key]
86
+ value = params[:value]
87
+ LocalCache[key] = value
88
+ handle_result({key: "#{key}", value: "#{value}"})
89
+ end
90
+
91
+ get '/current/identity' do
92
+ handle_result({identity: current_identity})
93
+ end
94
+
95
+ get '/current/user' do
96
+ handle_result({user: current_user, key: current_key, roles: current_roles, auth: {permissions: current_auth.permissions, restrictions: current_auth.restrictions, schema_filter: current_auth.schema_filter}} )
97
+ end
98
+
99
+ get '/current/user/auth' do
100
+ message = {
101
+ user_id: current_user.id,
102
+ user_name: current_user.user_name,
103
+ key_id: current_key.id,
104
+ key_name: current_key.name,
105
+ key_value: current_key.key,
106
+ roles: current_auth.roles,
107
+ permissions: current_auth.permissions,
108
+ restrictions: current_auth.restrictions,
109
+ schema_filter: current_auth.schema_filter
110
+ }
111
+ handle_result message
112
+ end
113
+
114
+ post '/debug/params' do
115
+ puts "/debug/params:"
116
+ pp params
117
+ end
118
+ end
119
+ end
120
+
121
+ require_relative 'server_gen'
@@ -0,0 +1,11 @@
1
+ #This file was generated using the ../lib/api_template.erb. Do not modify directly.
2
+ require 'sinatra/base'
3
+ require_relative '../db/db'
4
+ require_relative '../schemas/schema'
5
+ require_relative 'base_api'
6
+ require_relative '../controllers/controller'
7
+
8
+ module Server
9
+ class API < Server::BaseAPI
10
+ end
11
+ end
@@ -0,0 +1,96 @@
1
+ require 'jungle_path/authorization/paths'
2
+ require '../config/config'
3
+
4
+ module ServerAPI
5
+ module Authorization
6
+ def set_authorization
7
+ before do
8
+ puts "verb: #{request.request_method}."
9
+ puts "path: #{request.path_info}."
10
+
11
+ authorized = false
12
+
13
+ authorized = JunglePath::Authorization::Path.is_open_path?(request, jungle.route_access)
14
+ authorized = JunglePath::Authorization::Path.is_authenticated_path?(request, jungle.route_access) unless authorized
15
+
16
+ unless authorized
17
+ if request.get?
18
+ authorized = true if current_auth.has_permission?(:root)
19
+ authorized = true if current_auth.has_permission?(:read)
20
+ end
21
+
22
+ if request.post? or request.put? or request.delete?
23
+ authorized = true if current_auth.has_permission?(:root) unless authorized
24
+ authorized = true if current_auth.has_permission?(:write) unless authorized
25
+ authorized = true if request.path_info == "/query" and current_auth.has_permission?(:read) unless authorized
26
+ authorized = true if request.path_info == "/users/#{current_user.id}" unless authorized
27
+ authorized = true if ServerAPI::Authorization.authorized_admin?(request, params, current_auth, db) unless authorized
28
+ authorized = false if current_auth.has_restriction?(:read)
29
+ end
30
+
31
+ authorized = false if current_auth.has_restriction?(:query_only) unless JunglePath::Authorization::Path.is_query_only_path? request, current_auth
32
+ end
33
+
34
+ unless authorized
35
+ message = "request was not allowed.\n\nrequest: #{request.request_method} #{request.path_info}\nuser_name: #{current_user.user_name}\napi key name: #{current_key.name}\napi key value: #{current_key.key}\nroles: #{current_auth.roles}\npermissions: #{current_auth.permissions}\nrestrictions: #{current_auth.restrictions}"
36
+ # http status code 403 Forbidden.
37
+ puts "request status: 403\n#{message}."
38
+ halt 403, message
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.authorized_admin? request, params, current_auth, db
44
+ authorized = false
45
+ if current_auth.has_permission?(:admin)
46
+ # auth_admin not allowed to deal with root users/keys/roles...
47
+
48
+ authorized = true
49
+
50
+ parts = request.path_info.split('/')
51
+
52
+ allowed = {
53
+ 'organizations' => true,
54
+ 'user_organizations' => true,
55
+ 'images' => true,
56
+ 'sentiment_sets' => true,
57
+ 'events' => true,
58
+ 'sessions' => true,
59
+ 'moderators' => true,
60
+ 'foci' => true,
61
+ 'categories' => true
62
+ }
63
+
64
+ if request.path_info == "/users" # post...
65
+ role_id = params[:role_id]
66
+ authorized = false if role_id and SQL::UserRole.is_root_role_by_role_id(db, role_id) # :auth_admin not allowed to add a root user_role.
67
+
68
+ elsif parts[1] == "users" # put or delete
69
+ user_id = parts[2].to_i
70
+ role_id = params[:role_id]
71
+ authorized = false if SQL::AuthLocalUser::UserRole.has_root_role_by_user_id(db, user_id) # :auth_admin not allowed to modify data related to a user with a role of root.
72
+ authorized = false if authorized and role_id and SQL::UserRole.is_root_role_by_role_id(db, role_id) # :auth_admin not allowed to add a root user_role.
73
+
74
+ elsif request.path_info == "/user_roles" # post...
75
+ user_id = params[:user_id]
76
+ role_id = params[:role_id]
77
+ authorized = false if SQL::AuthLocalUser::UserRole.has_root_role_by_user_id(db, user_id)
78
+ authorized = false if authorized and SQL::UserRole.is_root_role_by_role_id(db, role_id)
79
+
80
+ elsif parts[1] == "user_roles" # put or delete
81
+ user_id = parts[2].to_i
82
+ role_id = parts[3].to_i
83
+ authorized = false if SQL::AuthLocalUser::UserRole.has_root_role_by_user_id(db, user_id)
84
+ authorized = false if authorized and SQL::UserRole.is_root_role_by_role_id(db, role_id)
85
+
86
+ elsif allowed[parts[1]]
87
+ authorized = true
88
+
89
+ else
90
+ authorized = false
91
+ end
92
+ end
93
+ authorized
94
+ end
95
+ end
96
+ end
@@ -0,0 +1 @@
1
+ override.rb
@@ -0,0 +1,240 @@
1
+ # base_config.rb
2
+ require 'date'
3
+ require 'jungle_path/config'
4
+ require 'jungle_path/logging'
5
+
6
+ # create a config.rb to override any of the jungle... values as needed:
7
+ module Config
8
+ def self.init
9
+ # setting global config settings name 'jungle' on:
10
+ JunglePath::Config.set_global_on # configuration will be global: can access 'jungle...' anywhere.
11
+ environment
12
+ application
13
+ on_startup
14
+ db
15
+ smtp
16
+ sms
17
+ password_settings
18
+ roles
19
+ users
20
+ schema_filters
21
+ role_schema_filters
22
+ role_query_filters
23
+ restriction_query_filters
24
+ user_query_filters
25
+ permissions_and_restrictions
26
+ route_access
27
+ schema_filters
28
+ debug
29
+ config_override
30
+ jungle.lock = true
31
+ end
32
+
33
+ def self.environment
34
+ # create 'environment.rb' file to override this setting:
35
+ jungle.environment.name = "dev" # "dev", "stage", or "prod"
36
+ begin
37
+ require_relative 'environment'
38
+ puts "[application root]/config/environment.rb file was loaded."
39
+ puts "jungle.environment.name == '#{jungle.environment.name}'"
40
+ rescue LoadError => ex
41
+ puts "[application root]/config/environment.rb file was not found, defaulting to jungle.environment.name == '#{jungle_config.environment.name}'."
42
+ puts "to override, create file ./config/environment.rb with one line like this:"
43
+ puts "jungle.environment.name = 'stage' \# valid environments may be: 'dev', 'stage' or 'prod' or whatever you want to use :)"
44
+ end
45
+ end
46
+
47
+ def self.application
48
+ jungle.application.id = 5
49
+ jungle.application.root_dir = ::File.expand_path('..',::File.dirname(__FILE__))
50
+ jungle.application.public_dir = File.join(jungle.application.root_dir, 'web_apps', 'public')
51
+ jungle.application.name = 'jungle_path'
52
+ jungle.application.url = nil
53
+ jungle.application.logger = Logging.make_logger(jungle.application.root_dir, "#{jungle.application.name}_requests.log") # $stdout
54
+ puts "application root dir: #{jungle.application.root_dir}"
55
+ puts "application public dir: #{jungle.application.public_dir}"
56
+ end
57
+
58
+ def self.on_startup
59
+ jungle.on_startup.run_database_migrations = false # Servers usually handle this on their own with deployments. For devs, may want to override in override.rb.
60
+ end
61
+
62
+ def self.db
63
+ jungle.db.name = "jungle_path"
64
+ jungle.db.type = "postgres"
65
+ jungle.db.user_name = "jungle_path"
66
+ jungle.db.password = nil
67
+ jungle.db.host = "localhost"
68
+ jungle.db.extensions = [:pg_json]
69
+ jungle.db.port = nil # defaults to PostgreSQL default port of 5432.
70
+ jungle.db.options = {max_connections: 4}
71
+ end
72
+
73
+ def self.smtp # (email)
74
+ jungle.smtp.host = "localhost"
75
+ jungle.smtp.port = 25 #587 # 25
76
+ jungle.smtp.domain_of_sender = 'mydomain.com'
77
+ jungle.smtp.user_name = nil
78
+ jungle.smtp.password = nil
79
+ jungle.smtp.enable_tls = false
80
+ jungle.smtp.authentication = nil
81
+ jungle.smtp.from = nil # 'me@mydomain.com'
82
+ end
83
+
84
+ def self.sms # (texting)
85
+ jungle.sms.from_phone_number = nil
86
+ jungle.sms.account_sid = nil
87
+ jungle.sms.auth_token = nil
88
+ end
89
+
90
+ def self.password_settings
91
+ jungle.password_settings = {
92
+ length: {must_be_greater_than: 0, message: "Password length must be at least 1 characters."},
93
+ #length: {must_be_greater_than: 7, message: "Password length must be at least 8 characters."},
94
+ regular_expression_matches: [
95
+ ## {expression: /[[:alpha:]]/, message: "Password must have at least one alphabetical character."},
96
+ ## {expression: /[[:digit:]]/, message: "Password must have at least one numeric character."}
97
+ #{expression: /\D/, message: "Password must have at least one alphabetical character."},
98
+ #{expression: /\d/, message: "Password must have at least one numeric character."}
99
+ ]
100
+ }
101
+ end
102
+
103
+ def self.roles
104
+ jungle.roles = {
105
+ root: {
106
+ id: 0,
107
+ name: :root,
108
+ description: 'root can do anything',
109
+ permissions: [:root],
110
+ restrictions: []
111
+ },
112
+ admin: {
113
+ id: 1,
114
+ name: :admin,
115
+ description: 'admin and add, edit and delete users, but not root users.',
116
+ permissions: [:admin],
117
+ restrictions: []
118
+ },
119
+ user: {
120
+ id: 2,
121
+ name: :user,
122
+ description: 'basic system user -- has read only access.',
123
+ permissions: [:read],
124
+ restrictions: [:query_only, :me_related]
125
+ }
126
+ }
127
+ end
128
+
129
+ def self.users
130
+ jungle.users = {
131
+ root: {
132
+ id: 0,
133
+ name: 'root',
134
+ email: nil,
135
+ phone: nil,
136
+ active: true,
137
+ user_name: :root,
138
+ password: 'test',
139
+ roles: [:root]
140
+ },
141
+ admin: {
142
+ id: 1,
143
+ name: 'admin',
144
+ email: nil,
145
+ phone: nil,
146
+ active: true,
147
+ user_name: :admin,
148
+ password: 'test',
149
+ roles: [:admin]
150
+ },
151
+ user: {
152
+ id: 2,
153
+ name: 'user',
154
+ email: nil,
155
+ phone: nil,
156
+ active: true,
157
+ user_name: :user,
158
+ password: 'test',
159
+ roles: [:user]
160
+ }
161
+ }
162
+ end
163
+
164
+ def self.schema_filters
165
+ jungle.schema_filters = lambda {|identity|
166
+ filters = {
167
+ allow_all_tables: {allow: [table: /./]},
168
+ hide_nonpublic_tables: {allow: [{table: /./}], deny: [{table: /^utility_/}, {table: /^temp_/}]}
169
+ }
170
+ }
171
+ end
172
+
173
+ def self.role_schema_filters
174
+ jungle.role_schema_filters = lambda {|identity|
175
+ filters = {
176
+ root: :allow_all_tables,
177
+ admin: :allow_all_tables,
178
+ user: :hide_nonpublic_tables
179
+ }
180
+ }
181
+ end
182
+
183
+ def self.role_query_filters
184
+ jungle.role_query_filters = lambda {|identity|
185
+ filters = {
186
+ admin: [
187
+ {table_name: :table_i_want_to_filter, sub_select: "select id from table_i_want_to_filter where a = b"}
188
+ ]
189
+ # more...
190
+ }
191
+ }
192
+ end
193
+
194
+ def self.restriction_query_filters
195
+ jungle.restriction_query_filters = lambda {|identity|
196
+ filters = {
197
+ me_related:[
198
+ {table_name: :user, sub_select: "select id from user where id = #{identity.user.id}"}
199
+ ]
200
+ }
201
+ }
202
+ end
203
+
204
+ def self.user_query_filters
205
+ jungle.user_query_filters = lambda {|identity|
206
+ filters = {}
207
+ }
208
+ end
209
+
210
+ def self.route_access
211
+ jungle.route_access = {
212
+ public: {
213
+ get: {
214
+ routes: ['/', '/app', '/admin', '/query', '/query/doc'],
215
+ routes_start_with: ['/activate/', '/passwordresetcode/']
216
+ }
217
+ },
218
+ authenticated: {
219
+ get: {
220
+ routes: ['/query/schema_tree'],
221
+ routes_start_with: []
222
+ }
223
+ }
224
+ }
225
+ end
226
+
227
+ def self.debug
228
+ jungle.debug.show_params = false
229
+ end
230
+
231
+ def self.config_override
232
+ begin
233
+ require_relative 'override'
234
+ puts "[application root]/config/override.rb file was loaded."
235
+ rescue LoadError => ex
236
+ puts "warning!!! [application root]/config/override.rb file was not found, please create an override.rb file so that you can override default settings in 'config.rb'! override.rb should be in the same directory as config.rb."
237
+ end
238
+ end
239
+ end
240
+ Config.init
@@ -0,0 +1,3 @@
1
+ # Use override.rb for configuration of any sensitive data such as passwords.
2
+ # Do not push override.rb to git! :)
3
+ jungle.db.password = nil
@@ -0,0 +1,28 @@
1
+ #\ -w -p 8087
2
+ # config.ru
3
+ #require 'opal'
4
+ #require 'sinatra'
5
+ require 'time'
6
+ #require 'rack/mobile-detect'
7
+ #require_relative '../lib/rack_json_body_parser'
8
+ require_relative 'api/server_custom'
9
+ require_relative 'config/config' # contains all settings except sensitive data set to nil. Put sensitive data (passwords, etc.) in config/override.rb and .gitignore override.rb!
10
+ require_relative 'schemas/schema'
11
+ require_relative 'db/db'
12
+ require_relative 'ztools/migration'
13
+ puts "startup at #{Time.now}."
14
+
15
+ #use Rack::MobileDetect
16
+ #use Rack::CommonLogger, configatron.application.logger
17
+ #use Rack::PostBodyContentTypeParser, true
18
+
19
+ if jungle.application.on_startup.run_database_migrations
20
+ puts "running (main) database migrations..."
21
+ puts "set jungle.application.on_startup.run_database_migrations = false in your config.rb or override.rb to prevent running main database migrations at startup."
22
+ Migration.run Schema, ServerAPI::DB.instance
23
+ else
24
+ puts "skipping database (main) migrations."
25
+ puts "set jungle.application.on_startup.run_database_migrations = true in your config.rb or override.rb to run main database migrations at startup."
26
+ end
27
+
28
+ map('/') {run Server::API}
File without changes
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ #rackup config.ru
3
+ echo "no longer running with rackup, starting with thin directly (and passing in config.ru...)"
4
+ thin --threaded start -R config.ru -p 8087 -t 300
@@ -0,0 +1,21 @@
1
+ # can just require this:
2
+ #require 'jungle_path/schema'
3
+
4
+ # or these:
5
+ require 'jungle_path/schema/version'
6
+ require 'jungle_path/schema/base'
7
+ require 'jungle_path/schema/db'
8
+ require 'jungle_path/schema/auth'
9
+
10
+ # application tables examples:
11
+
12
+ class Answer < Schema::Base
13
+ self.description = ""
14
+ define(
15
+ [:id, :primary_key],
16
+ [:question_id, :foreign_key, :question],
17
+ [:description, :string],
18
+ [:is_correct, :boolean],
19
+ [:audit_user]
20
+ )
21
+ end