8286: check if project is starred only when current_user is not null (anonymous user...
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index 9438da3fb699eb741fa352d3df848a11d7b870ad..1fc15807c9568e05876a349cc38ed152887dc943 100644 (file)
@@ -94,7 +94,10 @@ class ApplicationController < ActionController::Base
         # Fall back to the default-setting code later.
       end
     end
+    @starred_projects ||= []
     @my_wanted_projects_tree ||= []
+    @my_project_tree ||= []
+    @shared_project_tree ||= []
     render_error(err_opts)
   end
 
@@ -443,6 +446,15 @@ class ApplicationController < ActionController::Base
     end
   end
 
+  helper_method :is_starred
+  def is_starred
+    links = Link.where(tail_uuid: current_user.uuid,
+               head_uuid: @object.uuid,
+               link_class: 'star')
+
+    return links.andand.any?
+  end
+
   protected
 
   helper_method :strip_token_from_path
@@ -832,6 +844,17 @@ class ApplicationController < ActionController::Base
     {collections: c, owners: own}
   end
 
+  helper_method :my_starred_projects
+  def my_starred_projects user
+    return if @starred_projects
+    links = Link.filter([['tail_uuid', '=', user.uuid],
+                         ['link_class', '=', 'star'],
+                         ['head_uuid', 'is_a', 'arvados#group']]).select(%w(head_uuid))
+    uuids =links.collect { |x| x.head_uuid }
+    starred_projects = Group.filter([['uuid', 'in', uuids]]).order('name')
+    @starred_projects = starred_projects.results
+  end
+
   # If there are more than 200 projects that are readable by the user,
   # build the tree using only the top 200+ projects owned by the user,
   # from the top three levels.