Merge branch '15877-accept-json-in-json'
[arvados.git] / apps / workbench / app / controllers / users_controller.rb
index 1a1c5f802152ffe4cdb7ff009fce0bb02c70cbc1..27fc12bf4c9fc7d3239131f96e93d114588bad31 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
@@ -39,7 +43,7 @@ class UsersController < ApplicationController
 
   def activity
     @breadcrumb_page_name = nil
-    @users = User.limit(params[:limit])
+    @users = User.limit(params[:limit]).with_count("none")
     @user_activity = {}
     @activity = {
       logins: {},
@@ -60,13 +64,13 @@ class UsersController < ApplicationController
         filter([[:event_type, '=', 'login'],
                 [:object_kind, '=', 'arvados#user'],
                 [:created_at, '>=', threshold_start],
-                [:created_at, '<', threshold_end]])
+                [:created_at, '<', threshold_end]]).with_count("none")
       @activity[:jobs][span] = Job.select(%w(uuid modified_by_user_uuid)).
         filter([[:created_at, '>=', threshold_start],
-                [:created_at, '<', threshold_end]])
+                [:created_at, '<', threshold_end]]).with_count("none")
       @activity[:pipeline_instances][span] = PipelineInstance.select(%w(uuid modified_by_user_uuid)).
         filter([[:created_at, '>=', threshold_start],
-                [:created_at, '<', threshold_end]])
+                [:created_at, '<', threshold_end]]).with_count("none")
       @activity.each do |type, act|
         records = act[span]
         @users.each do |u|
@@ -92,7 +96,7 @@ class UsersController < ApplicationController
 
   def storage
     @breadcrumb_page_name = nil
-    @users = User.limit(params[:limit])
+    @users = User.limit(params[:limit]).with_count("none")
     @user_storage = {}
     total_storage = {}
     @log_date = {}
@@ -120,7 +124,7 @@ class UsersController < ApplicationController
 
   def show_pane_list
     if current_user.andand.is_admin
-      super | %w(Admin)
+      %w(Admin) | super
     else
       super
     end
@@ -140,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
@@ -150,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
 
@@ -164,7 +170,7 @@ class UsersController < ApplicationController
     end
 
     Link.filter([['head_uuid', 'in', collection_uuids],
-                             ['link_class', 'in', ['tag', 'resources']]]).
+                             ['link_class', 'in', ['tag', 'resources']]]).with_count("none")
       each do |link|
       case link.link_class
       when 'tag'
@@ -179,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|
@@ -198,7 +205,7 @@ class UsersController < ApplicationController
     respond_to do |format|
       if current_user.andand.is_admin
         setup_params = {}
-        setup_params[:send_notification_email] = "#{Rails.configuration.send_user_setup_notification_email}"
+        setup_params[:send_notification_email] = "#{Rails.configuration.Mail.SendUserSetupNotificationEmail}"
         if params['user_uuid'] && params['user_uuid'].size>0
           setup_params[:uuid] = params['user_uuid']
         end
@@ -256,44 +263,18 @@ class UsersController < ApplicationController
     end
   end
 
-  def repositories
-    repo_links = Link.
-      filter([['head_uuid', 'is_a', 'arvados#repository'],
-              ['tail_uuid', '=', current_user.uuid],
-              ['link_class', '=', 'permission'],
-             ])
-
-    owned_repositories = Repository.where(owner_uuid: @object.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
-  end
-
   def virtual_machines
     @my_vm_logins = {}
     Link.where(tail_uuid: @object.uuid,
                link_class: 'permission',
-               name: 'can_login').
+               name: 'can_login').with_count("none").
           each do |perm_link|
             if perm_link.properties.andand[:username]
               @my_vm_logins[perm_link.head_uuid] ||= []
               @my_vm_logins[perm_link.head_uuid] << perm_link.properties[:username]
             end
           end
-    @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys)
+    @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys).with_count("none")
   end
 
   def ssh_keys
@@ -339,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
@@ -352,7 +338,7 @@ class UsersController < ApplicationController
     oid_login_perms = Link.where(tail_uuid: user.email,
                                    head_kind: 'arvados#user',
                                    link_class: 'permission',
-                                   name: 'can_login')
+                                   name: 'can_login').with_count("none")
 
     if oid_login_perms.any?
       prefix_properties = oid_login_perms.first.properties
@@ -363,10 +349,10 @@ class UsersController < ApplicationController
     repo_perms = Link.where(tail_uuid: user.uuid,
                             head_kind: 'arvados#repository',
                             link_class: 'permission',
-                            name: 'can_write')
+                            name: 'can_write').with_count("none")
     if repo_perms.any?
       repo_uuid = repo_perms.first.head_uuid
-      repos = Repository.where(head_uuid: repo_uuid)
+      repos = Repository.where(head_uuid: repo_uuid).with_count("none")
       if repos.any?
         repo_name = repos.first.name
         current_selections[:repo_name] = repo_name
@@ -377,7 +363,7 @@ class UsersController < ApplicationController
     vm_login_perms = Link.where(tail_uuid: user.uuid,
                               head_kind: 'arvados#virtualMachine',
                               link_class: 'permission',
-                              name: 'can_login')
+                              name: 'can_login').with_count("none")
     if vm_login_perms.any?
       vm_perm = vm_login_perms.first
       vm_uuid = vm_perm.head_uuid