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.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/jungle_path.gemspec +4 -1
- data/lib/jungle_path/api/helpers/auth.rb +6 -10
- data/lib/jungle_path/api/helpers/defaults.rb +7 -6
- data/lib/jungle_path/api/helpers/logging.rb +7 -1
- data/lib/jungle_path/api/helpers.rb +2 -2
- data/lib/jungle_path/api/template.erb +2 -2
- data/lib/jungle_path/app/api/{server_base.rb → base.rb} +24 -23
- data/lib/jungle_path/app/api/{server_custom.rb → custom.rb} +15 -16
- data/lib/jungle_path/app/api/{server_gen.rb → generated.rb} +2 -2
- data/lib/jungle_path/app/auth/authorization.rb +15 -14
- data/lib/jungle_path/app/config/config.rb +8 -9
- data/lib/jungle_path/app/config/override.rb +2 -1
- data/lib/jungle_path/app/config.ru +6 -5
- data/lib/jungle_path/app/controllers/controller.rb +197 -0
- data/lib/jungle_path/app/controllers/generated.rb +13 -0
- data/lib/jungle_path/app/db/db.rb +13 -0
- data/lib/jungle_path/app/schemas/schema.rb +81 -0
- data/lib/jungle_path/app/services/email.rb +138 -0
- data/lib/jungle_path/app/services/sms.rb +17 -0
- data/lib/jungle_path/app/web_apps/public/index.html +10 -0
- data/lib/jungle_path/app/ztools/db/migrations/000_root.rb +1 -0
- data/lib/jungle_path/app/ztools/zbootstrapdata.rb +57 -0
- data/lib/jungle_path/app/ztools/zcreatedb.rb +19 -0
- data/lib/jungle_path/app/ztools/zgen.rb +9 -0
- data/lib/jungle_path/app/ztools/zgen_node_tree.rb +14 -0
- data/lib/jungle_path/app/ztools/zmigrate.rb +7 -0
- data/lib/jungle_path/app/ztools/zport_data.rb +292 -0
- data/lib/jungle_path/authentication/auth_provider/default.rb +36 -29
- data/lib/jungle_path/authentication/data_provider/default.rb +55 -109
- data/lib/jungle_path/authentication/data_provider/test.rb +149 -0
- data/lib/jungle_path/authentication/data_provider.rb +1 -0
- data/lib/jungle_path/authentication/identity.rb +4 -4
- data/lib/jungle_path/authentication/password_hash.rb +8 -8
- data/lib/jungle_path/authorization/filter.rb +0 -3
- data/lib/jungle_path/config.rb +1 -1
- data/lib/jungle_path/controller/template.erb +2 -2
- data/lib/jungle_path/db_access.rb +6 -0
- data/lib/jungle_path/file/file.rb +21 -0
- data/lib/jungle_path/file.rb +3 -0
- data/lib/jungle_path/gen/api.rb +3 -3
- data/lib/jungle_path/gen/controllers.rb +20 -0
- data/lib/jungle_path/gen/db.rb +77 -0
- data/lib/jungle_path/gen/schema.rb +2 -2
- data/lib/jungle_path/gen.rb +1 -1
- data/lib/jungle_path/migration/migration.rb +31 -0
- data/lib/jungle_path/migration.rb +3 -0
- data/lib/jungle_path/rack/json_body_parser.rb +2 -2
- data/lib/jungle_path/schema/auth.rb +32 -40
- data/lib/jungle_path/sql/key.rb +0 -22
- data/lib/jungle_path/sql/query_filter.rb +2 -2
- data/lib/jungle_path/sql/role.rb +2 -2
- data/lib/jungle_path/sql/user.rb +21 -2
- data/lib/jungle_path/time/time.rb +9 -0
- data/lib/jungle_path/time.rb +3 -0
- data/lib/jungle_path/version.rb +3 -0
- data/lib/jungle_path.rb +4 -0
- metadata +28 -6
- data/lib/jungle_path/gen/controller.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa568e6121f73ebcf9e37a3fa48f87b73b2c2d26
|
4
|
+
data.tar.gz: b4b800b43f212c708ffd76681c342cddca969d76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3968c3ba0864c05c8f2e2b05148d93d110f4c570ffc2d2d9df1174697be3d00b5b33cc1b328e669758d7920a7de5f10cfd81b5bbd4f744e5b78ab425ede06a6
|
7
|
+
data.tar.gz: 99ec0c3dbca92db4336fdf47cb68af87f20368a618f9fe37dc7d8a681bb12a014af06646e4aea3f5a04090af5a0e18c4b7f494003c38a1849e8740c84270c170
|
data/Gemfile
CHANGED
data/jungle_path.gemspec
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
puts "ARGV: #{ARGV}"
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'jungle_path/version'
|
4
7
|
|
5
8
|
Gem::Specification.new do |spec|
|
6
9
|
spec.name = 'jungle_path'
|
7
|
-
spec.version =
|
10
|
+
spec.version = JunglePath::VERSION
|
8
11
|
spec.authors = ['Michael VanZant']
|
9
12
|
spec.email = ['mxvanzant@yahoo.com']
|
10
13
|
spec.summary = 'Full-stack web application framework for creating API services.'
|
@@ -3,11 +3,11 @@ module JunglePath
|
|
3
3
|
module API
|
4
4
|
module Helpers
|
5
5
|
module Auth
|
6
|
-
def authenticate auth_provider
|
6
|
+
def authenticate auth_provider, data_provider, no_cache=false
|
7
7
|
puts "Auth.authenticate"
|
8
|
-
data_provider = JunglePath::Authentication::DataProvider::Default.new unless data_provider
|
9
|
-
auth_provider = JunglePath::Authentication::AuthProvider::Default.new unless auth_provider
|
10
|
-
@current_identity = auth_provider.authenticate(data_provider, no_cache)
|
8
|
+
#data_provider = JunglePath::Authentication::DataProvider::Default.new unless data_provider
|
9
|
+
#auth_provider = JunglePath::Authentication::AuthProvider::Default.new unless auth_provider
|
10
|
+
@current_identity = auth_provider.authenticate(request, data_provider, no_cache)
|
11
11
|
halt 401 unless @current_identity and @current_identity.valid?
|
12
12
|
request.body.rewind
|
13
13
|
end
|
@@ -24,16 +24,12 @@ module JunglePath
|
|
24
24
|
@current_identity and @current_identity.key
|
25
25
|
end
|
26
26
|
|
27
|
-
def current_roles
|
28
|
-
@current_identity and @current_identity.roles
|
29
|
-
end
|
30
|
-
|
31
27
|
def current_role
|
32
|
-
@current_identity and @current_identity.
|
28
|
+
@current_identity and @current_identity.role
|
33
29
|
end
|
34
30
|
|
35
31
|
def current_auth
|
36
|
-
@current_identity and @current_identity.
|
32
|
+
@current_identity and @current_identity.authorization_filter
|
37
33
|
end
|
38
34
|
|
39
35
|
def current_query_filters
|
@@ -10,9 +10,9 @@ module JunglePath
|
|
10
10
|
module Defaults
|
11
11
|
# default mixin that may be included in your Sinatra application class.
|
12
12
|
|
13
|
-
def set_default_rack_middleware issue_challenge=true
|
14
|
-
use Rack::MobileDetect
|
15
|
-
use Rack::CommonLogger,
|
13
|
+
def set_default_rack_middleware logger, issue_challenge=true
|
14
|
+
use ::Rack::MobileDetect
|
15
|
+
use ::Rack::CommonLogger, logger
|
16
16
|
use JunglePath::Rack::JsonBodyParser, true
|
17
17
|
# This is rack middleware that adds 'REMOTE_USER' and 'REMOTE_PASSWORD'
|
18
18
|
# keys with their associated basic auth values to request.env (if present in the HTTP header).
|
@@ -23,7 +23,7 @@ module JunglePath
|
|
23
23
|
use JunglePath::Rack::BasicCredentials::Basic, "Basic Authentication Required.", issue_challenge
|
24
24
|
end
|
25
25
|
|
26
|
-
def set_default_error_handling
|
26
|
+
def set_default_error_handling logger
|
27
27
|
# These must be disabled to allow error methods to fire.
|
28
28
|
disable :raise_errors
|
29
29
|
disable :show_exceptions
|
@@ -59,13 +59,14 @@ module JunglePath
|
|
59
59
|
helpers JunglePath::API::Helpers::QueryFilters
|
60
60
|
end
|
61
61
|
|
62
|
-
def set_default_authentication_check
|
62
|
+
def set_default_authentication_check debug_show_params=false
|
63
63
|
before do
|
64
64
|
puts ""
|
65
65
|
puts "::::[request_start: #{Time.now.utc}]::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
|
66
66
|
puts "::::[#{request.env['REMOTE_USER']}: #{request.request_method} #{request.url}"
|
67
67
|
puts "(api_helpsers - before do - default authentication check)"
|
68
|
-
puts "[params] #{params.to_h}" if configatron.debug.show_params
|
68
|
+
#puts "[params] #{params.to_h}" if configatron.debug.show_params
|
69
|
+
puts "[params] #{params.to_h}" if debug_show_params
|
69
70
|
puts "authenticate..."
|
70
71
|
# These three request paths return user info, so force no_cache = true so that stale user data is not returned!
|
71
72
|
no_cache = request.path_info == '/authenticate' or request.path_info == '/current/user' or request.path_info == '/current/user/auth'
|
@@ -10,9 +10,15 @@ module JunglePath
|
|
10
10
|
puts info
|
11
11
|
end
|
12
12
|
|
13
|
+
#def set_logger logger
|
14
|
+
# @logger = logger
|
15
|
+
#end
|
16
|
+
|
13
17
|
def logger
|
14
18
|
#API.logger
|
15
|
-
Logger.new(configatron.application.logger)
|
19
|
+
#Logger.new(configatron.application.logger)
|
20
|
+
#@logger
|
21
|
+
jungle.application.logger
|
16
22
|
end
|
17
23
|
|
18
24
|
def get_log_file_list
|
@@ -4,8 +4,8 @@ module JunglePath
|
|
4
4
|
require 'jungle_path/api/helpers/logging'
|
5
5
|
require 'jungle_path/api/helpers/rescues'
|
6
6
|
require 'jungle_path/api/helpers/auth'
|
7
|
-
require 'jungle_path/api/helpers/auth_local_user'
|
8
|
-
require 'jungle_path/api/helpers/auth_old'
|
7
|
+
#require 'jungle_path/api/helpers/auth_local_user'
|
8
|
+
#require 'jungle_path/api/helpers/auth_old'
|
9
9
|
require 'jungle_path/api/helpers/result'
|
10
10
|
require 'jungle_path/api/helpers/query_filters'
|
11
11
|
require 'jungle_path/api/helpers/standard_apis'
|
@@ -3,11 +3,11 @@
|
|
3
3
|
require 'sinatra/base'
|
4
4
|
require_relative '../db/db'
|
5
5
|
require_relative '../schemas/schema'
|
6
|
-
require_relative '
|
6
|
+
require_relative 'base'
|
7
7
|
require_relative '../controllers/controller'
|
8
8
|
|
9
9
|
module <%= name_space %>
|
10
|
-
class
|
10
|
+
class <%= class_name %> < <%= name_space %>::<%= base_class_name %>
|
11
11
|
<% for table in tables %>
|
12
12
|
begin # <%= table.plural_table_name %>
|
13
13
|
get '/<%= table.plural_table_name %>' do
|
@@ -1,27 +1,27 @@
|
|
1
|
+
require 'time'
|
1
2
|
require 'rack'
|
2
3
|
require 'sinatra/base'
|
3
4
|
require 'jungle_path/json'
|
4
5
|
require 'jungle_path/api/helpers'
|
5
6
|
require 'jungle_path/authentication/auth_provider'
|
6
7
|
require 'jungle_path/authentication/data_provider'
|
8
|
+
require 'jungle_path/authorization/filter'
|
9
|
+
require 'jungle_path/authorization/paths'
|
7
10
|
require 'jungle_path/query/filter'
|
11
|
+
require 'jungle_path/rack/basic_credentials'
|
12
|
+
require 'jungle_path/sql'
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#require_relative '../../lib/api_helpers'
|
14
|
-
#require_relative '../../lib/authorization'
|
15
|
-
#require_relative '../db/db'
|
16
|
-
#require_relative '../schemas/schema'
|
17
|
-
#require_relative '../auth/authorization'
|
14
|
+
require_relative '../config/config' #for config settings use jungle.setting...
|
15
|
+
require_relative '../db/db'
|
16
|
+
require_relative '../schemas/schema'
|
17
|
+
require_relative '../auth/authorization'
|
18
18
|
|
19
19
|
module Server
|
20
20
|
#class BaseAPI < Sinatra::Application
|
21
|
-
class
|
21
|
+
class Base < Sinatra::Base
|
22
22
|
configure do
|
23
|
-
set :public_folder,
|
24
|
-
set :root,
|
23
|
+
set :public_folder, jungle.application.public_dir
|
24
|
+
set :root, jungle.application.root_dir
|
25
25
|
set :dump_errors, true
|
26
26
|
set :sessions, false
|
27
27
|
set :logging, true
|
@@ -38,22 +38,23 @@ module Server
|
|
38
38
|
extend JunglePath::API::Helpers::StandardAPIs
|
39
39
|
|
40
40
|
# Your own:
|
41
|
-
|
41
|
+
extend Auth::Authorization
|
42
42
|
|
43
43
|
def self.inherited(subclass)
|
44
44
|
super
|
45
45
|
subclass.instance_eval do
|
46
|
-
set_default_rack_middleware false
|
47
|
-
set_default_error_handling
|
46
|
+
set_default_rack_middleware jungle.application.logger, false
|
47
|
+
set_default_error_handling jungle.application.logger
|
48
48
|
|
49
49
|
helpers JunglePath::API::Helpers::DataCache
|
50
50
|
helpers JunglePath::API::Helpers::Logging
|
51
|
+
#set_logger jungle.application.logger
|
51
52
|
helpers JunglePath::API::Helpers::Result
|
52
53
|
helpers JunglePath::API::Helpers::Auth
|
53
54
|
helpers Server::Base::Database
|
54
55
|
|
55
56
|
# Your own:
|
56
|
-
|
57
|
+
set_authorization jungle.route_access
|
57
58
|
|
58
59
|
set_standard_api_get_log_file_list
|
59
60
|
set_standard_api_get_log_file
|
@@ -70,26 +71,26 @@ module Server
|
|
70
71
|
puts "[request_start: #{Time.now.utc}]::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
|
71
72
|
puts "[#{request.env['REMOTE_USER']}: #{request.request_method} #{request.url}"
|
72
73
|
puts "(base_api - before do - authentication check)"
|
73
|
-
puts "[params] #{params.to_h}" if
|
74
|
-
if
|
74
|
+
puts "[params] #{params.to_h}" if jungle.debug.show_params
|
75
|
+
if JunglePath::Authorization::Paths.is_open_path?(request, jungle.route_access)
|
75
76
|
puts "is open path: #{request.path_info}"
|
76
77
|
else
|
77
78
|
puts "is secured path: #{request.path_info}"
|
78
79
|
# These three request paths return user info, so force no_cache = true so that stale user data is not returned!
|
79
80
|
no_cache = (request.path_info == '/authenticate' or request.path_info == '/current/user' or request.path_info == '/current/user/auth')
|
80
81
|
puts "authenticate no_cache: #{no_cache}."
|
82
|
+
#data_provider = JunglePath::Authentication::DataProvider::Test.new(Schema::Base.models)
|
83
|
+
#def initialize db, user_model, models, roles, schema_filters, role_schema_filters, role_query_filters, restriction_query_filters, user_query_filters
|
84
|
+
data_provider = JunglePath::Authentication::DataProvider::Default.new(self, cache, db, ::Schema::User, ::Schema::Base.models, jungle.roles, jungle.schema_filters, jungle.role_schema_filters, jungle.role_query_filters, jungle.restriction_query_filters, jungle.user_query_filters)
|
81
85
|
auth_provider = JunglePath::Authentication::AuthProvider::Default.new
|
82
|
-
data_provider
|
83
|
-
JunglePath::API::Helpers::Auth.authenticate auth_provider, data_provider, no_cache
|
86
|
+
authenticate auth_provider, data_provider, no_cache
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
87
90
|
module Database
|
88
91
|
def db
|
89
|
-
|
92
|
+
Server::DB.instance
|
90
93
|
end
|
91
94
|
end
|
92
|
-
|
93
|
-
end
|
94
95
|
end
|
95
96
|
end
|
@@ -3,21 +3,17 @@ require 'time'
|
|
3
3
|
require 'date'
|
4
4
|
require 'pp'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require_relative '../../lib/gen_node_tree'
|
11
|
-
#require_relative 'pubnub_rs'
|
6
|
+
require 'jungle_path/query'
|
7
|
+
require 'jungle_path/controller'
|
8
|
+
require 'jungle_path/cache'
|
9
|
+
|
12
10
|
require_relative '../db/db'
|
13
11
|
require_relative '../schemas/schema'
|
14
|
-
require_relative '
|
15
|
-
require_relative '../utils/utils'
|
12
|
+
require_relative 'base'
|
16
13
|
require_relative '../controllers/controller'
|
17
|
-
require_relative '../services/email'
|
18
14
|
|
19
15
|
module Server
|
20
|
-
class API < Server::
|
16
|
+
class API < Server::Base
|
21
17
|
get '/' do
|
22
18
|
# default page:
|
23
19
|
#if request.env['X_MOBILE_DEVICE']
|
@@ -77,7 +73,7 @@ module Server
|
|
77
73
|
|
78
74
|
get '/cachetest/:key' do
|
79
75
|
key = params[:key]
|
80
|
-
value =
|
76
|
+
value = JunglePath::Cache[key]
|
81
77
|
handle_result({key: "#{key}", value: "#{value}"})
|
82
78
|
end
|
83
79
|
|
@@ -93,16 +89,19 @@ module Server
|
|
93
89
|
end
|
94
90
|
|
95
91
|
get '/current/user' do
|
96
|
-
handle_result({user: current_user, key: current_key,
|
92
|
+
handle_result({user: current_user, key: current_key, role: current_role, auth: {permissions: current_auth.permissions, restrictions: current_auth.restrictions, schema_filter: current_auth.schema_filter}} )
|
97
93
|
end
|
98
94
|
|
99
95
|
get '/current/user/auth' do
|
100
96
|
message = {
|
101
97
|
user_id: current_user.id,
|
102
98
|
user_name: current_user.user_name,
|
103
|
-
key_id: current_key.id,
|
104
|
-
key_name: current_key.name,
|
105
|
-
key_value: current_key.key,
|
99
|
+
#key_id: current_key.id,
|
100
|
+
#key_name: current_key.name,
|
101
|
+
#key_value: current_key.key,
|
102
|
+
key_id: current_user.id,
|
103
|
+
key_name: current_user.user_name,
|
104
|
+
key_value: current_user.user_name,
|
106
105
|
roles: current_auth.roles,
|
107
106
|
permissions: current_auth.permissions,
|
108
107
|
restrictions: current_auth.restrictions,
|
@@ -118,4 +117,4 @@ module Server
|
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
|
-
require_relative '
|
120
|
+
require_relative 'generated'
|
@@ -2,10 +2,10 @@
|
|
2
2
|
require 'sinatra/base'
|
3
3
|
require_relative '../db/db'
|
4
4
|
require_relative '../schemas/schema'
|
5
|
-
require_relative '
|
5
|
+
require_relative 'base'
|
6
6
|
require_relative '../controllers/controller'
|
7
7
|
|
8
8
|
module Server
|
9
|
-
class API < Server::
|
9
|
+
class API < Server::Base
|
10
10
|
end
|
11
11
|
end
|
@@ -1,17 +1,18 @@
|
|
1
1
|
require 'jungle_path/authorization/paths'
|
2
|
-
require '
|
2
|
+
require 'jungle_path/sql'
|
3
|
+
require_relative '../config/config'
|
3
4
|
|
4
|
-
module
|
5
|
+
module Auth
|
5
6
|
module Authorization
|
6
|
-
def set_authorization
|
7
|
+
def set_authorization route_access
|
7
8
|
before do
|
8
9
|
puts "verb: #{request.request_method}."
|
9
10
|
puts "path: #{request.path_info}."
|
10
11
|
|
11
12
|
authorized = false
|
12
13
|
|
13
|
-
authorized = JunglePath::Authorization::
|
14
|
-
authorized = JunglePath::Authorization::
|
14
|
+
authorized = JunglePath::Authorization::Paths.is_open_path?(request, route_access)
|
15
|
+
authorized = JunglePath::Authorization::Paths.is_authenticated_path?(request, route_access) unless authorized
|
15
16
|
|
16
17
|
unless authorized
|
17
18
|
if request.get?
|
@@ -24,11 +25,11 @@ module ServerAPI
|
|
24
25
|
authorized = true if current_auth.has_permission?(:write) unless authorized
|
25
26
|
authorized = true if request.path_info == "/query" and current_auth.has_permission?(:read) unless authorized
|
26
27
|
authorized = true if request.path_info == "/users/#{current_user.id}" unless authorized
|
27
|
-
authorized = true if
|
28
|
+
authorized = true if Auth::Authorization.authorized_admin?(request, params, current_auth, db) unless authorized
|
28
29
|
authorized = false if current_auth.has_restriction?(:read)
|
29
30
|
end
|
30
31
|
|
31
|
-
authorized = false if current_auth.has_restriction?(:query_only) unless JunglePath::Authorization::
|
32
|
+
authorized = false if current_auth.has_restriction?(:query_only) unless JunglePath::Authorization::Paths.is_query_only_path? request, current_auth
|
32
33
|
end
|
33
34
|
|
34
35
|
unless authorized
|
@@ -63,25 +64,25 @@ module ServerAPI
|
|
63
64
|
|
64
65
|
if request.path_info == "/users" # post...
|
65
66
|
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
|
+
authorized = false if role_id and JunglePath::SQL::UserRole.is_root_role_by_role_id(db, role_id) # :auth_admin not allowed to add a root user_role.
|
67
68
|
|
68
69
|
elsif parts[1] == "users" # put or delete
|
69
70
|
user_id = parts[2].to_i
|
70
71
|
role_id = params[:role_id]
|
71
|
-
authorized = false if SQL::
|
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.
|
72
|
+
authorized = false if JunglePath::SQL::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.
|
73
|
+
authorized = false if authorized and role_id and JunglePath::SQL::UserRole.is_root_role_by_role_id(db, role_id) # :auth_admin not allowed to add a root user_role.
|
73
74
|
|
74
75
|
elsif request.path_info == "/user_roles" # post...
|
75
76
|
user_id = params[:user_id]
|
76
77
|
role_id = params[:role_id]
|
77
|
-
authorized = false if SQL::
|
78
|
-
authorized = false if authorized and SQL::UserRole.is_root_role_by_role_id(db, role_id)
|
78
|
+
authorized = false if JunglePath::SQL::UserRole.has_root_role_by_user_id(db, user_id)
|
79
|
+
authorized = false if authorized and JunglePath::SQL::UserRole.is_root_role_by_role_id(db, role_id)
|
79
80
|
|
80
81
|
elsif parts[1] == "user_roles" # put or delete
|
81
82
|
user_id = parts[2].to_i
|
82
83
|
role_id = parts[3].to_i
|
83
|
-
authorized = false if SQL::
|
84
|
-
authorized = false if authorized and SQL::UserRole.is_root_role_by_role_id(db, role_id)
|
84
|
+
authorized = false if JunglePath::SQL::UserRole.has_root_role_by_user_id(db, user_id)
|
85
|
+
authorized = false if authorized and JunglePath::SQL::UserRole.is_root_role_by_role_id(db, role_id)
|
85
86
|
|
86
87
|
elsif allowed[parts[1]]
|
87
88
|
authorized = true
|
@@ -22,9 +22,8 @@ module Config
|
|
22
22
|
role_query_filters
|
23
23
|
restriction_query_filters
|
24
24
|
user_query_filters
|
25
|
-
permissions_and_restrictions
|
25
|
+
#permissions_and_restrictions
|
26
26
|
route_access
|
27
|
-
schema_filters
|
28
27
|
debug
|
29
28
|
config_override
|
30
29
|
jungle.lock = true
|
@@ -38,7 +37,7 @@ module Config
|
|
38
37
|
puts "[application root]/config/environment.rb file was loaded."
|
39
38
|
puts "jungle.environment.name == '#{jungle.environment.name}'"
|
40
39
|
rescue LoadError => ex
|
41
|
-
puts "[application root]/config/environment.rb file was not found, defaulting to jungle.environment.name == '#{
|
40
|
+
puts "[application root]/config/environment.rb file was not found, defaulting to jungle.environment.name == '#{jungle.environment.name}'."
|
42
41
|
puts "to override, create file ./config/environment.rb with one line like this:"
|
43
42
|
puts "jungle.environment.name = 'stage' \# valid environments may be: 'dev', 'stage' or 'prod' or whatever you want to use :)"
|
44
43
|
end
|
@@ -62,11 +61,11 @@ module Config
|
|
62
61
|
def self.db
|
63
62
|
jungle.db.name = "jungle_path"
|
64
63
|
jungle.db.type = "postgres"
|
65
|
-
jungle.db.user_name = "
|
64
|
+
jungle.db.user_name = "junglepath"
|
66
65
|
jungle.db.password = nil
|
67
66
|
jungle.db.host = "localhost"
|
68
67
|
jungle.db.extensions = [:pg_json]
|
69
|
-
jungle.db.port = nil # defaults to PostgreSQL default port of 5432.
|
68
|
+
jungle.db.port = nil # defaults to PostgreSQL default port of 5432 if nil.
|
70
69
|
jungle.db.options = {max_connections: 4}
|
71
70
|
end
|
72
71
|
|
@@ -136,7 +135,7 @@ module Config
|
|
136
135
|
active: true,
|
137
136
|
user_name: :root,
|
138
137
|
password: 'test',
|
139
|
-
|
138
|
+
role: :root
|
140
139
|
},
|
141
140
|
admin: {
|
142
141
|
id: 1,
|
@@ -146,7 +145,7 @@ module Config
|
|
146
145
|
active: true,
|
147
146
|
user_name: :admin,
|
148
147
|
password: 'test',
|
149
|
-
|
148
|
+
role: :admin
|
150
149
|
},
|
151
150
|
user: {
|
152
151
|
id: 2,
|
@@ -156,7 +155,7 @@ module Config
|
|
156
155
|
active: true,
|
157
156
|
user_name: :user,
|
158
157
|
password: 'test',
|
159
|
-
roles:
|
158
|
+
roles: :user
|
160
159
|
}
|
161
160
|
}
|
162
161
|
end
|
@@ -184,7 +183,7 @@ module Config
|
|
184
183
|
jungle.role_query_filters = lambda {|identity|
|
185
184
|
filters = {
|
186
185
|
admin: [
|
187
|
-
{table_name: :table_i_want_to_filter, sub_select: "select id from table_i_want_to_filter where a = b"}
|
186
|
+
{table_name: :table_i_want_to_filter, sub_select: "select id from table_i_want_to_filter where a = b", use_not_in: false}
|
188
187
|
]
|
189
188
|
# more...
|
190
189
|
}
|
@@ -4,25 +4,26 @@
|
|
4
4
|
#require 'sinatra'
|
5
5
|
require 'time'
|
6
6
|
#require 'rack/mobile-detect'
|
7
|
+
require 'jungle_path/migration'
|
7
8
|
#require_relative '../lib/rack_json_body_parser'
|
8
|
-
require_relative 'api/
|
9
|
+
require_relative 'api/custom'
|
9
10
|
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
11
|
require_relative 'schemas/schema'
|
11
12
|
require_relative 'db/db'
|
12
|
-
|
13
|
+
|
13
14
|
puts "startup at #{Time.now}."
|
14
15
|
|
15
16
|
#use Rack::MobileDetect
|
16
17
|
#use Rack::CommonLogger, configatron.application.logger
|
17
18
|
#use Rack::PostBodyContentTypeParser, true
|
18
19
|
|
19
|
-
if jungle.
|
20
|
+
if jungle.on_startup.run_database_migrations
|
20
21
|
puts "running (main) database migrations..."
|
21
|
-
puts "set jungle.
|
22
|
+
puts "set jungle.on_startup.run_database_migrations = false in your config.rb or override.rb to prevent running main database migrations at startup."
|
22
23
|
Migration.run Schema, ServerAPI::DB.instance
|
23
24
|
else
|
24
25
|
puts "skipping database (main) migrations."
|
25
|
-
puts "set jungle.
|
26
|
+
puts "set jungle.on_startup.run_database_migrations = true in your config.rb or override.rb to run main database migrations at startup."
|
26
27
|
end
|
27
28
|
|
28
29
|
map('/') {run Server::API}
|