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|
214 # repositories current user can read / write
216 Link.filter([['head_uuid', 'is_a', 'arvados#repository'],
217 ['tail_uuid', '=', current_user.uuid],
218 ['link_class', '=', 'permission'],
219 ['name', 'in', ['can_write', 'can_read']],
222 repo_links << perm_link[:head_uuid]
224 @my_repositories = Repository.where(uuid: repo_links)
226 # virtual machines the current user can login into
228 Link.where(tail_uuid: current_user.uuid,
229 link_class: 'permission',
232 if perm_link.properties.andand[:username]
233 @my_vm_logins[perm_link.head_uuid] ||= []
234 @my_vm_logins[perm_link.head_uuid] << perm_link.properties[:username]
237 @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys)
239 # current user's ssh keys
240 @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: current_user.uuid)
243 f.html { render template: 'users/manage_account' }
247 def add_ssh_key_popup
248 respond_to do |format|
255 respond_to do |format|
256 key_params = {'key_type' => 'SSH'}
257 key_params['authorized_user_uuid'] = current_user.uuid
259 if params['name'] && params['name'].size>0
260 key_params['name'] = params['name']
262 if params['public_key'] && params['public_key'].size>0
263 key_params['public_key'] = params['public_key']
266 new_key = AuthorizedKey.create! key_params
270 self.render_error status: 422
277 def find_current_links user
278 current_selections = {}
281 return current_selections
285 oid_login_perms = Link.where(tail_uuid: user.email,
286 head_kind: 'arvados#user',
287 link_class: 'permission',
290 if oid_login_perms.any?
291 prefix_properties = oid_login_perms.first.properties
292 current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix]
296 repo_perms = Link.where(tail_uuid: user.uuid,
297 head_kind: 'arvados#repository',
298 link_class: 'permission',
301 repo_uuid = repo_perms.first.head_uuid
302 repos = Repository.where(head_uuid: repo_uuid)
304 repo_name = repos.first.name
305 current_selections[:repo_name] = repo_name
310 vm_login_perms = Link.where(tail_uuid: user.uuid,
311 head_kind: 'arvados#virtualMachine',
312 link_class: 'permission',
314 if vm_login_perms.any?
315 vm_uuid = vm_login_perms.first.head_uuid
316 current_selections[:vm_uuid] = vm_uuid
319 return current_selections