1 class UsersController < ApplicationController
2 skip_before_filter :find_object_by_uuid, :only => [:welcome, :activity, :storage]
3 before_filter :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup]
7 params[:action] = 'home'
13 @breadcrumb_page_name = nil
14 @users = User.limit(params[:limit] || 1000).all
19 pipeline_instances: {}
22 @spans = [['This week', Time.now.beginning_of_week, Time.now],
24 Time.now.beginning_of_week.advance(weeks:-1),
25 Time.now.beginning_of_week],
26 ['This month', Time.now.beginning_of_month, Time.now],
28 1.month.ago.beginning_of_month,
29 Time.now.beginning_of_month]]
30 @spans.each do |span, threshold_start, threshold_end|
31 @activity[:logins][span] = Log.
32 filter([[:event_type, '=', 'login'],
33 [:object_kind, '=', 'arvados#user'],
34 [:created_at, '>=', threshold_start],
35 [:created_at, '<', threshold_end]])
36 @activity[:jobs][span] = Job.
37 filter([[:created_at, '>=', threshold_start],
38 [:created_at, '<', threshold_end]])
39 @activity[:pipeline_instances][span] = PipelineInstance.
40 filter([[:created_at, '>=', threshold_start],
41 [:created_at, '<', threshold_end]])
42 @activity.each do |type, act|
45 @user_activity[u.uuid] ||= {}
46 @user_activity[u.uuid][span + ' ' + type.to_s] ||= 0
48 records.each do |record|
49 @user_activity[record.modified_by_user_uuid] ||= {}
50 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] ||= 0
51 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] += 1
52 @total_activity[span + ' ' + type.to_s] ||= 0
53 @total_activity[span + ' ' + type.to_s] += 1
57 @users = @users.sort_by do |a|
58 [-@user_activity[a.uuid].values.inject(:+), a.full_name]
60 # Prepend a "Total" pseudo-user to the sorted list
61 @user_activity[nil] = @total_activity
62 @users = [OpenStruct.new(uuid: nil)] + @users
66 @breadcrumb_page_name = nil
67 @users = User.limit(params[:limit] || 1000).all
72 @user_storage[u.uuid] ||= {}
74 filter([[:object_uuid, '=', u.uuid],
75 [:event_type, '=', 'user-storage-report']]).
76 order(:created_at => :desc).
78 storage_log.each do |log_entry|
79 # We expect this block to only execute once since we specified limit(1)
80 @user_storage[u.uuid] = log_entry['properties']
81 @log_date[u.uuid] = log_entry['event_at']
83 total_storage.merge!(@user_storage[u.uuid]) { |k,v1,v2| v1 + v2 }
85 @users = @users.sort_by { |u|
86 [-@user_storage[u.uuid].values.push(0).inject(:+), u.full_name]}
87 # Prepend a "Total" pseudo-user to the sorted list
88 @users = [OpenStruct.new(uuid: nil)] + @users
89 @user_storage[nil] = total_storage
93 if current_user.andand.is_admin
101 if current_user.andand.is_admin
109 resp = arvados_api_client.api(ApiClientAuthorization, '', {
110 api_client_authorization: {
111 owner_uuid: @object.uuid
114 redirect_to root_url(api_token: resp[:api_token])
118 @showallalerts = false
119 @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
124 order('created_at desc').
125 where(created_by: current_user.uuid)
127 @my_collections = Collection.
129 order('created_at desc').
130 where(created_by: current_user.uuid)
131 collection_uuids = @my_collections.collect &:uuid
134 collection_uuids.each do |uuid|
135 @persist_state[uuid] = 'cache'
138 Link.limit(1000).filter([['head_uuid', 'in', collection_uuids],
139 ['link_class', 'in', ['tag', 'resources']]]).
143 (@my_tag_links[link.head_uuid] ||= []) << link
145 if link.name == 'wants'
146 @persist_state[link.head_uuid] = 'persistent'
151 @my_pipelines = PipelineInstance.
153 order('created_at desc').
154 where(created_by: current_user.uuid)
157 f.js { render template: 'users/home.js' }
158 f.html { render template: 'users/home' }
163 if current_user.andand.is_admin
170 respond_to do |format|
171 if current_user.andand.is_admin
173 setup_params[:send_notification_email] = "#{Rails.configuration.send_user_setup_notification_email}"
174 if params['user_uuid'] && params['user_uuid'].size>0
175 setup_params[:uuid] = params['user_uuid']
177 if params['email'] && params['email'].size>0
178 user = {email: params['email']}
179 setup_params[:user] = user
181 if params['openid_prefix'] && params['openid_prefix'].size>0
182 setup_params[:openid_prefix] = params['openid_prefix']
184 if params['repo_name'] && params['repo_name'].size>0
185 setup_params[:repo_name] = params['repo_name']
187 if params['vm_uuid'] && params['vm_uuid'].size>0
188 setup_params[:vm_uuid] = params['vm_uuid']
191 if User.setup setup_params
194 self.render_error status: 422
197 self.render_error status: 422
203 @vms = VirtualMachine.all.results
205 @current_selections = find_current_links @object
207 respond_to do |format|
215 def find_current_links user
216 current_selections = {}
219 return current_selections
223 oid_login_perms = Link.where(tail_uuid: user.email,
224 head_kind: 'arvados#user',
225 link_class: 'permission',
228 if oid_login_perms.any?
229 prefix_properties = oid_login_perms.first.properties
230 current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix]
234 repo_perms = Link.where(tail_uuid: user.uuid,
235 head_kind: 'arvados#repository',
236 link_class: 'permission',
239 repo_uuid = repo_perms.first.head_uuid
240 repos = Repository.where(head_uuid: repo_uuid)
242 repo_name = repos.first.name
243 current_selections[:repo_name] = repo_name
248 vm_login_perms = Link.where(tail_uuid: user.uuid,
249 head_kind: 'arvados#virtualMachine',
250 link_class: 'permission',
252 if vm_login_perms.any?
253 vm_uuid = vm_login_perms.first.head_uuid
254 current_selections[:vm_uuid] = vm_uuid
257 return current_selections