1 class UsersController < ApplicationController
2 skip_before_filter :find_object_by_uuid, :only => [:welcome, :activity]
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 if current_user.andand.is_admin
75 if current_user.andand.is_admin
83 resp = $arvados_api_client.api(ApiClientAuthorization, '', {
84 api_client_authorization: {
85 owner_uuid: @object.uuid
88 redirect_to root_url(api_token: resp[:api_token])
92 @showallalerts = false
93 @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid)
98 order('created_at desc').
99 where(created_by: current_user.uuid)
101 @my_collections = Collection.
103 order('created_at desc').
104 where(created_by: current_user.uuid)
106 Link.limit(1000).where(head_uuid: @my_collections.collect(&:uuid),
107 link_class: 'tag').each do |link|
108 (@my_tag_links[link.head_uuid] ||= []) << link
111 @my_pipelines = PipelineInstance.
113 order('created_at desc').
114 where(created_by: current_user.uuid)
117 # A Tutorial is a Link which has link_class "resources" and name
118 # "wants", and is owned by the Tutorials Group (i.e., named
119 # "Arvados Tutorials" and owned by the system user).
120 @tutorial_group = Group.where(owner_uuid: User.system.uuid,
121 name: 'Arvados Tutorials').first
123 @tutorial_links = Link.where(tail_uuid: @tutorial_group.uuid,
124 link_class: 'resources',
129 @tutorial_complete = {
130 'Run a job' => @my_last_job
133 f.js { render template: 'users/home.js' }
134 f.html { render template: 'users/home' }
139 if current_user.andand.is_admin
146 respond_to do |format|
147 if current_user.andand.is_admin
149 if params['user_uuid'] && params['user_uuid'].size>0
150 setup_params[:uuid] = params['user_uuid']
152 if params['email'] && params['email'].size>0
153 user = {email: params['email']}
154 setup_params[:user] = user
156 if params['openid_prefix'] && params['openid_prefix'].size>0
157 setup_params[:openid_prefix] = params['openid_prefix']
159 if params['repo_name'] && params['repo_name'].size>0
160 setup_params[:repo_name] = params['repo_name']
162 if params['vm_uuid'] && params['vm_uuid'].size>0
163 setup_params[:vm_uuid] = params['vm_uuid']
166 if User.setup setup_params
169 self.render_error status: 422
172 self.render_error status: 422
178 @vms = VirtualMachine.all.results
180 @current_selections = find_current_links @object
182 respond_to do |format|
190 def find_current_links user
191 current_selections = {}
194 return current_selections
198 oid_login_perms = Link.where(tail_uuid: user.email,
199 head_kind: 'arvados#user',
200 link_class: 'permission',
203 if oid_login_perms.any?
204 prefix_properties = oid_login_perms.first.properties
205 current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix]
209 repo_perms = Link.where(tail_uuid: user.uuid,
210 head_kind: 'arvados#repository',
211 link_class: 'permission',
214 repo_uuid = repo_perms.first.head_uuid
215 repos = Repository.where(head_uuid: repo_uuid)
217 repo_name = repos.first.name
218 current_selections[:repo_name] = repo_name
223 vm_login_perms = Link.where(tail_uuid: user.uuid,
224 head_kind: 'arvados#virtualMachine',
225 link_class: 'permission',
227 if vm_login_perms.any?
228 vm_uuid = vm_login_perms.first.head_uuid
229 current_selections[:vm_uuid] = vm_uuid
232 return current_selections