[ARVADOS] created: 820ce7ad92cba95587800a275e14bbf24670898f

git at public.curoverse.com git at public.curoverse.com
Thu Feb 12 17:08:02 EST 2015


        at  820ce7ad92cba95587800a275e14bbf24670898f (commit)


commit 820ce7ad92cba95587800a275e14bbf24670898f
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Feb 12 17:09:17 2015 -0500

    5200: Enable anonymous file view/download.

diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index 613ed98..3ef4688 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -120,7 +120,9 @@ class CollectionsController < ApplicationController
     # purposes: it lets us return a useful status code for common errors, and
     # helps us figure out which token to provide to arv-get.
     coll = nil
-    tokens = [Thread.current[:arvados_api_token], params[:reader_token]].compact
+    tokens = [Thread.current[:arvados_api_token],
+              params[:reader_token],
+              (Rails.configuration.anonymous_user_token || nil)].compact
     usable_token = find_usable_token(tokens) do
       coll = Collection.find(params[:uuid])
     end
@@ -296,7 +298,9 @@ class CollectionsController < ApplicationController
     return nil
   end
 
-  def file_enumerator(opts)
+  # Note: several controller and integration tests rely on stubbing
+  # file_enumerator to return fake file content.
+  def file_enumerator opts
     FileStreamer.new opts
   end
 
diff --git a/apps/workbench/test/controllers/collections_controller_test.rb b/apps/workbench/test/controllers/collections_controller_test.rb
index ca5763b..45124f7 100644
--- a/apps/workbench/test/controllers/collections_controller_test.rb
+++ b/apps/workbench/test/controllers/collections_controller_test.rb
@@ -166,6 +166,18 @@ class CollectionsControllerTest < ActionController::TestCase
                  "failed to get a correct file from Keep")
   end
 
+  test 'anonymous download' do
+    Rails.configuration.anonymous_user_token =
+      api_fixture('api_client_authorizations')['anonymous']['api_token']
+    expect_content = stub_file_content
+    get :show_file, {
+      uuid: api_fixture('collections')['user_agreement_in_anonymously_accessible_project']['uuid'],
+      file: 'GNU_General_Public_License,_version_3.pdf',
+    }
+    assert_response :success
+    assert_equal expect_content, response.body
+  end
+
   test "can't get a file from Keep without permission" do
     params = collection_params(:foo_file, 'foo')
     sess = session_for(:spectator)
diff --git a/apps/workbench/test/integration/anonymous_access_test.rb b/apps/workbench/test/integration/anonymous_access_test.rb
index 2e63662..2e04dca 100644
--- a/apps/workbench/test/integration/anonymous_access_test.rb
+++ b/apps/workbench/test/integration/anonymous_access_test.rb
@@ -75,12 +75,13 @@ class AnonymousAccessTest < ActionDispatch::IntegrationTest
 
   test "anonymous user accesses data collections tab in shared project" do
     visit PUBLIC_PROJECT
+    collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
     assert_text 'GNU General Public License'
 
     assert_selector 'a', text: 'Data collections'
 
     # click on show collection
-    within first('tr[data-kind="arvados#collection"]') do
+    within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
       click_link 'Show'
     end
 
@@ -89,12 +90,22 @@ class AnonymousAccessTest < ActionDispatch::IntegrationTest
     assert_no_selector 'a', text: 'Upload'
     assert_no_selector 'button', 'Selection'
 
-    within ('#collection_files') do
-      assert_text 'GNU_General_Public_License,_version_3.pdf'
-      # how do i assert the view and download link existence?
+    within '#collection_files tr,li', text: 'GNU_General_Public_License,_version_3.pdf' do
+      find 'a[title~=View]'
+      find 'a[title~=Download]'
     end
   end
 
+  test 'view file' do
+    magic = rand(2**512).to_s 36
+    CollectionsController.any_instance.stubs(:file_enumerator).returns([magic])
+    collection = api_fixture('collections')['public_text_file']
+    visit '/collections/' + collection['uuid']
+    find('tr,li', text: 'Hello world.txt').
+      find('a[title~=View]').click
+    assert_text magic
+  end
+
   [
     'running_job',
     'completed_job',
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index 9ddc452..d5b78aa 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -155,6 +155,16 @@ user_agreement_in_anonymously_accessible_project:
   manifest_text: ". 6a4ff0499484c6c79c95cd8c566bd25f+249025 0:249025:GNU_General_Public_License,_version_3.pdf\n"
   name: GNU General Public License, version 3
 
+public_text_file:
+  uuid: zzzzz-4zz18-4en62shvi99lxd4
+  portable_data_hash: 55713e6a34081eb03609e7ad5fcad129+62
+  owner_uuid: zzzzz-j7d0g-zhxawtyetzwc5f0
+  created_at: 2015-02-12 16:58:03 -0500
+  modified_at: 2015-02-12 16:58:03 -0500
+  updated_at: 2015-02-12 16:58:03 -0500
+  manifest_text: ". f0ef7081e1539ac00ef5b761b4fb01b3+12 0:12:Hello\\040world.txt\n"
+  name: Hello world
+
 baz_collection_name_in_asubproject:
   uuid: zzzzz-4zz18-lsitwcf548ui4oe
   portable_data_hash: ea10d51bcf88862dbcc36eb292017dfd+45

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list