X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/017d19d31606b8b313c04fffc33d44592ad9644b..9318b234cbfae138524e45080f549c277e15776b:/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 6cf15a8542..350f297af3 100644 --- a/apps/workbench/app/controllers/users_controller.rb +++ b/apps/workbench/app/controllers/users_controller.rb @@ -102,6 +102,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) @@ -255,39 +256,31 @@ class UsersController < ApplicationController end end - def manage_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: current_user.uuid) - - @my_repositories = (Repository.where(uuid: repo_links.collect(&:head_uuid)) | - owned_repositories). - uniq { |repo| repo.uuid } - + def repositories + # all repositories accessible by current user + all_repositories = Hash[Repository.all.order('name asc').collect {|repo| [repo.uuid, repo]}] + @my_repositories = [] # we want them ordered as owned and the rest @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' + # owned repos + all_repositories.each do |_, repo| + if repo.owner_uuid == current_user.uuid + @repo_writable[repo.uuid] = 'can_write' + @my_repositories << repo + end end - respond_to do |f| - f.html { render template: 'users/manage_repositories' } + # rest of the repos + handled = @my_repositories.map(&:uuid) + all_repositories.each do |_, repo| + @my_repositories << repo if !repo.uuid.in?(handled) end end - def manage_virtual_machines + 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| @@ -297,66 +290,10 @@ class UsersController < ApplicationController end end @my_virtual_machines = VirtualMachine.where(uuid: @my_vm_logins.keys) - - respond_to do |f| - f.html { render template: 'users/manage_virtual_machines' } - end end - def manage_ssh_keys - @my_ssh_keys = AuthorizedKey.where(key_type: 'SSH', owner_uuid: current_user.uuid) - - @page = params["page"] - respond_to do |f| - f.html { render template: 'users/manage_ssh_keys' } - 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 - @my_vm_logins = {} - Link.where(tail_uuid: current_user.uuid, - link_class: 'permission', - name: 'can_login'). - 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) - - # 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