Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika@curoverse.com>
authorradhika <radhika@curoverse.com>
Fri, 30 Jun 2017 17:25:31 +0000 (13:25 -0400)
committerradhika <radhika@curoverse.com>
Fri, 30 Jun 2017 17:25:31 +0000 (13:25 -0400)
Merge branch 'master' into 11870-repositories-index

Conflicts:
apps/workbench/app/views/repositories/_show_help.html.erb
apps/workbench/app/views/users/_repositories.html.erb
apps/workbench/app/views/users/repositories.html.erb

1  2 
apps/workbench/app/controllers/repositories_controller.rb
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/app/views/repositories/_add_repository_modal.html.erb
apps/workbench/app/views/repositories/_show_help.html.erb
apps/workbench/test/controllers/repositories_controller_test.rb
apps/workbench/test/controllers/users_controller_test.rb
apps/workbench/test/integration/application_layout_test.rb
apps/workbench/test/integration/user_settings_menu_test.rb

index 37bc000c75b96aac120ce7a6d7916e7a88003832,2a39a9401857d6fe8035091d2af0100fca480b80..5ca6f22b02f54bf2ea3b213b7106717cd10c845b
@@@ -1,8 -1,12 +1,12 @@@
+ # Copyright (C) The Arvados Authors. All rights reserved.
+ #
+ # SPDX-License-Identifier: AGPL-3.0
  class RepositoriesController < ApplicationController
    before_filter :set_share_links, if: -> { defined? @object }
  
    def index_pane_list
 -    %w(recent help)
 +    %w(repositories help)
    end
  
    def show_pane_list
    def show_commit
      @commit = params[:commit]
    end
 +
 +  def all_repos
 +    limit = params[:limit].andand.to_i || 100
 +    offset = params[:offset].andand.to_i || 0
 +    @filters = params[:filters] || []
 +
 +    if @filters.any?
 +      owner_filter = @filters.select do |attr, op, val|
 +        (attr == 'owner_uuid')
 +      end
 +    end
 +
 +    if !owner_filter.andand.any?
 +      filters = @filters + [["owner_uuid", "=", current_user.uuid]]
 +      my_repos = Repository.all.order("name ASC").limit(limit).offset(offset).filter(filters).results
 +    else      # done fetching all owned repositories
 +      my_repos = []
 +    end
 +
 +    if !owner_filter.andand.any?  # if this is next page request, the first page was still fetching "own" repos
 +      @filters = @filters.reject do |attr, op, val|
 +        (attr == 'owner_uuid') or
 +        (attr == 'name') or
 +        (attr == 'uuid')
 +      end
 +    end
 +
 +    filters = @filters + [["owner_uuid", "!=", current_user.uuid]]
 +    other_repos = Repository.all.order("name ASC").limit(limit).offset(offset).filter(filters).results
 +
 +    @objects = (my_repos + other_repos).first(limit)
 +  end
 +
 +  def find_objects_for_index
 +    return if !params[:partial]
 +
 +    all_repos
 +
 +    if @objects.any?
 +      @next_page_filters = next_page_filters('>=')
 +      @next_page_href = url_for(partial: :repositories_rows,
 +                                filters: @next_page_filters.to_json)
 +    else
 +      @next_page_href = nil
 +    end
 +  end
 +
 +  def next_page_href with_params={}
 +    @next_page_href
 +  end
 +
 +  def next_page_filters nextpage_operator
 +    next_page_filters = @filters.reject do |attr, op, val|
 +      (attr == 'owner_uuid') or
 +      (attr == 'name' and op == nextpage_operator) or
 +      (attr == 'uuid' and op == 'not in')
 +    end
 +
 +    if @objects.any?
 +      last_obj = @objects.last
 +      next_page_filters += [['name', nextpage_operator, last_obj.name]]
 +      next_page_filters += [['uuid', 'not in', [last_obj.uuid]]]
 +      # if not-owned, it means we are done with owned repos and fetching other repos
 +      next_page_filters += [['owner_uuid', '!=', last_obj.uuid]] if last_obj.owner_uuid != current_user.uuid
 +    end
 +
 +    next_page_filters
 +  end
  end
