1 class UsersController < ApplicationController
2 skip_before_filter :find_object_by_uuid, :only => [:welcome, :activity, :storage]
3 skip_around_filter :thread_with_mandatory_api_token, :only => :welcome
4 before_filter :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup]
8 params[:action] = 'home'
14 @breadcrumb_page_name = nil
15 @users = User.limit(params[:limit] || 1000).all
20 pipeline_instances: {}
23 @spans = [['This week', Time.now.beginning_of_week, Time.now],
25 Time.now.beginning_of_week.advance(weeks:-1),
26 Time.now.beginning_of_week],
27 ['This month', Time.now.beginning_of_month, Time.now],
29 1.month.ago.beginning_of_month,
30 Time.now.beginning_of_month]]
31 @spans.each do |span, threshold_start, threshold_end|
32 @activity[:logins][span] = Log.
33 filter([[:event_type, '=', 'login'],
34 [:object_kind, '=', 'arvados#user'],
35 [:created_at, '>=', threshold_start],
36 [:created_at, '<', threshold_end]])
37 @activity[:jobs][span] = Job.
38 filter([[:created_at, '>=', threshold_start],
39 [:created_at, '<', threshold_end]])
40 @activity[:pipeline_instances][span] = PipelineInstance.
41 filter([[:created_at, '>=', threshold_start],
42 [:created_at, '<', threshold_end]])
43 @activity.each do |type, act|
46 @user_activity[u.uuid] ||= {}
47 @user_activity[u.uuid][span + ' ' + type.to_s] ||= 0
49 records.each do |record|
50 @user_activity[record.modified_by_user_uuid] ||= {}
51 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] ||= 0
52 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] += 1
53 @total_activity[span + ' ' + type.to_s] ||= 0
54 @total_activity[span + ' ' + type.to_s] += 1
58 @users = @users.sort_by do |a|
59 [-@user_activity[a.uuid].values.inject(:+), a.full_name]
61 # Prepend a "Total" pseudo-user to the sorted list
62 @user_activity[nil] = @total_activity
63 @users = [OpenStruct.new(uuid: nil)] + @users
67 @breadcrumb_page_name = nil
68 @users = User.limit(params[:limit] || 1000).all
73 @user_storage[u.uuid] ||= {}
75 filter([[:object_uuid, '=', u.uuid],
76 [:event_type, '=', 'user-storage-report']]).
77 order(:created_at => :desc).
79 storage_log.each do |log_entry|
80 # We expect this block to only execute once since we specified limit(1)
81 @user_storage[u.uuid] = log_entry['properties']
82 @log_date[u.uuid] = log_entry['event_at']
84 total_storage.merge!(@user_storage[u.uuid]) { |k,v1,v2| v1 + v2 }
86 @users = @users.sort_by { |u|
87 [-@user_storage[u.uuid].values.push(0).inject(:+), u.full_name]}
88 # Prepend a "Total" pseudo-user to the sorted list
89 @users = [OpenStruct.new(uuid: nil)] + @users
90 @user_storage[nil] = total_storage
94 if current_user.andand.is_admin
102 if current_user.andand.is_admin
110 resp = $arvados_api_client.api(ApiClientAuthorization, '', {
111 api_client_authorization: {
112 owner_uuid: @object.uuid
115 redirect_to root_url(api_token: resp[:api_token])
119 @showallalerts = false
120 @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
125 order('created_at desc').
126 where(created_by: current_user.uuid)
128 @my_collections = Collection.
130 order('created_at desc').
131 where(created_by: current_user.uuid)
132 collection_uuids = @my_collections.collect &:uuid
135 collection_uuids.each do |uuid|
136 @persist_state[uuid] = 'cache'
139 Link.limit(1000).filter([['head_uuid', 'in', collection_uuids],
140 ['link_class', 'in', ['tag', 'resources']]]).
144 (@my_tag_links[link.head_uuid] ||= []) << link
146 if link.name == 'wants'
147 @persist_state[link.head_uuid] = 'persistent'
152 @my_pipelines = PipelineInstance.
154 order('created_at desc').
155 where(created_by: current_user.uuid)
158 f.js { render template: 'users/home.js' }
159 f.html { render template: 'users/home' }
164 if current_user.andand.is_admin
171 respond_to do |format|
172 if current_user.andand.is_admin
174 setup_params[:send_notification_email] = "#{Rails.configuration.send_user_setup_notification_email}"
175 if params['user_uuid'] && params['user_uuid'].size>0
176 setup_params[:uuid] = params['user_uuid']
178 if params['email'] && params['email'].size>0
179 user = {email: params['email']}
180 setup_params[:user] = user
182 if params['openid_prefix'] && params['openid_prefix'].size>0
183 setup_params[:openid_prefix] = params['openid_prefix']
185 if params['repo_name'] && params['repo_name'].size>0
186 setup_params[:repo_name] = params['repo_name']
188 if params['vm_uuid'] && params['vm_uuid'].size>0
189 setup_params[:vm_uuid] = params['vm_uuid']
192 if User.setup setup_params
195 self.render_error status: 422
198 self.render_error status: 422
204 @vms = VirtualMachine.all.results
206 @current_selections = find_current_links @object
208 respond_to do |format|
216 def find_current_links user
217 current_selections = {}
220 return current_selections
224 oid_login_perms = Link.where(tail_uuid: user.email,
225 head_kind: 'arvados#user',
226 link_class: 'permission',
229 if oid_login_perms.any?
230 prefix_properties = oid_login_perms.first.properties
231 current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix]
235 repo_perms = Link.where(tail_uuid: user.uuid,
236 head_kind: 'arvados#repository',
237 link_class: 'permission',
240 repo_uuid = repo_perms.first.head_uuid
241 repos = Repository.where(head_uuid: repo_uuid)
243 repo_name = repos.first.name
244 current_selections[:repo_name] = repo_name
249 vm_login_perms = Link.where(tail_uuid: user.uuid,
250 head_kind: 'arvados#virtualMachine',
251 link_class: 'permission',
253 if vm_login_perms.any?
254 vm_uuid = vm_login_perms.first.head_uuid
255 current_selections[:vm_uuid] = vm_uuid
258 return current_selections