Merge branch '2257-inequality-conditions' into 2290-user-activity
[arvados.git] / apps / workbench / app / controllers / users_controller.rb
index 927637f65d010cdf6f33a6972f909999ad605d9a..b9f43ba76a03d3e27141559aa8d24e1e046f48dc 100644 (file)
@@ -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
 
   def welcome
     if current_user
@@ -19,14 +20,13 @@ class UsersController < ApplicationController
       pipeline_instances: {}
     }
     @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'],
@@ -57,6 +57,23 @@ class UsersController < ApplicationController
     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)