Merge branch 'master' into 6466-disable-public-projects
authorManoj <jonam33@gmail.com>
Tue, 7 Jul 2015 13:07:33 +0000 (09:07 -0400)
committerManoj <jonam33@gmail.com>
Tue, 7 Jul 2015 13:07:33 +0000 (09:07 -0400)
apps/workbench/app/controllers/projects_controller.rb
apps/workbench/app/views/layouts/body.html.erb
apps/workbench/config/application.default.yml
apps/workbench/test/controllers/projects_controller_test.rb

index 4087b59fdbeede3f399a965a9e73360626203268..44c85185c7c316a3f7d5efbb1c5566016b14348d 100644 (file)
@@ -319,7 +319,7 @@ class ProjectsController < ApplicationController
   end
 
   def public  # Yes 'public' is the name of the action for public projects
-    return render_not_found if not Rails.configuration.anonymous_user_token
+    return render_not_found if not Rails.configuration.anonymous_user_token or not Rails.configuration.enable_public_projects_page
     @objects = using_specific_api_token Rails.configuration.anonymous_user_token do
       Group.where(group_class: 'project').order("updated_at DESC")
     end
index 54e662605a8314e245ae539fbcd5d6b494676b87..0f90c416f0c929c660dd97616dd54db32a2f4750 100644 (file)
               </li>
             <% end %>
           <% else %>
-            <% if Rails.configuration.anonymous_user_token %>
+            <% if Rails.configuration.anonymous_user_token and Rails.configuration.enable_public_projects_page %>
               <li><%= link_to 'Browse public projects', "/projects/public" %></li>
             <% end %>
             <li class="dropdown hover-dropdown login-menu">
               <span class="caret"></span>
             </a>
             <ul class="dropdown-menu" style="min-width: 20em" role="menu">
-              <% if Rails.configuration.anonymous_user_token %>
+              <% if Rails.configuration.anonymous_user_token and Rails.configuration.enable_public_projects_page %>
                 <li><%= link_to 'Browse public projects', "/projects/public", class: 'btn btn-xs btn-default pull-right' %></li>
               <% end %>
               <li>
index cae7b19d8d03562aa1d2e2c80116f4b5e1ff6074..4ade8b49b6b86767482e29f6b99bf739bfddaed6 100644 (file)
@@ -209,5 +209,8 @@ common:
   # in the directory where your API server is running.
   anonymous_user_token: false
 
+  # when anonymous_user_token is configured, show public projects page
+  enable_public_projects_page: true
+
   # Ask Arvados API server to compress its response payloads.
   api_response_compression: true
index d7fb8f2a0081a4ec13fc2a5a2747460d1e1cb1b6..62a93a1308b3755ac64e0f6c49b348b5354957f2 100644 (file)
@@ -267,6 +267,7 @@ class ProjectsControllerTest < ActionController::TestCase
       project_names = assigns(:objects).collect(&:name)
       assert_includes project_names, 'Unrestricted public data'
       assert_not_includes project_names, 'A Project'
+      refute_empty css_select('[href="/projects/public"]')
     end
   end
 
@@ -275,9 +276,34 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_response 404
   end
 
+  test "visit public projects page when anon config is enabled but public projects page is disabled as active user and expect 404" do
+    Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+    Rails.configuration.enable_public_projects_page = false
+    get :public, {}, session_for(:active)
+    assert_response 404
+  end
+
   test "visit public projects page when anon config is not enabled as anonymous and expect login page" do
     get :public
     assert_response :redirect
     assert_match /\/users\/welcome/, @response.redirect_url
+    assert_empty css_select('[href="/projects/public"]')
+  end
+
+  test "visit public projects page when anon config is enabled and public projects page is disabled and expect login page" do
+    Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+    Rails.configuration.enable_public_projects_page = false
+    get :index
+    assert_response :redirect
+    assert_match /\/users\/welcome/, @response.redirect_url
+    assert_empty css_select('[href="/projects/public"]')
+  end
+
+  test "visit public projects page when anon config is not enabled and public projects page is enabled and expect login page" do
+    Rails.configuration.enable_public_projects_page = true
+    get :index
+    assert_response :redirect
+    assert_match /\/users\/welcome/, @response.redirect_url
+    assert_empty css_select('[href="/projects/public"]')
   end
 end