15583: Add with_count('none') more places
[arvados.git] / apps / workbench / app / controllers / users_controller.rb
index 4cf1fffc09bb3e3a815311f86c2550bbe16e5f3d..0e86575b2ecdab360993aedec8db977b6fb64816 100644 (file)
@@ -1,9 +1,13 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 class UsersController < ApplicationController
-  skip_around_filter :require_thread_api_token, only: :welcome
-  skip_before_filter :check_user_agreements, only: [:welcome, :inactive]
-  skip_before_filter :check_user_profile, only: [:welcome, :inactive, :profile]
-  skip_before_filter :find_object_by_uuid, only: [:welcome, :activity, :storage]
-  before_filter :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup]
+  skip_around_action :require_thread_api_token, only: :welcome
+  skip_before_action :check_user_agreements, only: [:welcome, :inactive, :link_account, :merge]
+  skip_before_action :check_user_profile, only: [:welcome, :inactive, :profile, :link_account, :merge]
+  skip_before_action :find_object_by_uuid, only: [:welcome, :activity, :storage]
+  before_action :ensure_current_user_is_admin, only: [:sudo, :unsetup, :setup]
 
   def show
     if params[:uuid] == current_user.uuid
@@ -102,6 +106,7 @@ class UsersController < ApplicationController
         filter([[:object_uuid, '=', u.uuid],
                 [:event_type, '=', 'user-storage-report']]).
         order(:created_at => :desc).
+        with_count('none').
         limit(1)
       storage_log.each do |log_entry|
         # We expect this block to only execute once since we specified limit(1)
@@ -139,7 +144,7 @@ class UsersController < ApplicationController
                                       owner_uuid: @object.uuid
                                     }
                                   })
-    redirect_to root_url(api_token: resp[:api_token])
+    redirect_to root_url(api_token: "v2/#{resp[:uuid]}/#{resp[:api_token]}")
   end
 
   def home
@@ -149,11 +154,13 @@ class UsersController < ApplicationController
     @my_jobs = Job.
       limit(10).
       order('created_at desc').
+      with_count('none').
       where(created_by: current_user.uuid)
 
     @my_collections = Collection.
       limit(10).
       order('created_at desc').
+      with_count('none').
       where(created_by: current_user.uuid)
     collection_uuids = @my_collections.collect &:uuid
 
@@ -178,6 +185,7 @@ class UsersController < ApplicationController
     @my_pipelines = PipelineInstance.
       limit(10).
       order('created_at desc').
+      with_count('none').
       where(created_by: current_user.uuid)
 
     respond_to do |f|
@@ -255,35 +263,9 @@ class UsersController < ApplicationController
     end
   end
 
-  def manage_account
-    # repositories current user can read / write
-    repo_links = Link.
-      filter([['head_uuid', 'is_a', 'arvados#repository'],
-              ['tail_uuid', '=', current_user.uuid],
-              ['link_class', '=', 'permission'],
-             ])
-
-    owned_repositories = Repository.where(owner_uuid: current_user.uuid)
-
-    @my_repositories = (Repository.where(uuid: repo_links.collect(&:head_uuid)) |
-                        owned_repositories).
-                       uniq { |repo| repo.uuid }
-
-
-    @repo_writable = {}
-    repo_links.each do |link|
-      if link.name.in? ['can_write', 'can_manage']
-        @repo_writable[link.head_uuid] = link.name
-      end
-    end
-
-    owned_repositories.each do |repo|
-      @repo_writable[repo.uuid] = 'can_manage'
-    end
-
-    # virtual machines the current user can login into
+  def virtual_machines
     @my_vm_logins = {}
-    Link.where(tail_uuid: current_user.uuid,
+    Link.where(tail_uuid: @object.uuid,
                link_class: 'permission',
                name: 'can_login').
           each do |perm_link|
@@ -293,13 +275,10 @@ class UsersController < ApplicationController
             end
           end
     @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys)
+  end
 
-    # current user's ssh keys
-    @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: current_user.uuid)
-
-    respond_to do |f|
-      f.html { render template: 'users/manage_account' }
-    end
+  def ssh_keys
+    @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: @object.uuid)
   end
 
   def add_ssh_key_popup
@@ -341,6 +320,11 @@ class UsersController < ApplicationController
     RequestShellAccessReporter.send_request(current_user, params).deliver
   end
 
+  def merge
+    User.merge params[:new_user_token], params[:direction]
+    redirect_to "/"
+  end
+
   protected
 
   def find_current_links user