[ARVADOS] updated: 310f6c81aad96a063f798d5940853dfad3409bba

git at public.curoverse.com git at public.curoverse.com
Fri Feb 5 18:26:26 EST 2016


Summary of changes:
 .../app/controllers/application_controller.rb      | 36 ++++++++++++----------
 .../views/application/_projects_tree_menu.html.erb |  2 +-
 .../test/controllers/projects_controller_test.rb   | 28 +++++++++++++++++
 3 files changed, 48 insertions(+), 18 deletions(-)

       via  310f6c81aad96a063f798d5940853dfad3409bba (commit)
      from  0da328cc74af2989f811d2970096bd5be5f9776b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 310f6c81aad96a063f798d5940853dfad3409bba
Author: radhika <radhika at curoverse.com>
Date:   Fri Feb 5 18:25:11 2016 -0500

    8183: add test to check build of my projects tree with the new method; update the method implementation
    to accommodate testing by make the page_size an argument.

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index ab018d7..696e821 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -89,7 +89,7 @@ class ApplicationController < ActionController::Base
     # exception here than in a template.)
     unless current_user.nil?
       begin
-        build_my_wanted_projects_tree
+        build_my_wanted_projects_tree current_user
       rescue ArvadosApiClient::ApiError
         # Fall back to the default-setting code later.
       end
@@ -833,19 +833,21 @@ class ApplicationController < ActionController::Base
   end
 
   # If there are more than 200 projects that are readable by the user,
-  # build the tree using only the top 200+ projects. That is:
-  # get toplevel projects under home, get subprojects under these
-  # projects, and so on until we hit the limit
-  def my_wanted_projects
+  # build the tree using only the top 200+ projects owned by the user.
+  # That is: get toplevel projects under home, get subprojects of
+  # these projects, and so on until we hit the limit
+  def my_wanted_projects page_size=100
     return @my_wanted_projects if @my_wanted_projects
 
-    all = Group.filter([['group_class','=','project']]).order('name').limit(100)
-    if all.items_available > 200
+    all = Group.filter([['group_class','=','project']]).order('name').limit(page_size)
+    if all.items_available > page_size*3
       @total_projects = all.items_available
       from_top = []
       uuids = [current_user.uuid]
-      while from_top.size <= 200
-        current_level = Group.filter([['group_class','=','project'], ['owner_uuid', 'in', uuids]]).order('name').limit(200)
+      while from_top.size <= page_size*2
+        current_level = Group.filter([['group_class','=','project'],
+                                      ['owner_uuid', 'in', uuids]])
+                             .order('name').limit(page_size*2)
         break if current_level.results.size == 0
         from_top.concat current_level.results
         uuids = current_level.results.collect { |x| x.uuid }
@@ -861,21 +863,21 @@ class ApplicationController < ActionController::Base
   end
 
   helper_method :my_wanted_projects_tree
-  def my_wanted_projects_tree
-    build_my_wanted_projects_tree
+  def my_wanted_projects_tree user, page_size=100
+    build_my_wanted_projects_tree user, page_size
     [@my_wanted_projects_tree, @total_projects]
   end
 
-  def build_my_wanted_projects_tree
+  def build_my_wanted_projects_tree user, page_size=100
     return @my_wanted_projects_tree if @my_wanted_projects_tree
 
-    parent_of = {current_user.uuid => 'me'}
-    my_wanted_projects.each do |ob|
+    parent_of = {user.uuid => 'me'}
+    my_wanted_projects(page_size).each do |ob|
       parent_of[ob.uuid] = ob.owner_uuid
     end
-    children_of = {false => [], 'me' => [current_user]}
-    my_wanted_projects.each do |ob|
-      if ob.owner_uuid != current_user.uuid and
+    children_of = {false => [], 'me' => [user]}
+    my_wanted_projects(page_size).each do |ob|
+      if ob.owner_uuid != user.uuid and
           not parent_of.has_key? ob.owner_uuid
         parent_of[ob.uuid] = false
       end
diff --git a/apps/workbench/app/views/application/_projects_tree_menu.html.erb b/apps/workbench/app/views/application/_projects_tree_menu.html.erb
index acb6030..10a951a 100644
--- a/apps/workbench/app/views/application/_projects_tree_menu.html.erb
+++ b/apps/workbench/app/views/application/_projects_tree_menu.html.erb
@@ -6,7 +6,7 @@
     <span style="padding-left: 0">Home</span>
   <% end %>
 </li>
-<% my_tree = my_wanted_projects_tree %>
+<% my_tree = my_wanted_projects_tree current_user %>
 <% my_tree[0].each do |pnode| %>
   <% next if pnode[:object].class != Group %>
   <li>
diff --git a/apps/workbench/test/controllers/projects_controller_test.rb b/apps/workbench/test/controllers/projects_controller_test.rb
index 8fa9fe9..32826db 100644
--- a/apps/workbench/test/controllers/projects_controller_test.rb
+++ b/apps/workbench/test/controllers/projects_controller_test.rb
@@ -418,4 +418,32 @@ class ProjectsControllerTest < ActionController::TestCase
     }, session_for(:active)
     assert_select "#projects-menu + ul li.divider ~ li a[href=/projects/#{project_uuid}]"
   end
+
+  [
+    ["active", 5, ["aproject", "asubproject"], "anonymously_accessible_project"],
+    ["admin", 5, ["anonymously_accessible_project", "subproject_in_anonymous_accessible_project"], "aproject"],
+  ].each do |user, page_size, tree_segment, unexpected|
+    test "build my projects tree for #{user} with page size #{page_size}" do
+      use_token user
+      ctrl = ProjectsController.new
+
+      current_user = User.find(api_fixture('users')[user]['uuid'])
+
+      my_tree = ctrl.send :my_wanted_projects_tree, current_user, 10
+
+      tree_segment_at_depth_1 = api_fixture('groups')[tree_segment[0]]
+      tree_segment_at_depth_2 = api_fixture('groups')[tree_segment[1]]
+
+      tree_nodes = {}
+      my_tree[0].each do |x|
+        tree_nodes[x[:object]['uuid']] = x[:depth]
+      end
+
+      assert_equal(1, tree_nodes[tree_segment_at_depth_1['uuid']])
+      assert_equal(2, tree_nodes[tree_segment_at_depth_2['uuid']])
+
+      unexpected_project = api_fixture('groups')[unexpected]
+      assert_nil(tree_nodes[unexpected_project['uuid']])
+    end
+  end
 end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list