From: Tom Clegg Date: Fri, 14 Mar 2014 15:12:16 +0000 (-0400) Subject: Merge branch '2257-inequality-conditions' into 2290-user-activity X-Git-Tag: 1.1.0~2709^2~41^2~5^2~3 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/cf7e30873ef4b92cc8ec099b2bb344391a070e93 Merge branch '2257-inequality-conditions' into 2290-user-activity Conflicts: apps/workbench/app/controllers/users_controller.rb apps/workbench/app/models/arvados_base.rb apps/workbench/config/routes.rb --- cf7e30873ef4b92cc8ec099b2bb344391a070e93 diff --cc apps/workbench/app/controllers/users_controller.rb index 6168cd5293,c33de2d034..b9f43ba76a --- a/apps/workbench/app/controllers/users_controller.rb +++ b/apps/workbench/app/controllers/users_controller.rb @@@ -1,6 -1,7 +1,7 @@@ class UsersController < ApplicationController - skip_before_filter :find_object_by_uuid, :only => :welcome + 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 def welcome if current_user @@@ -9,53 -10,23 +10,70 @@@ end end + def activity + @breadcrumb_page_name = nil + @users = User.all + @user_activity = {} + @activity = { + logins: {}, + jobs: {}, + pipeline_instances: {} + } + @spans = [['This week', Time.now.beginning_of_week, Time.now], + ['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, + Time.now.beginning_of_month]] + @spans.each do |span, threshold_start, threshold_end| + @activity[:logins][span] = Log. + filter([[:event_type, '=', 'login'], + [:object_kind, '=', 'arvados#user'], + [:created_at, '>=', threshold_start], + [:created_at, '<', threshold_end]]) + @activity[:jobs][span] = Job. + filter([[:created_at, '>=', threshold_start], + [:created_at, '<', threshold_end]]) + @activity[:pipeline_instances][span] = PipelineInstance. + filter([[:created_at, '>=', threshold_start], + [:created_at, '<', threshold_end]]) + @activity.each do |type, act| + records = act[span] + @users.each do |u| + @user_activity[u.uuid] ||= {} + @user_activity[u.uuid][span + ' ' + type.to_s] ||= 0 + end + records.each do |record| + @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 + end + end + end + @users = @users.sort_by do |a| + [-@user_activity[a.uuid].values.inject(:+), a.full_name] + end + end + + def show_pane_list + if current_user.andand.is_admin + super | %w(Admin) + 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 @showallalerts = false @my_ssh_keys = AuthorizedKey.where(authorized_user_uuid: current_user.uuid) diff --cc apps/workbench/app/models/arvados_base.rb index 09e3d8cea2,fbf7ee5e79..4ba53b9529 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@@ -87,9 -91,7 +91,11 @@@ class ArvadosBase < ActiveRecord::Bas def self.order(*args) ArvadosResourceList.new(self).order(*args) end + + def self.filter(*args) + ArvadosResourceList.new(self).filter(*args) + end ++ def self.where(*args) ArvadosResourceList.new(self).where(*args) end diff --cc apps/workbench/config/routes.rb index 376934e91b,523771c0b1..0981d2ea37 --- a/apps/workbench/config/routes.rb +++ b/apps/workbench/config/routes.rb @@@ -19,7 -21,7 +21,8 @@@ ArvadosWorkbench::Application.routes.dr resources :users do get 'home', :on => :member get 'welcome', :on => :collection + get 'activity', :on => :collection + post 'sudo', :on => :member end resources :logs resources :factory_jobs