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]
33 [Server::Application.config.uuid_prefix,
35 '000000000000000'].join('-')
39 [Server::Application.config.uuid_prefix,
41 '000000000000000'].join('-')
44 def anonymous_group_uuid
45 [Server::Application.config.uuid_prefix,
47 'anonymouspublic'].join('-')
50 def anonymous_user_uuid
51 [Server::Application.config.uuid_prefix,
53 'anonymouspublic'].join('-')
57 $system_user = check_cache $system_user do
58 real_current_user = Thread.current[:user]
60 Thread.current[:user] = User.new(is_admin: true,
62 uuid: system_user_uuid)
63 User.where(uuid: system_user_uuid).
64 first_or_create!(is_active: true,
70 Thread.current[:user] = real_current_user
76 $system_group = check_cache $system_group do
78 ActiveRecord::Base.transaction do
79 Group.where(uuid: system_group_uuid).
80 first_or_create!(name: "System group",
81 description: "System group") do |g|
83 User.all.collect(&:uuid).each do |user_uuid|
84 Link.create!(link_class: 'permission',
86 tail_kind: 'arvados#group',
87 tail_uuid: system_group_uuid,
88 head_kind: 'arvados#user',
97 def all_users_group_uuid
98 [Server::Application.config.uuid_prefix,
100 'fffffffffffffff'].join('-')
104 $all_users_group = check_cache $all_users_group do
105 act_as_system_user do
106 ActiveRecord::Base.transaction do
107 Group.where(uuid: all_users_group_uuid).
108 first_or_create!(name: "All users",
109 description: "All users",
116 def act_as_system_user
118 act_as_user system_user do
122 Thread.current[:user] = system_user
127 user_was = Thread.current[:user]
128 Thread.current[:user] = user
132 Thread.current[:user] = user_was
137 $anonymous_group = check_cache $anonymous_group do
138 act_as_system_user do
139 ActiveRecord::Base.transaction do
140 Group.where(uuid: anonymous_group_uuid).
141 first_or_create!(group_class: "role",
142 name: "Anonymous users",
143 description: "Anonymous users")
150 $anonymous_user = check_cache $anonymous_user do
151 act_as_system_user do
152 User.where(uuid: anonymous_user_uuid).
153 first_or_create!(is_active: false,
156 first_name: 'Anonymous',
157 last_name: '') do |u|
159 Link.where(tail_uuid: anonymous_user_uuid,
160 head_uuid: anonymous_group.uuid,
161 link_class: 'permission',
169 def empty_collection_uuid
170 'd41d8cd98f00b204e9800998ecf8427e+0'
174 $empty_collection = check_cache $empty_collection do
175 act_as_system_user do
176 ActiveRecord::Base.transaction do
178 where(portable_data_hash: empty_collection_uuid).
179 first_or_create!(manifest_text: '', owner_uuid: anonymous_group.uuid)
187 # If the given value is nil, or the cache has been cleared since it
188 # was set, yield. Otherwise, return the given value.
189 def check_cache value
190 Rails.cache.fetch "CurrentApiClient.$globals" do
194 return value unless value.nil?