[ARVADOS] created: 4b056c34fa04a3b611a0cf5f70e9b8d59b7ef632

Git user git at public.curoverse.com
Wed Jun 14 10:21:26 EDT 2017


        at  4b056c34fa04a3b611a0cf5f70e9b8d59b7ef632 (commit)


commit 4b056c34fa04a3b611a0cf5f70e9b8d59b7ef632
Author: radhika <radhika at curoverse.com>
Date:   Wed Jun 14 10:13:23 2017 -0400

    11060: show all repositories that are accessible to the user in <user_uuid>/repositories page
    
    Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>

diff --git a/apps/workbench/app/controllers/users_controller.rb b/apps/workbench/app/controllers/users_controller.rb
index 1a1c5f8..d3acf58 100644
--- a/apps/workbench/app/controllers/users_controller.rb
+++ b/apps/workbench/app/controllers/users_controller.rb
@@ -257,28 +257,40 @@ class UsersController < ApplicationController
   end
 
   def repositories
+    # all repositories accessible by current user
+    all_repositories = Hash[Repository.where(authorized_user_uuid: current_user.uuid).collect {|repo| [repo.uuid, repo]}]
+
+    # repositories shared with the user
     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 }
+    @my_repositories = [] # we want them ordered as owned, manageable, 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
 
-    @repo_writable = {}
+    # shared and either writable or manageable
+    handled = @my_repositories.map(&:uuid)
     repo_links.each do |link|
       if link.name.in? ['can_write', 'can_manage']
         @repo_writable[link.head_uuid] = link.name
+        @my_repositories << all_repositories[link.head_uuid] if !link.head_uuid.in?(handled)
       end
     end
 
-    owned_repositories.each do |repo|
-      @repo_writable[repo.uuid] = 'can_manage'
+    # rest of the repos
+    handled = @my_repositories.map(&:uuid)
+    all_repositories.each do |_, repo|
+      @my_repositories << repo if !repo.uuid.in?(handled)
     end
   end
 
diff --git a/apps/workbench/app/views/users/_repositories.html.erb b/apps/workbench/app/views/users/_repositories.html.erb
index d409b8c..0ac8405 100644
--- a/apps/workbench/app/views/users/_repositories.html.erb
+++ b/apps/workbench/app/views/users/_repositories.html.erb
@@ -12,54 +12,60 @@
     </h4>
   </div>
 
-<div id="manage_repositories" class="panel-body">
-  <p>
-    For more information see <%= link_to raw('Writing a pipeline'),
-    "#{Rails.configuration.arvados_docsite}/user/tutorials/tutorial-firstscript.html", target: "_blank"%>.
-  </p>
+  <div id="manage_repositories" class="panel-body">
+    <p>
+      When you are using an Arvados virtual machine, you should clone the https:// URLs. This will authenticate automatically using your API token.
+    </p>
+    <p>
+      In order to clone git repositories using SSH, <%= link_to ssh_keys_user_path(current_user) do%> add an SSH key to your account<%end%> and clone the git@ URLs.
+    </p>
+    <p>
+      For more information see <%= link_to raw('Writing a pipeline'),
+      "#{Rails.configuration.arvados_docsite}/user/tutorials/tutorial-firstscript.html", target: "_blank"%>.
+    </p>
 
-  <% if !@my_repositories.any? %>
-    You do not seem to have access to any repositories. If you would like to request access, please contact your system admin.
-  <% else %>
-    <table class="table repositories-table">
-      <colgroup>
-        <col style="width: 30%" />
-        <col style="width: 10%" />
-        <col style="width: 60%" />
-      </colgroup>
-      <thead>
-        <tr>
-          <th> Name </th>
-          <th> Read/Write </th>
-          <th> URL </th>
-          <th> </th>
-        </tr>
-      </thead>
-      <tbody>
-        <% @my_repositories.andand.each do |repo| %>
-          <% writable = @repo_writable[repo.uuid] %>
+    <% if !@my_repositories.any? %>
+      You do not seem to have access to any repositories. If you would like to request access, please contact your system admin.
+    <% else %>
+      <table class="table repositories-table">
+        <colgroup>
+          <col style="width: 5%" />
+          <col style="width: 30%" />
+          <col style="width: 60%" />
+          <col style="width: 5%" />
+        </colgroup>
+        <thead>
           <tr>
