1 module CurrentApiClient
7 Thread.current[:api_client]
10 def current_api_client_authorization
11 Thread.current[:api_client_authorization]
15 Thread.current[:api_url_base]
18 def current_default_owner
19 # owner_uuid for newly created objects
20 ((current_api_client_authorization &&
21 current_api_client_authorization.default_owner_uuid) ||
22 (current_user && current_user.default_owner_uuid) ||
23 (current_user && current_user.uuid) ||
27 # Where is the client connecting from?
28 def current_api_client_ip_address
29 Thread.current[:api_client_ip_address]
32 # Does the current API client authorization include any of ok_scopes?
33 def current_api_client_auth_has_scope(ok_scopes)
34 auth_scopes = current_api_client_authorization.andand.scopes || []
35 unless auth_scopes.index('all') or (auth_scopes & ok_scopes).any?
36 logger.warn "Insufficient auth scope: need #{ok_scopes}, #{current_api_client_authorization.inspect} has #{auth_scopes}"
43 [Server::Application.config.uuid_prefix,
45 '000000000000000'].join('-')
50 real_current_user = Thread.current[:user]
51 Thread.current[:user] = User.new(is_admin: true, is_active: true)
52 $system_user = User.where('uuid=?', system_user_uuid).first
54 $system_user = User.new(uuid: system_user_uuid,
63 Thread.current[:user] = real_current_user
68 def act_as_system_user
70 user_was = Thread.current[:user]
71 Thread.current[:user] = system_user
73 Thread.current[:user] = user_was
76 Thread.current[:user] = system_user