[ARVADOS] updated: 28e59edcec4af09f78be965fa3abfaa9ee3f8dff
Git user
git at public.curoverse.com
Fri Mar 31 14:04:21 EDT 2017
Summary of changes:
.../app/controllers/collections_controller.rb | 14 +++++++---
.../controllers/collections_controller_test.rb | 30 ++++++++++++++++++++++
2 files changed, 40 insertions(+), 4 deletions(-)
via 28e59edcec4af09f78be965fa3abfaa9ee3f8dff (commit)
via 4af850d6898dea0c5f460f6acbc52f2e361cbf1d (commit)
from 736a629e16c388a5afecc97268bd7eadfd7ce3c2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 28e59edcec4af09f78be965fa3abfaa9ee3f8dff
Merge: 736a629 4af850d
Author: radhika <radhika at curoverse.com>
Date: Fri Mar 31 14:04:02 2017 -0400
closes #11368
Merge branch '11368-collection-file-rename-warning'
commit 4af850d6898dea0c5f460f6acbc52f2e361cbf1d
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..dc9ed43 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -326,12 +326,18 @@ 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
+ if arv_coll.exist?(new_file_path)
+ @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