5989: API repo perms method always returns all repos. 5989-api-all-repos-permissions-wip
authorBrett Smith <brett@curoverse.com>
Sun, 5 Jul 2015 11:39:09 +0000 (07:39 -0400)
committerBrett Smith <brett@curoverse.com>
Sun, 5 Jul 2015 11:39:09 +0000 (07:39 -0400)
Previously the method would not return repositories that were not
accessible to any authorized key.  This change helps deployment tools
like update-gitolite do repository setup correctly with a single API
call.

services/api/app/controllers/arvados/v1/repositories_controller.rb
services/api/test/functional/arvados/v1/repositories_controller_test.rb

index b5123d97e3017af8b9c5fbcbf4e8d98a81a91436..fd6ab582071cc65f27ad0c943ad2b2d75ff03f6b 100644 (file)
@@ -4,14 +4,20 @@ class Arvados::V1::RepositoriesController < ApplicationController
   before_filter :admin_required, :only => :get_all_permissions
   def get_all_permissions
     @users = {}
-    User.includes(:authorized_keys).all.each do |u|
+    User.includes(:authorized_keys).find_each do |u|
       @users[u.uuid] = u
     end
     admins = @users.select { |k,v| v.is_admin }
     @user_aks = {}
     @repo_info = {}
-    @repos = Repository.includes(:permissions).all
-    @repos.each do |repo|
+    Repository.includes(:permissions).find_each do |repo|
+      @repo_info[repo.uuid] = {
+        uuid: repo.uuid,
+        name: repo.name,
+        push_url: repo.push_url,
+        fetch_url: repo.fetch_url,
+        user_permissions: {},
+      }
       gitolite_permissions = ''
       perms = []
       repo.permissions.each do |perm|
@@ -45,13 +51,6 @@ class Arvados::V1::RepositoriesController < ApplicationController
           }
         end || []
         if @user_aks[user_uuid].any?
-          @repo_info[repo.uuid] ||= {
-            uuid: repo.uuid,
-            name: repo.name,
-            push_url: repo.push_url,
-            fetch_url: repo.fetch_url,
-            user_permissions: {}
-          }
           ri = (@repo_info[repo.uuid][:user_permissions][user_uuid] ||= {})
           ri[perm[:name]] = true
         end
index 7f4ed8e4f16745a4146fe563b0af5e9b8dd880ab..7ba2183d3e7c62d540ace6721fe75a65efb00809 100644 (file)
@@ -88,6 +88,17 @@ class Arvados::V1::RepositoriesControllerTest < ActionController::TestCase
     end
   end
 
+  test "get_all_permissions lists repos with no authorized keys" do
+    authorize_with :admin
+    AuthorizedKey.destroy_all
+    get :get_all_permissions
+    assert_response :success
+    assert_equal(Repository.count, json_response["repositories"].size)
+    assert(json_response["repositories"].any? do |repo|
+             repo["user_permissions"].empty?
+           end, "test is invalid - all repositories have authorized keys")
+  end
+
   test "default index includes fetch_url" do
     authorize_with :active
     get(:index)