-            <td style="word-break:break-all;">
-              <%= repo[:name] %>
-            </td>
-            <td>
-              <%= writable ? 'writable' : 'read-only' %>
-            </td>
-            <td style="word-break:break-all;">
-              <code><%= repo.http_fetch_url %></code><br/>
-              <code><%= writable ? repo.push_url : repo.fetch_url %></code>
-            </td>
-            <td>
-              <% if writable == 'can_manage' %>
-                <%= link_to "Share", "/repositories/#{repo[:uuid]}#Sharing" %>
-              <% end %>
-            </td>
+            <th></th>
+            <th> Name </th>
+            <th> URL </th>
+            <th></th>
           </tr>
-        <% end %>
-      </tbody>
-    </table>
-  <% end %>
-</div>
+        </thead>
+        <tbody>
+          <% @my_repositories.andand.each do |repo| %>
+            <tr>
+              <td>
+                <%= render :partial => "show_object_button", :locals => {object: repo, size: 'xs' } %>
+              </td>
+              <td style="word-break:break-all;">
+                <%= repo[:name] %>
+              </td>
+              <td style="word-break:break-all;">
+                <code><%= repo.http_fetch_url %></code><br/>
+                <code><%= @repo_writable[repo.uuid] ? repo.push_url : repo.fetch_url %></code>
+              </td>
+              <td>
+                <% if repo.editable? %>
+                    <%= link_to(repository_path(id: repo.uuid), method: :delete, class: 'btn btn-sm', data: {confirm: "Really delete repositories?"}) do %>
+                        <i class="fa fa-fw fa-trash-o"></i>
+                    <% end %>
+                <% end %>
+              </td>
+            </tr>
+          <% end %>
+        </tbody>
+      </table>
+    <% end %>
+  </div>
 </div>
-  <p>When you are using an Arvados virtual machine, you should clone the https:// URLs. This will authenticate automatically using your API token.</p>
-  <p>In order to clone git repositories using SSH, <%= link_to ssh_keys_user_path(current_user) do%> add an SSH key to your account<%end%> and clone the git@ URLs.</p>
diff --git a/apps/workbench/test/integration/user_settings_menu_test.rb b/apps/workbench/test/integration/user_settings_menu_test.rb
index 147b487..e1391de 100644
--- a/apps/workbench/test/integration/user_settings_menu_test.rb
+++ b/apps/workbench/test/integration/user_settings_menu_test.rb
@@ -111,23 +111,20 @@ class UserSettingsMenuTest < ActionDispatch::IntegrationTest
 
   test "verify repositories for active user" do
     visit page_with_token('active',"/users/#{api_fixture('users')['active']['uuid']}/repositories")
-    repos = [[api_fixture('repositories')['foo'], true, true],
-             [api_fixture('repositories')['repository3'], false, false],
-             [api_fixture('repositories')['repository4'], true, false]]
 
-    repos.each do |(repo, writable, sharable)|
+    repos = [[api_fixture('repositories')['foo'], true],
+             [api_fixture('repositories')['repository3'], false],
+             [api_fixture('repositories')['repository4'], false],
+             [api_fixture('repositories')['arvados'], false]]
+
+    repos.each do |(repo, owned)|
       within('tr', text: repo['name']+'.git') do
-        if sharable
-          assert_selector 'a', text:'Share'
-          assert_text 'writable'
+        assert_text repo['name']
+        assert_selector 'a', text:'Show'
+        if owned
+          assert_not_nil first('.fa-trash-o')
         else
-          assert_text repo['name']
-          assert_no_selector 'a', text:'Share'
-          if writable
-            assert_text 'writable'
-          else
-            assert_text 'read-only'
-          end
+          assert_nil first('.fa-trash-o')
         end
       end
     end
@@ -215,18 +212,21 @@ class UserSettingsMenuTest < ActionDispatch::IntegrationTest
 
   [
     ['virtual_machines', 'You do not have access to any virtual machines.'],
-    ['repositories', 'You do not seem to have access to any repositories.'],
+    ['/repositories', api_fixture('repositories')['arvados']['uuid']],
     ['/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|
     test "test user settings menu for page #{page_name} when page is empty" do
-      if page_name == '/current_token'
+      if page_name == '/current_token' || page_name == '/repositories'
         visit page_with_token('user1_with_load', page_name)
       else
         visit page_with_token('admin', "/users/#{api_fixture('users')['user1_with_load']['uuid']}/#{page_name}")
       end
 
-     assert page.has_text? look_for
+      assert page.has_text? look_for
+      if page_name == '/repositories'
+        assert_equal 1, page.all('a[data-original-title="show repository"]').count
+      end
     end
   end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list