Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>
end
def find_objects_for_index
- @objects ||= model_class.readable_by(*@read_users, {:include_trash => (params[:include_trash] || 'untrash' == action_name)})
+ @objects ||= model_class.readable_by(*@read_users, {
+ :include_trash => (params[:include_trash] || 'untrash' == action_name),
+ :include_old_versions => params[:include_old_versions]
+ })
apply_where_limit_order_params
end
end
def find_objects_for_index
+ opts = {}
if params[:include_trash] || ['destroy', 'trash', 'untrash'].include?(action_name)
- @objects = Collection.readable_by(*@read_users, {include_trash: true})
+ opts.update({include_trash: true})
end
+ if params[:include_old_versions]
+ opts.update({include_old_versions: true})
+ end
+ @objects = Collection.readable_by(*@read_users, opts) if !opts.empty?
super
end
@select ||= model_class.selectable_attributes - ["manifest_text", "unsigned_manifest_text"]
end
end
+
+ def load_filters_param
+ super
+ return if !params[:include_old_versions]
+ @filters = @filters.map do |col, operator, operand|
+ # Replace uuid filters when including past versions
+ if col == 'uuid'
+ ['current_version_uuid', operator, operand]
+ else
+ [col, operator, operand]
+ end
+ end
+ end
end
end
self[:name] = new_name
- self[:uuid] = nil if uuid_was.nil? && !uuid.nil?
+ if uuid_was.nil? && !uuid.nil?
+ self[:uuid] = nil
+ if self.is_a? Collection
+ # Reset so that is assigned to the new UUID
+ self[:current_version_uuid] = nil
+ end
+ end
conn.exec_query 'SAVEPOINT save_with_unique_name'
retry
ensure
validate :ensure_storage_classes_contain_non_empty_strings
validate :old_versions_cannot_be_updated, on: :update
before_save :set_file_names
- before_create :set_current_version_uuid
api_accessible :user, extend: :common do |t|
t.add :name
['current_version_uuid']
end
- def set_current_version_uuid
- self.current_version_uuid ||= self.uuid
- end
-
def save! *args
# Skip if feature is disabled or saving a new record
if !Rails.configuration.collection_versioning || new_record?
end
def self.searchable_columns operator
- super - ["manifest_text", "current_version_uuid"]
+ super - ["manifest_text"]
end
def self.full_text_searchable_columns
raise ArvadosModel::PermissionDeniedError.new("previous versions cannot be updated")
end
end
+
+ def assign_uuid
+ super
+ self.current_version_uuid ||= self.uuid
+ true
+ end
end
--- /dev/null
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class AddCurrentVersionUuidToCollectionSearchIndex < ActiveRecord::Migration
+ disable_ddl_transaction!
+
+ def up
+ remove_index :collections, :name => 'collections_search_index'
+ add_index :collections, ["owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "portable_data_hash", "uuid", "name", "current_version_uuid"], name: 'collections_search_index', algorithm: :concurrently
+ end
+
+ def down
+ remove_index :collections, :name => 'collections_search_index'
+ add_index :collections, ["owner_uuid", "modified_by_client_uuid", "modified_by_user_uuid", "portable_data_hash", "uuid", "name"], name: 'collections_search_index', algorithm: :concurrently
+ end
+end
-- Name: collections_search_index; Type: INDEX; Schema: public; Owner: -
--
-CREATE INDEX collections_search_index ON public.collections USING btree (owner_uuid, modified_by_client_uuid, modified_by_user_uuid, portable_data_hash, uuid, name);
+CREATE INDEX collections_search_index ON public.collections USING btree (owner_uuid, modified_by_client_uuid, modified_by_user_uuid, portable_data_hash, uuid, name, current_version_uuid);
--
INSERT INTO schema_migrations (version) VALUES ('20181001175023');
+INSERT INTO schema_migrations (version) VALUES ('20181004131141');
+
"basic Collections index included past version")
end
+ test "get index with include_old_versions" do
+ authorize_with :active
+ get :index, {
+ include_old_versions: true
+ }
+ assert_response :success
+ assert(assigns(:objects).andand.any?, "no Collections returned in index")
+ assert(json_response["items"].any? { |c| c["uuid"] == collections(:collection_owned_by_active_past_version_1).uuid },
+ "past version not included on index")
+ end
+
test "collections.get returns signed locators, and no unsigned_manifest_text" do
permit_unsigned_manifests
authorize_with :active
end
assert_includes(item_uuids, collections(:collection_in_trashed_subproject).uuid)
end
+
+ test 'can get collection with past versions' do
+ authorize_with :active
+ get :index, {
+ filters: [['uuid','=',collections(:collection_owned_by_active).uuid]],
+ include_old_versions: true
+ }
+ assert_response :success
+ assert_equal 2, assigns(:objects).length
+ assert_equal 2, json_response['items_available']
+ assert_equal 2, json_response['items'].count
+ json_response['items'].each do |c|
+ assert_equal collections(:collection_owned_by_active).uuid,
+ c['current_version_uuid'],
+ 'response includes a version from a different collection'
+ end
+ end
end