diff --git a/seahub/api2/endpoints/copy_move_task.py b/seahub/api2/endpoints/copy_move_task.py index 84f801c8a7..6532db7440 100644 --- a/seahub/api2/endpoints/copy_move_task.py +++ b/seahub/api2/endpoints/copy_move_task.py @@ -76,10 +76,6 @@ class CopyMoveTaskView(APIView): error_msg = 'dirent_type invalid.' return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - if src_repo_id == dst_repo_id and src_parent_dir == dst_parent_dir: - error_msg = _('Invalid destination path') - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - if len(dst_parent_dir + src_dirent_name) > MAX_PATH: error_msg = _('Destination path is too long.') return api_error(status.HTTP_400_BAD_REQUEST, error_msg) @@ -89,6 +85,11 @@ class CopyMoveTaskView(APIView): error_msg = "operation can only be 'move' or 'copy'." return api_error(status.HTTP_400_BAD_REQUEST, error_msg) + if operation == 'move': + if src_repo_id == dst_repo_id and src_parent_dir == dst_parent_dir: + error_msg = _('Invalid destination path') + return api_error(status.HTTP_400_BAD_REQUEST, error_msg) + dirent_type = dirent_type.lower() if dirent_type not in ('file', 'dir'): error_msg = "operation can only be 'file' or 'dir'." diff --git a/seahub/api2/endpoints/file.py b/seahub/api2/endpoints/file.py index 107ef072ba..04ca56f95d 100644 --- a/seahub/api2/endpoints/file.py +++ b/seahub/api2/endpoints/file.py @@ -405,11 +405,6 @@ class FileView(APIView): error_msg = 'Permission denied.' return api_error(status.HTTP_403_FORBIDDEN, error_msg) - # copy file - if src_repo_id == dst_repo_id and src_dir == dst_dir: - file_info = self.get_file_info(username, repo_id, path) - return Response(file_info) - filename = os.path.basename(path) new_file_name = check_filename_with_rename(dst_repo_id, dst_dir, filename) try: diff --git a/seahub/api2/views.py b/seahub/api2/views.py index ea1e2e03bd..d061e83f18 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -2252,10 +2252,6 @@ class OpCopyView(APIView): return api_error(status.HTTP_400_BAD_REQUEST, 'Missing argument.') - if repo_id == dst_repo and parent_dir == dst_dir: - return api_error(status.HTTP_400_BAD_REQUEST, - 'The destination directory is the same as the source.') - # src resource check repo = get_repo(repo_id) if not repo: @@ -2713,9 +2709,6 @@ class FileView(APIView): if not (dst_repo_id and dst_dir): return api_error(status.HTTP_400_BAD_REQUEST, 'Missing arguments.') - if src_repo_id == dst_repo_id and src_dir == dst_dir: - return Response('success', status=status.HTTP_200_OK) - # check src folder permission if check_folder_permission(request, repo_id, src_dir) is None: return api_error(status.HTTP_403_FORBIDDEN, diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index 0db5e4c319..dda7835a86 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -678,12 +678,6 @@ def dirents_copy_move_common(): return HttpResponse(json.dumps(result), status=400, content_type=content_type) - # when dst is the same as src - if repo_id == dst_repo_id and parent_dir == dst_path: - result['error'] = _('Invalid destination path') - return HttpResponse(json.dumps(result), status=400, - content_type=content_type) - # check whether user has write permission to dest repo if check_folder_permission(request, dst_repo_id, dst_path) != 'rw': result['error'] = _('Permission denied') @@ -755,6 +749,12 @@ def mv_dirents(request, src_repo_id, src_path, dst_repo_id, dst_path, allowed_files = [] allowed_dirs = [] + # when dst is the same as src + if src_repo_id == dst_repo_id and src_path == dst_path: + result['error'] = _('Invalid destination path') + return HttpResponse(json.dumps(result), status=400, + content_type=content_type) + locked_files = get_locked_files_by_dir(request, src_repo_id, src_path) # check parent dir perm for files diff --git a/static/scripts/app/views/dialogs/dirent-mvcp.js b/static/scripts/app/views/dialogs/dirent-mvcp.js index 88b354797e..5e59bb6e42 100644 --- a/static/scripts/app/views/dialogs/dirent-mvcp.js +++ b/static/scripts/app/views/dialogs/dirent-mvcp.js @@ -179,10 +179,12 @@ define([ dst_path = $('[name="dst_path"]', this.$form).val(); if (!$.trim(dst_repo) || !$.trim(dst_path)) { - $('.error', form).removeClass('hide'); + this.$error.removeClass('hide'); return false; } - if (dst_repo == repo_id && (dst_path == path || (obj_type == 'dir' && dst_path == path + obj_name + '/'))) { + if (dst_repo == repo_id && ( + (dst_path == path && this.op_type == 'mv') || + (obj_type == 'dir' && dst_path == path + obj_name + '/'))) { this.$error.html(gettext("Invalid destination path")).removeClass('hide'); return false; } @@ -207,6 +209,10 @@ define([ } else { msg = gettext("Successfully copied %(name)s") .replace('%(name)s', obj_name); + + if (dst_repo == repo_id && dst_path == path) { + _this.dirView.renderDir(); + } } if (!data['task_id']) { // no progress diff --git a/static/scripts/app/views/dir.js b/static/scripts/app/views/dir.js index dbdb92c256..fa0b5eb51b 100644 --- a/static/scripts/app/views/dir.js +++ b/static/scripts/app/views/dir.js @@ -1167,7 +1167,8 @@ define([ $('.error', form).removeClass('hide'); return false; } - if (dst_repo == dirents.repo_id && dst_path == cur_path) { + if (dst_repo == dirents.repo_id && + (op == 'mv' && dst_path == cur_path)) { $('.error', form).html(gettext("Invalid destination path")).removeClass('hide'); return false; } @@ -1232,6 +1233,11 @@ define([ } else { msg_s = gettext("Successfully copied %(name)s and %(amount)s other items."); } + + // show the added items + if (dst_path == cur_path) { + _this.renderDir(); + } } msg_s = msg_s.replace('%(name)s', data['success'][0]).replace('%(amount)s', success_len - 1); diff --git a/static/scripts/app/views/dirent-grid.js b/static/scripts/app/views/dirent-grid.js index 697ea3bfd9..5df8ebf367 100644 --- a/static/scripts/app/views/dirent-grid.js +++ b/static/scripts/app/views/dirent-grid.js @@ -232,6 +232,7 @@ define([ mvcp: function(e) { var op_type = $(e.currentTarget).hasClass('mv') ? 'mv' : 'cp'; var options = { + 'dirView': this.dirView, 'dir': this.dir, 'dirent': this.model, 'op_type': op_type @@ -240,7 +241,6 @@ define([ if (this.model.get('is_img') && op_type == 'mv') { var index = $('.img-grid-item', this.dirView.$gridViewContainer).index(this.$el); $.extend(options, { - 'dirView': this.dirView, 'imgIndex': index }); } diff --git a/static/scripts/app/views/dirent.js b/static/scripts/app/views/dirent.js index 9d40b262a5..4d5af2e0c2 100644 --- a/static/scripts/app/views/dirent.js +++ b/static/scripts/app/views/dirent.js @@ -540,6 +540,7 @@ define([ this.hideMobileMenu(); var op_type = $(e.currentTarget).hasClass('mv') ? 'mv' : 'cp'; var options = { + 'dirView': this.dirView, 'dir': this.dir, 'dirent': this.model, 'op_type': op_type @@ -547,7 +548,6 @@ define([ if (this.model.get('is_img') && op_type == 'mv') { var index = $('.img-name-link', this.dirView.$table).index(this.$('.img-name-link')); $.extend(options, { - 'dirView': this.dirView, 'imgIndex': index }); }