[ARVADOS] created: 9f34059300412b551a21bb8ef8bae1ffa28cf9dc

git at public.curoverse.com git at public.curoverse.com
Tue Sep 16 15:15:55 EDT 2014


        at  9f34059300412b551a21bb8ef8bae1ffa28cf9dc (commit)


commit 9f34059300412b551a21bb8ef8bae1ffa28cf9dc
Author: Tim Pierce <twp at curoverse.com>
Date:   Tue Sep 16 00:57:44 2014 -0400

    3411: set default collection expiration policy
    
    * Added default_scope to Collections restricting them to collections that
      have not yet expired
    
    * Added a default_trash_lifetime setting in application.default.yml,
      exposed in the discovery doc setting 'defaultTrashLifetime' (default:
      2 weeks)
    
    * Added test fixtures to exercise fetching expired collections and
      collections that expire in the future.

diff --git a/services/api/app/controllers/arvados/v1/schema_controller.rb b/services/api/app/controllers/arvados/v1/schema_controller.rb
index f856dd6..c5b2bcf 100644
--- a/services/api/app/controllers/arvados/v1/schema_controller.rb
+++ b/services/api/app/controllers/arvados/v1/schema_controller.rb
@@ -26,6 +26,7 @@ class Arvados::V1::SchemaController < ApplicationController
         rootUrl: root_url,
         servicePath: "arvados/v1/",
         batchPath: "batch",
+        defaultTrashLifetime: Rails.application.config.default_trash_lifetime,
         parameters: {
           alt: {
             type: "string",
diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index 84101ff..d7cd9a2 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -10,6 +10,9 @@ class Collection < ArvadosModel
   before_validation :set_portable_data_hash
   validate :ensure_hash_matches_manifest_text
 
+  # Query only undeleted collections by default.
+  default_scope { where("expires_at IS NULL or expires_at > CURRENT_TIMESTAMP") }
+
   api_accessible :user, extend: :common do |t|
     t.add :name
     t.add :description
diff --git a/services/api/config/application.default.yml b/services/api/config/application.default.yml
index 2cf2ce2..78d1d51 100644
--- a/services/api/config/application.default.yml
+++ b/services/api/config/application.default.yml
@@ -196,3 +196,6 @@ common:
   # source_version
   source_version: "<%= `git log -n 1 --format=%h` %>"
   local_modified: false
+
+  # Default lifetime for ephemeral collections: 2 weeks.
+  default_trash_lifetime: 1209600
diff --git a/services/api/test/fixtures/collections.yml b/services/api/test/fixtures/collections.yml
index acc6cc0..1a4a9ab 100644
--- a/services/api/test/fixtures/collections.yml
+++ b/services/api/test/fixtures/collections.yml
@@ -173,3 +173,29 @@ collection_to_move_around_in_aproject:
   updated_at: 2014-02-03T17:22:54Z
   manifest_text: ". 73feffa4b7f6bb68e44cf984c85f6e88+3 0:3:baz\n"
   name: collection_to_move_around
+
+expired_collection:
+  uuid: zzzzz-4zz18-mto52zx1s7sn3ih
+  portable_data_hash: 0b21a217243bfce5617fb9224b95bcb9+49
+  owner_uuid: zzzzz-tpzed-000000000000000
+  created_at: 2014-02-03T17:22:54Z
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+  modified_at: 2014-02-03T17:22:54Z
+  updated_at: 2014-02-03T17:22:54Z
+  expires_at: 2001-01-01T00:00:00Z
+  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:expired\n"
+  name: expired_collection
+
+collection_expires_in_future:
+  uuid: zzzzz-4zz18-padkqo7yb8d9i3j
+  portable_data_hash: 0b21a217243bfce5617fb9224b95bcb9+49
+  owner_uuid: zzzzz-tpzed-000000000000000
+  created_at: 2014-02-03T17:22:54Z
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
+  modified_at: 2014-02-03T17:22:54Z
+  updated_at: 2014-02-03T17:22:54Z
+  expires_at: 2038-01-01T00:00:00Z
+  manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:expired\n"
+  name: collection_expires_in_future
diff --git a/services/api/test/fixtures/links.yml b/services/api/test/fixtures/links.yml
index 28dbf01..bd69b36 100644
--- a/services/api/test/fixtures/links.yml
+++ b/services/api/test/fixtures/links.yml
@@ -222,6 +222,34 @@ baz_file_publicly_readable:
   head_uuid: zzzzz-4zz18-y9vne9npefyxh8g
   properties: {}
 
+expired_collection_readable_by_active:
+  uuid: zzzzz-o0j2j-e3cq2eg21va67ud
+  owner_uuid: zzzzz-tpzed-000000000000000
+  created_at: 2014-01-24 20:42:26 -0800
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-000000000000000
+  modified_at: 2014-01-24 20:42:26 -0800
+  updated_at: 2014-01-24 20:42:26 -0800
+  tail_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  link_class: permission
+  name: can_read
+  head_uuid: zzzzz-4zz18-mto52zx1s7sn3ih
+  properties: {}
+
+unexpired_collection_readable_by_active:
+  uuid: zzzzz-o0j2j-4undx2cussodkkg
+  owner_uuid: zzzzz-tpzed-000000000000000
+  created_at: 2014-01-24 20:42:26 -0800
+  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_user_uuid: zzzzz-tpzed-000000000000000
+  modified_at: 2014-01-24 20:42:26 -0800
+  updated_at: 2014-01-24 20:42:26 -0800
+  tail_uuid: zzzzz-tpzed-xurymjxw79nv3jz
+  link_class: permission
+  name: can_read
+  head_uuid: zzzzz-4zz18-padkqo7yb8d9i3j
+  properties: {}
+
 barbaz_job_readable_by_spectator:
   uuid: zzzzz-o0j2j-cpy7p41hpk531e1
   owner_uuid: zzzzz-tpzed-000000000000000
diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb
index 8e3e631..18cbafc 100644
--- a/services/api/test/functional/arvados/v1/collections_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb
@@ -559,4 +559,24 @@ EOS
     "Collection should not exist in database after failed create"
   end
 
+  test 'Expired collections are not returned' do
+    permit_unsigned_manifests
+    authorize_with :active
+    get :index, {
+      where: {name: 'expired_collection'},
+    }
+    assert_response :success
+    found = assigns(:objects)
+    assert_equal 0, found.count
+  end
+
+  test 'Collection with future expiration time is returned' do
+    permit_unsigned_manifests
+    authorize_with :active
+    get :index, {
+      where: {name: 'collection_expires_in_future'},
+    }
+    found = assigns(:objects)
+    assert_equal 1, found.count
+  end
 end
diff --git a/services/api/test/functional/arvados/v1/schema_controller_test.rb b/services/api/test/functional/arvados/v1/schema_controller_test.rb
index 816834b..520e36e 100644
--- a/services/api/test/functional/arvados/v1/schema_controller_test.rb
+++ b/services/api/test/functional/arvados/v1/schema_controller_test.rb
@@ -13,4 +13,11 @@ class Arvados::V1::SchemaControllerTest < ActionController::TestCase
                  "discovery document was generated >#{MAX_SCHEMA_AGE}s ago")
   end
 
+  test "discovery document has defaultTrashLifetime" do
+    get :index
+    assert_response :success
+    discovery_doc = JSON.parse(@response.body)
+    assert_includes discovery_doc, 'defaultTrashLifetime'
+    assert_equal discovery_doc['defaultTrashLifetime'], Rails.application.config.default_trash_lifetime
+  end
 end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list