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('-')
58 real_current_user = Thread.current[:user]
59 Thread.current[:user] = User.new(is_admin: true,
61 uuid: system_user_uuid)
62 $system_user = User.where('uuid=?', system_user_uuid).first
64 $system_user = User.new(uuid: system_user_uuid,
73 Thread.current[:user] = real_current_user
81 ActiveRecord::Base.transaction do
82 $system_group = Group.
83 where(uuid: system_group_uuid).first_or_create do |g|
84 g.update_attributes(name: "System group",
85 description: "System group")
86 User.all.collect(&:uuid).each do |user_uuid|
87 Link.create(link_class: 'permission',
89 tail_kind: 'arvados#group',
90 tail_uuid: system_group_uuid,
91 head_kind: 'arvados#user',
101 def act_as_system_user
103 user_was = Thread.current[:user]
104 Thread.current[:user] = system_user
108 Thread.current[:user] = user_was
111 Thread.current[:user] = system_user
116 if not $anonymous_group
117 act_as_system_user do
118 ActiveRecord::Base.transaction do
119 $anonymous_group = Group.
120 where(uuid: anonymous_group_uuid).first_or_create do |g|
121 g.update_attributes(name: "Anonymous group",
122 description: "Anonymous group")
131 if not $anonymous_user
132 act_as_system_user do
133 $anonymous_user = User.where('uuid=?', anonymous_user_uuid).first
135 $anonymous_user = User.new(uuid: anonymous_user_uuid,
138 email: 'anonymouspublic',
139 first_name: 'anonymouspublic',
140 last_name: 'anonymouspublic')
141 $anonymous_user.save!
142 $anonymous_user.reload
145 group_perms = Link.where(tail_uuid: anonymous_user_uuid,
146 head_uuid: anonymous_group_uuid,
147 link_class: 'permission',
151 group_perm = Link.create!(tail_uuid: anonymous_user_uuid,
152 head_uuid: anonymous_group_uuid,
153 link_class: 'permission',
161 def empty_collection_uuid
162 'd41d8cd98f00b204e9800998ecf8427e+0'
166 if not $empty_collection
167 act_as_system_user do
168 ActiveRecord::Base.transaction do
169 $empty_collection = Collection.
170 where(uuid: empty_collection_uuid).
171 first_or_create!(manifest_text: '')
172 Link.where(tail_uuid: anonymous_group_uuid,
173 head_uuid: empty_collection_uuid,
174 link_class: 'permission',
175 name: 'can_read').first_or_create!