3686: when a repository is manageable by a user, make repository name a link in manag...
authorRadhika Chippada <radhika@curoverse.com>
Sat, 24 Jan 2015 18:07:42 +0000 (13:07 -0500)
committerRadhika Chippada <radhika@curoverse.com>
Sat, 24 Jan 2015 18:07:42 +0000 (13:07 -0500)
apps/workbench/app/controllers/repositories_controller.rb
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/users/_manage_repositories.html.erb
apps/workbench/test/integration/repositories_test.rb
apps/workbench/test/integration/user_manage_account_test.rb

index 3678ceb4fe265d7d42242f7c36a22d2942b312fa..d32c92a1e71fde336c99b52b990b86f019662af8 100644 (file)
@@ -11,7 +11,9 @@ class RepositoriesController < ApplicationController
       panes.insert(panes.length-1, panes.delete_at(panes.index('Advanced'))) if panes.index('Advanced')
       panes
     else
-      super
+      panes = super
     end
+    panes.delete('Attributes') if !current_user.is_admin
+    panes
   end
 end
index f3f36e6b29e123b063f31920e66e53527778e957..68b082bc03975781b4a89cce32b0adfc1c942768 100644 (file)
@@ -244,7 +244,7 @@ class UsersController < ApplicationController
     @repo_writable = {}
     repo_links.each do |link|
       if link.name.in? ['can_write', 'can_manage']
-        @repo_writable[link.head_uuid] = true
+        @repo_writable[link.head_uuid] = link.name
       end
     end
 
index d20498f8c02bc1a932286d9e2f7bb73e690c8fec..1956016d9fce86001b080da4cf2db67608463eff 100644 (file)
           <% writable = @repo_writable[repo.uuid] %>
           <tr>
             <td style="word-break:break-all;">
-              <%= repo[:name] %>
+              <% if writable == 'can_manage' %>
+                <%= link_to raw("#{repo[:name]}"), "/repositories/#{repo[:uuid]}" %>
+              <% else %>
+                <%= repo[:name] %>
+              <% end %>
             </td>
             <td>
               <%= writable ? 'writable' : 'read-only' %>
index 1e1a118a7a5ec6d8e9610c3d244ddd9a7bafd0dd..4c62eea55a879d3f8b76019dba86cdbdd5f5f779 100644 (file)
@@ -15,7 +15,8 @@ class RepositoriesTest < ActionDispatch::IntegrationTest
     test "#{user} can manage sharing for another user" do
       add_user = api_fixture('users')['future_project_user']
       new_name = ["first_name", "last_name"].map { |k| add_user[k] }.join(" ")
-      show_object_using(user, 'repositories', 'foo', 'push_url')
+      show_object_using(user, 'repositories', 'foo',
+                        api_fixture('repositories')['foo']['name'])
       click_on "Sharing"
       add_share_and_check("users", new_name, add_user)
       modify_share_and_check(new_name)
@@ -28,7 +29,8 @@ class RepositoriesTest < ActionDispatch::IntegrationTest
   ].each do |user|
     test "#{user} can manage sharing for another group" do
       new_name = api_fixture('groups')['future_project_viewing_group']['name']
-      show_object_using(user, 'repositories', 'foo', 'push_url')
+      show_object_using(user, 'repositories', 'foo',
+                        api_fixture('repositories')['foo']['name'])
       click_on "Sharing"
       add_share_and_check("groups", new_name)
       modify_share_and_check(new_name)
@@ -36,8 +38,27 @@ class RepositoriesTest < ActionDispatch::IntegrationTest
   end
 
   test "spectator does not see repository sharing tab" do
-    show_object_using("spectator", 'repositories', 'arvados', 'push_url')
+    show_object_using('spectator', 'repositories', 'arvados',
+                      api_fixture('repositories')['arvados']['name'])
     assert(page.has_no_link?("Sharing"),
            "read-only repository user sees sharing tab")
   end
+
+  [
+    'active',
+    'admin',
+  ].each do |user_key|
+    test "#{user_key} user is presented with attributes tab" do
+      user = api_fixture('users')[user_key]
+      show_object_using(user_key, 'repositories', 'foo',
+                        api_fixture('repositories')['foo']['name'])
+      if user['is_admin']
+        assert_selector 'li', text: 'Attributes'
+      else
+        assert_no_selector 'li', text: 'Attributes'
+      end
+      assert_selector 'li', text: 'Advanced'
+    end
+  end
+
 end
index fae7e62e728d12212dd4f2c3cb69dcbe420f83d2..c8149a77ae94791006e429dd80a69644fec0edfa 100644 (file)
@@ -22,6 +22,7 @@ class UserManageAccountTest < ActionDispatch::IntegrationTest
       assert page.has_text?('Current Token'), 'No text - Current Token'
       assert page.has_text?('The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'), 'No text - Arvados API token'
       add_and_verify_ssh_key
+      verify_repositories user
     else  # inactive user
       within('.navbar-fixed-top') do
         find('a', text: "#{user['email']}").click
@@ -60,6 +61,40 @@ class UserManageAccountTest < ActionDispatch::IntegrationTest
       assert page.has_text?('added_in_test'), 'No text - added_in_test'
   end
 
+  def verify_repositories user
+    Thread.current[:arvados_api_token] = @@API_AUTHS["admin"]['api_token']
+    repo_links = Link.filter([['head_uuid', 'is_a', 'arvados#repository'],
+                              ['tail_uuid', '=', user['uuid']],
+                              ['link_class', '=', 'permission']])
+    repos = Repository.where uuid: repo_links.collect(&:head_uuid)
+    repositories = {}
+    repos.each do |repo|
+      repositories[repo.uuid] = repo
+    end
+
+    repo_writables = {}
+    repo_links.each do |link|
+      if link.name.in? ['can_write','can_manage']
+        repo_writables[link.head_uuid] = link.name
+      end
+    end
+
+    repo_links.each do |link|
+      if repo_writables[link.head_uuid] == 'can_manage'
+        assert_selector 'a', text: repositories[link.head_uuid]['name']
+        within('tr', text: repositories[link.head_uuid]['fetch_url']) do
+          assert_text 'writable'
+        end
+      else
+        assert_no_selector 'a', text: repositories[link.head_uuid]['name']
+        assert_text repositories[link.head_uuid]['name']
+        within('tr', text: repositories[link.head_uuid]['fetch_url']) do
+          assert_text 'read-only'
+        end
+      end
+    end
+  end
+
   [
     ['inactive', api_fixture('users')['inactive']],
     ['inactive_uninvited', api_fixture('users')['inactive_uninvited']],