6057: if /projects/public is accessed when anonymous config is not enabled, show...
authorradhika <radhika@curoverse.com>
Tue, 26 May 2015 22:54:13 +0000 (18:54 -0400)
committerradhika <radhika@curoverse.com>
Tue, 26 May 2015 22:54:13 +0000 (18:54 -0400)
apps/workbench/app/controllers/projects_controller.rb
apps/workbench/app/views/projects/public.html.erb [moved from apps/workbench/app/views/projects/public_projects.html.erb with 71% similarity]
apps/workbench/test/controllers/projects_controller_test.rb
apps/workbench/test/integration/anonymous_access_test.rb
apps/workbench/test/integration/application_layout_test.rb
apps/workbench/test/integration/projects_test.rb

index dec26c338703a193b48c2057c0036425c59a2a6f..c4600f2c0f7627a88fa6e8235d04077678afafda 100644 (file)
@@ -309,13 +309,9 @@ class ProjectsController < ApplicationController
   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'
+    return render_not_found if not Rails.configuration.anonymous_user_token
+    @objects = using_specific_api_token Rails.configuration.anonymous_user_token do
+      Group.where(group_class: 'project').order("updated_at DESC")
     end
   end
 end
similarity index 71%
rename from apps/workbench/app/views/projects/public_projects.html.erb
rename to apps/workbench/app/views/projects/public.html.erb
index fdae70e0707f76328d7c34037f77f65da895bbe1..9fc9759717d9c6788c5646d276c9a9fc701f4843 100644 (file)
@@ -1,4 +1,4 @@
-<table class="table arv-public-projects" style="width: 100%;">
+<table class="table">
   <colgroup>
     <col width="25%" />
     <col width="75%" />
@@ -6,21 +6,24 @@
   <thead>
     <tr class="contain-align-left">
       <th>
-       Name
-      </th><th>
-       Description
+        Name
+      </th>
+      <th>
+        Description
+      </th>
     </tr>
   </thead>
 
-  <% @public_projects.each do |p| %>
+  <tbody>
+  <% @objects.each do |p| %>
     <tr>
       <td style="word-break:break-all;">
         <%= link_to_if_arvados_object p, {friendly_name: true} %>
-      </div></td>
+      </td>
       <td style="word-break:break-all;">
         <%= render_attribute_as_textile(p, "description", p.description, true) %>
-      </div></td>
+      </td>
     </tr>
   <% end %>
+  </tbody>
 </table>
-
index 119ed8c8f42c5d4e2129e4257b19509b592df3d5..b050383b522529971840c817ba3f469f6137a734 100644 (file)
@@ -248,4 +248,42 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_response :redirect
     assert_match /\/users\/welcome/, @response.redirect_url
   end
+
+  [
+    nil,
+    :active,
+  ].each do |user|
+    test "visit public projects page when anon config is enabled, as user #{user}, and expect page" do
+      Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+
+      if user
+        get :public, {}, session_for(user)
+      else
+        get :public
+      end
+
+      assert_response :success
+      assert_not_nil assigns(:objects)
+      project_names = assigns(:objects).collect(&:name)
+      assert_operator 0, :<, project_names.length
+      assert project_names.include?('Unrestricted public data')
+      assert !project_names.include?('A Project')
+    end
+  end
+
+  [
+    nil,
+    :active,
+  ].each do |user|
+    test "visit public projects page when anon config is not enabled, as user #{user}, and expect no such page" do
+      if user
+        get :public, {}, session_for(user)
+        assert_response 404
+      else
+        get :public
+        assert_response :redirect
+        assert_match /\/users\/welcome/, @response.redirect_url
+      end
+    end
+  end
 end
index a4155fbdb8d41236fd95db5bc9dc8e0697555add..8ac3a56cb42abd1983e15d621541c3cb158df85d 100644 (file)
@@ -18,6 +18,10 @@ class AnonymousAccessTest < ActionDispatch::IntegrationTest
       if user['is_active']
         assert_text 'Unrestricted public data'
         assert_selector 'a', text: 'Projects'
+        page.find("#projects-menu").click
+        assert_selector 'a', text: 'Add a new project'
+        assert_selector 'a', text: 'Browse public projects'
+        assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
       else
         assert_text 'indicate that you have read and accepted the user agreement'
       end
index b6a501f924e690012d2b3f96a646ccb857c743a3..f8984f0db38aba11455dc118e74785afc72fa850 100644 (file)
@@ -24,6 +24,8 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
       else
         assert page.has_link?("Projects"), 'Not found link - Projects'
         page.find("#projects-menu").click
+        assert_selector 'a', text: 'Add a new project'
+        assert_no_selector 'a', text: 'Browse public projects'  # anonymous config is not enabled by default
         assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
       end
     elsif invited
index 84237ae14eb8853a234d4fb8eb913ee14931f3c3..9c2842f1c2c6d5ba62d07413d28ebecb415cf054 100644 (file)
@@ -830,42 +830,4 @@ 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