1 class UsersController < ApplicationController
2 skip_around_filter :require_thread_api_token, only: :welcome
3 skip_before_filter :check_user_agreements, only: [:welcome, :inactive]
4 skip_before_filter :check_user_profile, only: [:welcome, :inactive, :profile]
5 skip_before_filter :find_object_by_uuid, only: [:welcome, :activity, :storage]
6 before_filter :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup]
9 if params[:uuid] == current_user.uuid
12 redirect_to(params[:return_to] || project_path(params[:uuid]))
22 redirect_to (params[:return_to] || '/')
27 if current_user.andand.is_invited
28 redirect_to (params[:return_to] || '/')
33 params[:offer_return_to] ||= params[:return_to]
37 @breadcrumb_page_name = nil
38 @users = User.limit(params[:limit])
43 pipeline_instances: {}
46 @spans = [['This week', Time.now.beginning_of_week, Time.now],
48 Time.now.beginning_of_week.advance(weeks:-1),
49 Time.now.beginning_of_week],
50 ['This month', Time.now.beginning_of_month, Time.now],
52 1.month.ago.beginning_of_month,
53 Time.now.beginning_of_month]]
54 @spans.each do |span, threshold_start, threshold_end|
55 @activity[:logins][span] = Log.
56 filter([[:event_type, '=', 'login'],
57 [:object_kind, '=', 'arvados#user'],
58 [:created_at, '>=', threshold_start],
59 [:created_at, '<', threshold_end]])
60 @activity[:jobs][span] = Job.
61 filter([[:created_at, '>=', threshold_start],
62 [:created_at, '<', threshold_end]])
63 @activity[:pipeline_instances][span] = PipelineInstance.
64 filter([[:created_at, '>=', threshold_start],
65 [:created_at, '<', threshold_end]])
66 @activity.each do |type, act|
69 @user_activity[u.uuid] ||= {}
70 @user_activity[u.uuid][span + ' ' + type.to_s] ||= 0
72 records.each do |record|
73 @user_activity[record.modified_by_user_uuid] ||= {}
74 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] ||= 0
75 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] += 1
76 @total_activity[span + ' ' + type.to_s] ||= 0
77 @total_activity[span + ' ' + type.to_s] += 1
81 @users = @users.sort_by do |a|
82 [-@user_activity[a.uuid].values.inject(:+), a.full_name]
84 # Prepend a "Total" pseudo-user to the sorted list
85 @user_activity[nil] = @total_activity
86 @users = [OpenStruct.new(uuid: nil)] + @users
90 @breadcrumb_page_name = nil
91 @users = User.limit(params[:limit])
96 @user_storage[u.uuid] ||= {}
98 filter([[:object_uuid, '=', u.uuid],
99 [:event_type, '=', 'user-storage-report']]).
100 order(:created_at => :desc).
102 storage_log.each do |log_entry|
103 # We expect this block to only execute once since we specified limit(1)
104 @user_storage[u.uuid] = log_entry['properties']
105 @log_date[u.uuid] = log_entry['event_at']
107 total_storage.merge!(@user_storage[u.uuid]) { |k,v1,v2| v1 + v2 }
109 @users = @users.sort_by { |u|
110 [-@user_storage[u.uuid].values.push(0).inject(:+), u.full_name]}
111 # Prepend a "Total" pseudo-user to the sorted list
112 @users = [OpenStruct.new(uuid: nil)] + @users
113 @user_storage[nil] = total_storage
117 if current_user.andand.is_admin
125 if current_user.andand.is_admin
133 resp = arvados_api_client.api(ApiClientAuthorization, '', {
134 api_client_authorization: {
135 owner_uuid: @object.uuid
138 redirect_to root_url(api_token: resp[:api_token])
142 @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
147 order('created_at desc').
148 where(created_by: current_user.uuid)
150 @my_collections = Collection.
152 order('created_at desc').
153 where(created_by: current_user.uuid)
154 collection_uuids = @my_collections.collect &:uuid
157 collection_uuids.each do |uuid|
158 @persist_state[uuid] = 'cache'
161 Link.filter([['head_uuid', 'in', collection_uuids],
162 ['link_class', 'in', ['tag', 'resources']]]).
166 (@my_tag_links[link.head_uuid] ||= []) << link
168 if link.name == 'wants'
169 @persist_state[link.head_uuid] = 'persistent'
174 @my_pipelines = PipelineInstance.
176 order('created_at desc').
177 where(created_by: current_user.uuid)
180 f.js { render template: 'users/home.js' }
181 f.html { render template: 'users/home' }
186 if current_user.andand.is_admin
193 respond_to do |format|
194 if current_user.andand.is_admin
196 setup_params[:send_notification_email] = "#{Rails.configuration.send_user_setup_notification_email}"
197 if params['user_uuid'] && params['user_uuid'].size>0
198 setup_params[:uuid] = params['user_uuid']
200 if params['email'] && params['email'].size>0
201 user = {email: params['email']}
202 setup_params[:user] = user
204 if params['openid_prefix'] && params['openid_prefix'].size>0
205 setup_params[:openid_prefix] = params['openid_prefix']
207 if params['repo_name'] && params['repo_name'].size>0
208 setup_params[:repo_name] = params['repo_name']
210 if params['vm_uuid'] && params['vm_uuid'].size>0
211 setup_params[:vm_uuid] = params['vm_uuid']
214 if User.setup setup_params
217 self.render_error status: 422
220 self.render_error status: 422
226 @vms = VirtualMachine.all.results
228 @current_selections = find_current_links @object
230 respond_to do |format|
237 # repositories current user can read / write
239 filter([['head_uuid', 'is_a', 'arvados#repository'],
240 ['tail_uuid', '=', current_user.uuid],
241 ['link_class', '=', 'permission'],
244 owned_repositories = Repository.where(owner_uuid: current_user.uuid)
246 @my_repositories = (Repository.where(uuid: repo_links.collect(&:head_uuid)) |
248 uniq { |repo| repo.uuid }
252 repo_links.each do |link|
253 if link.name.in? ['can_write', 'can_manage']
254 @repo_writable[link.head_uuid] = link.name
258 owned_repositories.each do |repo|
259 @repo_writable[repo.uuid] = 'can_manage'
262 # virtual machines the current user can login into
264 Link.where(tail_uuid: current_user.uuid,
265 link_class: 'permission',
268 if perm_link.properties.andand[:username]
269 @my_vm_logins[perm_link.head_uuid] ||= []
270 @my_vm_logins[perm_link.head_uuid] << perm_link.properties[:username]
273 @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys)
275 # current user's ssh keys
276 @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: current_user.uuid)
279 f.html { render template: 'users/manage_account' }
283 def add_ssh_key_popup
284 respond_to do |format|
291 respond_to do |format|
292 key_params = {'key_type' => 'SSH'}
293 key_params['authorized_user_uuid'] = current_user.uuid
295 if params['name'] && params['name'].size>0
296 key_params['name'] = params['name'].strip
298 if params['public_key'] && params['public_key'].size>0
299 key_params['public_key'] = params['public_key'].strip
302 if !key_params['name'] && params['public_key'].andand.size>0
303 split_key = key_params['public_key'].split
304 key_params['name'] = split_key[-1] if (split_key.size == 3)
307 new_key = AuthorizedKey.create! key_params
311 self.render_error status: 422
316 def request_shell_access
317 logger.warn "request_access: #{params.inspect}"
318 params['request_url'] = request.url
319 RequestShellAccessReporter.send_request(current_user, params).deliver
324 def find_current_links user
325 current_selections = {}
328 return current_selections
332 oid_login_perms = Link.where(tail_uuid: user.email,
333 head_kind: 'arvados#user',
334 link_class: 'permission',
337 if oid_login_perms.any?
338 prefix_properties = oid_login_perms.first.properties
339 current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix]
343 repo_perms = Link.where(tail_uuid: user.uuid,
344 head_kind: 'arvados#repository',
345 link_class: 'permission',
348 repo_uuid = repo_perms.first.head_uuid
349 repos = Repository.where(head_uuid: repo_uuid)
351 repo_name = repos.first.name
352 current_selections[:repo_name] = repo_name
357 vm_login_perms = Link.where(tail_uuid: user.uuid,
358 head_kind: 'arvados#virtualMachine',
359 link_class: 'permission',
361 if vm_login_perms.any?
362 vm_uuid = vm_login_perms.first.head_uuid
363 current_selections[:vm_uuid] = vm_uuid
366 return current_selections