index d3b8bfe99cf0158fad01198c0e2e2a15b30d63a9,4a40f031203f7a1663d5d92f1617511cf8906f3a..2e3ced69a534485ca5d18df22b19ac53abeea793
@@@ -1,3 -1,7 +1,7 @@@
+ # 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]
      end
    end
  
 -  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 = {}
 -
 -    # 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
 -
 -    # 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 virtual_machines
      @my_vm_logins = {}
      Link.where(tail_uuid: @object.uuid,
index 0357866d44bcc392830c595c700b5b5656fa7c45,8073615c31cea407ecfcdd91fffc4fe9274bee91..3315027b3d9a1b485eaf0b578b86af1e1e68cb30
@@@ -1,3 -1,7 +1,7 @@@
+ <%# Copyright (C) The Arvados Authors. All rights reserved.
+ SPDX-License-Identifier: AGPL-3.0 %>
    <div id="wrapper" class="container-fluid">
      <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="navbar-header">
                      <i class="fa fa-lg fa-terminal fa-fw"></i> Virtual machines
                    <% end %>
                  </li>
 -                <li role="menuitem">
 -                  <%= link_to repositories_user_path(current_user), role: 'menu-item' do %>
 -                    <i class="fa fa-lg fa-code-fork fa-fw"></i> Repositories
 -                  <% end %>
 -                </li>
 +                <li role="menuitem"><a href="/repositories" role="menuitem"><i class="fa fa-lg fa-code-fork fa-fw"></i> Repositories </a></li>
                  <li role="menuitem"><a href="/current_token" role="menuitem"><i class="fa fa-lg fa-ticket fa-fw"></i> Current token</a></li>
                  <li role="menuitem">
                    <%= link_to ssh_keys_user_path(current_user), role: 'menu-item' do %>
index db74ec5c9fa2b4b4780374c39b34db93e64b5d06,8fe151b7536db7e35eaf85cdabae5992d324cd04..8fe151b7536db7e35eaf85cdabae5992d324cd04
@@@ -1,3 -1,7 +1,7 @@@
+ <%# Copyright (C) The Arvados Authors. All rights reserved.
+ SPDX-License-Identifier: AGPL-3.0 %>
  <%
     if current_user.uuid.ends_with?("-000000000000000")
       repo_prefix = ""
index 42ec96ff7eb90fb3eae5acced930a622be9fe67a,7980738b557d09abaf7f7f24caf553014f3bd845..5904fb29db8a513d05f0d9532cf666b650c1bb49
@@@ -1,10 -1,8 +1,14 @@@
 -<% if (example = @objects.select(&:push_url).first) %>
+ <%# Copyright (C) The Arvados Authors. All rights reserved.
+ SPDX-License-Identifier: AGPL-3.0 %>
 +<%
 +    filters = @filters + [["owner_uuid", "=", current_user.uuid]]
 +    example = Repository.all.order("name ASC").filter(filters).limit(1).results.first
 +    example = Repository.all.order("name ASC").limit(1).results.first if !example
 +%>
 +
 +<% if example %>
  
  <p>
  Sample git quick start:
index cb8916bc5810158b30b7101e2371578c274cafac,561723da540bfff1fcfb0aac80dfbe4faaf48042..99e7285b3ba150eaa05d0ba0adc5809a744c832c
@@@ -1,3 -1,7 +1,7 @@@
+ # Copyright (C) The Arvados Authors. All rights reserved.
+ #
+ # SPDX-License-Identifier: AGPL-3.0
  require 'test_helper'
  require 'helpers/repository_stub_helper'
  require 'helpers/share_object_helper'
@@@ -121,20 -125,4 +125,20 @@@ class RepositoriesControllerTest < Acti
        assert_select 'tr td', 'COPYING'
      end
    end
 +
 +  test "get repositories lists linked as well as owned repositories" do
 +    params = {
 +      partial: :repositories_rows,
 +      format: :json,
 +    }
 +    get :index, params, session_for(:active)
 +    assert_response :success
 +    repos = assigns(:objects)
 +    assert repos
 +    assert_not_empty repos, "my_repositories should not be empty"
 +    repo_uuids = repos.map(&:uuid)
 +    assert_includes repo_uuids, api_fixture('repositories')['repository2']['uuid']  # owned by active
 +    assert_includes repo_uuids, api_fixture('repositories')['repository4']['uuid']  # shared with active
 +    assert_includes repo_uuids, api_fixture('repositories')['arvados']['uuid']      # shared with all_users
 +  end
  end
index 56096d962a1a705f9f4da406d9d30d9dfe0492e9,ee64969f76461b618f93561e65e19d972ff79689..ce9282ff77d1e69450c864d8a09f70ec2d8637e7
@@@ -1,3 -1,7 +1,7 @@@
+ # Copyright (C) The Arvados Authors. All rights reserved.
+ #
+ # SPDX-License-Identifier: AGPL-3.0
  require 'test_helper'
  
  class UsersControllerTest < ActionController::TestCase
      assert_match /\/users\/welcome/, @response.redirect_url
    end
  
 -  test "show repositories with read, write, or manage permission" do
 -    get :repositories, {id: api_fixture("users")['active']['uuid']}, session_for(:active)
 -    assert_response :success
 -    repos = assigns(:my_repositories)
 -    assert repos
 -    assert_not_empty repos, "my_repositories should not be empty"
 -    editables = repos.collect { |r| !!assigns(:repo_writable)[r.uuid] }
 -    assert_includes editables, true, "should have a writable repository"
 -    assert_includes editables, false, "should have a readonly repository"
 -  end
 -
 -  test "show repositories lists linked as well as owned repositories" do
 -    get :repositories, {id: api_fixture("users")['active']['uuid']}, session_for(:active)
 -    assert_response :success
 -    repos = assigns(:my_repositories)
 -    assert repos
 -    assert_not_empty repos, "my_repositories should not be empty"
 -    repo_uuids = repos.map(&:uuid)
 -    assert_includes repo_uuids, api_fixture('repositories')['repository2']['uuid']  # owned by active
 -    assert_includes repo_uuids, api_fixture('repositories')['repository4']['uuid']  # shared with active
 -    assert_includes repo_uuids, api_fixture('repositories')['arvados']['uuid']      # shared with all_users
 -  end
 -
    test "request shell access" do
      user = api_fixture('users')['spectator']
  
index e777ed04d16a9b9801704e46c1c64d4f960dce8b,e777ebe784272a065513f5bf7aa708deae5cd755..7692d8e5dc1b0df9a50c1dae8d258eb298e36e33
@@@ -1,3 -1,7 +1,7 @@@
+ # Copyright (C) The Arvados Authors. All rights reserved.
+ #
+ # SPDX-License-Identifier: AGPL-3.0
  require 'integration_helper'
  
  class ApplicationLayoutTest < ActionDispatch::IntegrationTest
@@@ -52,7 -56,7 +56,7 @@@
  
              assert_selector "a[href=\"/projects/#{user['uuid']}\"]", text: 'Home project'
              assert_selector "a[href=\"/users/#{user['uuid']}/virtual_machines\"]", text: 'Virtual machines'
 -            assert_selector "a[href=\"/users/#{user['uuid']}/repositories\"]", text: 'Repositories'
 +            assert_selector "a[href=\"/repositories\"]", text: 'Repositories'
              assert_selector "a[href=\"/current_token\"]", text: 'Current token'
              assert_selector "a[href=\"/users/#{user['uuid']}/ssh_keys\"]", text: 'SSH keys'
  
    end
  
     [
 -    ['Repositories', nil, 's0uqq'],
 +    ['Repositories', nil, 'active/crunchdispatchtest'],
      ['Virtual machines', nil, 'testvm.shell'],
      ['SSH keys', nil, 'public_key'],
      ['Links', nil, 'link_class'],
index b2cd39957ac30bc84a4584c2f599c12217fcbb6c,75009f709c311ee3b65acf2c7af548a072ac2164..6a0e46e26aea5b6455fd400ac73d55596ab5895b
@@@ -1,3 -1,7 +1,7 @@@
+ # Copyright (C) The Arvados Authors. All rights reserved.
+ #
+ # SPDX-License-Identifier: AGPL-3.0
  require 'integration_helper'
  
  class UserSettingsMenuTest < ActionDispatch::IntegrationTest
    end
  
    test "verify repositories for active user" do
 -    visit page_with_token('active',"/users/#{api_fixture('users')['active']['uuid']}/repositories")
 +    visit page_with_token('active',"/repositories")
  
      repos = [[api_fixture('repositories')['foo'], true],
               [api_fixture('repositories')['repository3'], false],
          assert_text repo['name']
          assert_selector 'a', text:'Show'
          if owned
 -          assert_not_nil first('.fa-trash-o')
 +          assert_not_nil first('.glyphicon-trash')
          else
 -          assert_nil first('.fa-trash-o')
 +          assert_nil first('.glyphicon-trash')
          end
        end
      end
  
    [
      ['virtual_machines', nil, 'Host name', 'testvm2.shell'],
 -    ['repositories', 'Add new repository', 'It may take a minute or two before you can clone your new repository.', 'active/foo'],
 +    ['/repositories', 'Add new repository', 'It may take a minute or two before you can clone your new repository.', 'active/foo'],
      ['/current_token', nil, 'HISTIGNORE=$HISTIGNORE', 'ARVADOS_API_TOKEN=3kg6k6lzmp9kj5'],
      ['ssh_keys', 'Add new SSH key', 'Click here to learn about SSH keys in Arvados.', 'active'],
    ].each do |page_name, button_name, look_for, content|
      test "test user settings menu for page #{page_name}" do
 -      if page_name == '/current_token'
 +      if page_name == '/current_token' || page_name == '/repositories'
          visit page_with_token('active', page_name)
        else
          visit page_with_token('active', "/users/#{api_fixture('users')['active']['uuid']}/#{page_name}")
  
    [
      ['virtual_machines', 'You do not have access to any virtual machines.'],
 -    ['/repositories', api_fixture('repositories')['arvados']['uuid']],
 +    ['/repositories', api_fixture('repositories')['arvados']['name']],
      ['/current_token', 'HISTIGNORE=$HISTIGNORE'],
      ['ssh_keys', 'You have not yet set up an SSH public key for use with Arvados.'],
    ].each do |page_name, look_for|