X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cf7e30873ef4b92cc8ec099b2bb344391a070e93..eeeceb21a479780dfa7d550523ab961f477e39ad:/apps/workbench/app/controllers/users_controller.rb diff --git a/apps/workbench/app/controllers/users_controller.rb b/apps/workbench/app/controllers/users_controller.rb index b9f43ba76a..3077c2f6d3 100644 --- a/apps/workbench/app/controllers/users_controller.rb +++ b/apps/workbench/app/controllers/users_controller.rb @@ -1,7 +1,7 @@ class UsersController < ApplicationController skip_before_filter :find_object_by_uuid, :only => [:welcome, :activity] skip_around_filter :thread_with_mandatory_api_token, :only => :welcome - before_filter :ensure_current_user_is_admin, only: :sudo + before_filter :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup] def welcome if current_user @@ -12,13 +12,14 @@ class UsersController < ApplicationController def activity @breadcrumb_page_name = nil - @users = User.all + @users = User.limit(params[:limit] || 1000).all @user_activity = {} @activity = { logins: {}, jobs: {}, pipeline_instances: {} } + @total_activity = {} @spans = [['This week', Time.now.beginning_of_week, Time.now], ['Last week', Time.now.beginning_of_week.advance(weeks:-1), @@ -49,12 +50,17 @@ class UsersController < ApplicationController @user_activity[record.modified_by_user_uuid] ||= {} @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] ||= 0 @user_activity[record.modified_by_user_uuid][span + ' ' + type.to_s] += 1 + @total_activity[span + ' ' + type.to_s] ||= 0 + @total_activity[span + ' ' + type.to_s] += 1 end end end @users = @users.sort_by do |a| [-@user_activity[a.uuid].values.inject(:+), a.full_name] end + # Prepend a "Total" pseudo-user to the sorted list + @user_activity[nil] = @total_activity + @users = [OpenStruct.new(uuid: nil)] + @users end def show_pane_list @@ -65,6 +71,14 @@ class UsersController < ApplicationController end end + def index_pane_list + if current_user.andand.is_admin + super | %w(Activity) + else + super + end + end + def sudo resp = $arvados_api_client.api(ApiClientAuthorization, '', { api_client_authorization: { @@ -77,9 +91,6 @@ class UsersController < ApplicationController def home @showallalerts = false @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid) - # @my_vm_perms = Link.where(tail_uuid: current_user.uuid, head_kind: 'arvados#virtual_machine', link_class: 'permission', name: 'can_login') - # @my_repo_perms = Link.where(tail_uuid: current_user.uuid, head_kind: 'arvados#repository', link_class: 'permission', name: 'can_write') - @my_tag_links = {} @my_jobs = Job. @@ -123,4 +134,103 @@ class UsersController < ApplicationController f.html { render template: 'users/home' } end end + + def unsetup + if current_user.andand.is_admin + @object.unsetup + end + show + end + + def setup + respond_to do |format| + if current_user.andand.is_admin + setup_params = {} + setup_params[:send_notification_email] = "#{Rails.configuration.send_user_setup_notification_email}" + if params['user_uuid'] && params['user_uuid'].size>0 + setup_params[:uuid] = params['user_uuid'] + end + if params['email'] && params['email'].size>0 + user = {email: params['email']} + setup_params[:user] = user + end + if params['openid_prefix'] && params['openid_prefix'].size>0 + setup_params[:openid_prefix] = params['openid_prefix'] + end + if params['repo_name'] && params['repo_name'].size>0 + setup_params[:repo_name] = params['repo_name'] + end + if params['vm_uuid'] && params['vm_uuid'].size>0 + setup_params[:vm_uuid] = params['vm_uuid'] + end + + if User.setup setup_params + format.js + else + self.render_error status: 422 + end + else + self.render_error status: 422 + end + end + end + + def setup_popup + @vms = VirtualMachine.all.results + + @current_selections = find_current_links @object + + respond_to do |format| + format.html + format.js + end + end + + protected + + def find_current_links user + current_selections = {} + + if !user + return current_selections + end + + # oid login perm + oid_login_perms = Link.where(tail_uuid: user.email, + head_kind: 'arvados#user', + link_class: 'permission', + name: 'can_login') + + if oid_login_perms.any? + prefix_properties = oid_login_perms.first.properties + current_selections[:identity_url_prefix] = prefix_properties[:identity_url_prefix] + end + + # repo perm + repo_perms = Link.where(tail_uuid: user.uuid, + head_kind: 'arvados#repository', + link_class: 'permission', + name: 'can_write') + if repo_perms.any? + repo_uuid = repo_perms.first.head_uuid + repos = Repository.where(head_uuid: repo_uuid) + if repos.any? + repo_name = repos.first.name + current_selections[:repo_name] = repo_name + end + end + + # vm login perm + vm_login_perms = Link.where(tail_uuid: user.uuid, + head_kind: 'arvados#virtualMachine', + link_class: 'permission', + name: 'can_login') + if vm_login_perms.any? + vm_uuid = vm_login_perms.first.head_uuid + current_selections[:vm_uuid] = vm_uuid + end + + return current_selections + end + end