6057: add projects/public page, which lists publicly accessible projects.
authorradhika <radhika@curoverse.com>
Fri, 22 May 2015 20:39:57 +0000 (16:39 -0400)
committerradhika <radhika@curoverse.com>
Fri, 22 May 2015 20:39:57 +0000 (16:39 -0400)
apps/workbench/app/controllers/projects_controller.rb
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/app/views/projects/public_projects.html.erb [new file with mode: 0644]
apps/workbench/config/routes.rb
apps/workbench/test/integration/anonymous_access_test.rb
apps/workbench/test/integration/projects_test.rb

index b43ad65e9134cb1ce69af4e603850b4a60a5b823..dec26c338703a193b48c2057c0036425c59a2a6f 100644 (file)
@@ -1,8 +1,8 @@
 class ProjectsController < ApplicationController
-  before_filter :set_share_links, if: -> { defined? @object }
+  before_filter :set_share_links, if: -> { defined? @object and @object}
   skip_around_filter :require_thread_api_token, if: proc { |ctrl|
     Rails.configuration.anonymous_user_token and
-    %w(show tab_counts).include? ctrl.action_name
+    %w(show tab_counts public).include? ctrl.action_name
   }
 
   def model_class
@@ -307,4 +307,15 @@ class ProjectsController < ApplicationController
     end
     objects_and_names
   end
+
+  def public  # Yes 'public' is the name of the action for public projects
+    if Rails.configuration.anonymous_user_token
+      @public_projects = using_specific_api_token Rails.configuration.anonymous_user_token do
+        Group.where(group_class: 'project').order("updated_at DESC")
+      end
+      render 'public_projects'
+    else
+      redirect_to '/projects'
+    end
+  end
 end
index 9f253a47a5915848f52e6023c0727279db940c62..6c23035adc5fddd5ac351560cc58a8252c8ddce4 100644 (file)
               </li>
             <% end %>
           <% else %>
+            <% if Rails.configuration.anonymous_user_token %>
+              <li><%= link_to raw('Browse public projects'), "/projects/public" %></li>
+            <% end %>
             <li class="dropdown hover-dropdown login-menu">
               <a href="<%= arvados_api_client.arvados_login_url(return_to: root_url) %>">Log in</a>
               <ul class="dropdown-menu">
               <span class="caret"></span>
             </a>
             <ul class="dropdown-menu" style="min-width: 20em" role="menu">
+              <% if Rails.configuration.anonymous_user_token %>
+                <li><%= link_to raw('Browse public projects'), "/projects/public", class: 'btn btn-xs btn-default pull-right' %></li>
+              <% end %>
               <li>
                 <%= link_to projects_path(options: {ensure_unique_name: true}), method: :post, class: 'btn btn-xs btn-default pull-right' do %>
                   <i class="fa fa-plus"></i> Add a new project
diff --git a/apps/workbench/app/views/projects/public_projects.html.erb b/apps/workbench/app/views/projects/public_projects.html.erb
new file mode 100644 (file)
index 0000000..fdae70e
--- /dev/null
@@ -0,0 +1,26 @@
+<table class="table arv-public-projects" style="width: 100%;">
+  <colgroup>
+    <col width="25%" />
+    <col width="75%" />
+  </colgroup>
+  <thead>
+    <tr class="contain-align-left">
+      <th>
+       Name
+      </th><th>
+       Description
+    </tr>
+  </thead>
+
+  <% @public_projects.each do |p| %>
+    <tr>
+      <td style="word-break:break-all;">
+        <%= link_to_if_arvados_object p, {friendly_name: true} %>
+      </div></td>
+      <td style="word-break:break-all;">
+        <%= render_attribute_as_textile(p, "description", p.description, true) %>
+      </div></td>
+    </tr>
+  <% end %>
+</table>
+
index 44d7ded6c10c70cd1f7f72f627ce619011828ec5..b2d48ffcc8cba5f05d994cac6442c7cfd4507878 100644 (file)
@@ -82,7 +82,9 @@ ArvadosWorkbench::Application.routes.draw do
     get 'choose', on: :collection
     post 'share_with', on: :member
     get 'tab_counts', on: :member
+    get 'public', on: :collection
   end
+
   resources :search do
     get 'choose', :on => :collection
   end
index 1e486d8fef662ea241998ae835c4a2360e16b7bf..a4155fbdb8d41236fd95db5bc9dc8e0697555add 100644 (file)
@@ -35,6 +35,7 @@ class AnonymousAccessTest < ActionDispatch::IntegrationTest
         assert_text Rails.configuration.site_name.downcase
         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
         assert_selector 'a', text: 'Log in'
+        assert_selector 'a', text: 'Browse public projects'
       end
     end
   end
index 9c2842f1c2c6d5ba62d07413d28ebecb415cf054..84237ae14eb8853a234d4fb8eb913ee14931f3c3 100644 (file)
@@ -830,4 +830,42 @@ class ProjectsTest < ActionDispatch::IntegrationTest
       assert_no_selector 'li.disabled', text: 'Copy selected'
     end
   end
+
+  [
+    [true, nil, true],
+    [true, 'active', true],
+    [false, nil, false],
+    [false, 'active', false],
+  ].each do |anon_config, user, expect_page|
+    test "visit public_projects page when anon config enabled #{anon_config}, as user #{user}, and expect page #{expect_page}" do
+      Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token'] if anon_config
+
+      if user
+        visit page_with_token user, '/projects/public'
+      else
+        visit '/public_projects'
+      end
+
+      # verify public projects are listed
+      assert_selector 'a', 'Unrestricted public data'
+
+      if user
+        find("#projects-menu").click
+        if anon_config
+          assert_selector 'a', text: 'Browse public projects'
+        else
+          assert_no_selector 'a', text: 'Browse public projects'
+        end
+      else
+        within('.navbar-fixed-top') do
+          assert_selector 'a', text: 'Log in'
+          if anon_config
+            assert_selector 'a', text: 'Browse public projects'
+          else
+            assert_no_selector 'a', text: 'Browse public projects'
+          end
+        end
+      end
+    end
+  end
 end