[ARVADOS] created: 02a997da87252380eac0a653edce2442c2b8b518
Git user
git at public.curoverse.com
Fri Mar 31 11:39:56 EDT 2017
at 02a997da87252380eac0a653edce2442c2b8b518 (commit)
commit 02a997da87252380eac0a653edce2442c2b8b518
Author: radhika <radhika at curoverse.com>
Date: Fri Mar 31 11:39:13 2017 -0400
11368: show error if user tries to rename a collection file with a duplicate name.
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index 02b204f..75553b6 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -326,12 +326,19 @@ class CollectionsController < ApplicationController
end
arv_coll = Arv::Collection.new(@object.manifest_text)
- arv_coll.rename "./"+file_path, new_file_path
- if @object.update_attributes manifest_text: arv_coll.manifest_text
- show
- else
+ dst_exists = arv_coll.exist? new_file_path
+ if dst_exists
+ @errors = 'Duplicate file path. Please use a different name.'
self.render_error status: 422
+ else
+ arv_coll.rename "./"+file_path, new_file_path
+
+ if @object.update_attributes manifest_text: arv_coll.manifest_text
+ show
+ else
+ self.render_error status: 422
+ end
end
else
# Not a file rename; use default
diff --git a/apps/workbench/test/controllers/collections_controller_test.rb b/apps/workbench/test/controllers/collections_controller_test.rb
index b4d0f4a..1632dd0 100644
--- a/apps/workbench/test/controllers/collections_controller_test.rb
+++ b/apps/workbench/test/controllers/collections_controller_test.rb
@@ -732,4 +732,34 @@ class CollectionsControllerTest < ActionController::TestCase
collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
assert_match /. d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:file1renamed\n.\/dir1 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file2 0:0:file2\n.\/dir2\/dir3 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file1moved\n$/, collection['manifest_text']
end
+
+ test "renaming file with a duplicate name in same stream not allowed" do
+ use_token :active
+
+ # rename 'file2' as 'file1' and expect error
+ post :update, {
+ id: 'zzzzz-4zz18-pyw8yp9g3pr7irn',
+ collection: {
+ 'rename-file-path:file2' => 'file1'
+ },
+ format: :json
+ }, session_for(:active)
+ assert_response 422
+ assert_includes json_response['errors'], 'Duplicate file path'
+ end
+
+ test "renaming file with a duplicate name as another stream not allowed" do
+ use_token :active
+
+ # rename 'file1' as 'dir1/file1' and expect error
+ post :update, {
+ id: 'zzzzz-4zz18-pyw8yp9g3pr7irn',
+ collection: {
+ 'rename-file-path:file1' => 'dir1/file1'
+ },
+ format: :json
+ }, session_for(:active)
+ assert_response 422
+ assert_includes json_response['errors'], 'Duplicate file path'
+ end
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list