X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2d9d106c40b83e9a72d431bdb198ed5b8b13550a..e40fdedbc285a0fa6af16e41b5b4f72e46e9987d:/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 927637f65d..a98bb11a99 100644 --- a/apps/workbench/app/controllers/users_controller.rb +++ b/apps/workbench/app/controllers/users_controller.rb @@ -1,6 +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, :unsetup] def welcome if current_user @@ -18,15 +19,15 @@ class UsersController < ApplicationController jobs: {}, pipeline_instances: {} } + @total_activity = {} @spans = [['This week', Time.now.beginning_of_week, Time.now], - ['Last week', 1.week.ago.beginning_of_week, nil], + ['Last week', + Time.now.beginning_of_week.advance(weeks:-1), + Time.now.beginning_of_week], ['This month', Time.now.beginning_of_month, Time.now], - ['Last month', 1.month.ago.beginning_of_month, nil]]. - collect do |span| - span[2] ||= span[1].advance(months: 1) if span[0].match /month/ - span[2] ||= span[1].advance(weeks: 1) if span[0].match /week/ - span - end + ['Last month', + 1.month.ago.beginning_of_month, + Time.now.beginning_of_month]] @spans.each do |span, threshold_start, threshold_end| @activity[:logins][span] = Log. filter([[:event_type, '=', 'login'], @@ -49,12 +50,42 @@ 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 + if current_user.andand.is_admin + super | %w(Admin) + else + super + 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: { + owner_uuid: @object.uuid + } + }) + redirect_to root_url(api_token: resp[:api_token]) end def home @@ -106,4 +137,12 @@ class UsersController < ApplicationController f.html { render template: 'users/home' } end end + + def unsetup + if current_user.andand.is_admin + @object.unsetup @object + end + show + end + end