X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/files/js/favoritesfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ $(document).ready(function() {
if (result) {
// prepend empty dir info because original handler
result.unshift({});

for (var i = 0; i < result.length; i++) {
/**
* Set extraData to file path and name
* if the file is not in user's root home directory
*/
if (result[i].path !== '/') {
result[i].extraData = result[i].path + '/' + result[i].name;
}
}
}

return OCA.Files.FileList.prototype.reloadCallback.call(this, status, result);
Expand Down
27 changes: 23 additions & 4 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@
if (filename !== oldName) {
// Files.isFileNameValid(filename) throws an exception itself
OCA.Files.Files.isFileNameValid(filename);
if (self.inList(filename)) {
if (self.inList(filename, oldFileInfo.path)) {
throw t('files', '{newName} already exists', {newName: filename});
}
}
Expand Down Expand Up @@ -2405,6 +2405,18 @@
.done(function() {
newFileInfo = Object.create(oldFileInfo);
newFileInfo.name = newName;

/**
* Indicate that extraData has a path
* so we adjust it with the new file name
*/
if (newFileInfo.extraData &&
newFileInfo.extraData.indexOf('/') !== -1
) {
newFileInfo.extraData = oldFileInfo.path + '/' + newName;
}


updateInList(newFileInfo, oldFileInfo);
})
.fail(function(status) {
Expand Down Expand Up @@ -2665,11 +2677,18 @@
* Returns whether the given file name exists in the list
*
* @param {string} file file name
* @param {string} pathToSearch only look in certain path
*
* @return {bool} true if the file exists in the list, false otherwise
* @return {boolean} true if the file exists in the list, false otherwise
*/
inList:function(file) {
return this.findFile(file);
inList:function(file, pathToSearch) {
if(pathToSearch === undefined){
return this.findFile(file);
}

return _.find(this.files, function(aFile) {
return (aFile.name === file && aFile.path === pathToSearch);
});
},

/**
Expand Down
11 changes: 11 additions & 0 deletions changelog/unreleased/39315
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Bugfix: Allow renaming two files with the same name but different paths

With this change, we allow renaming a file to an existing file name,
when the path differs.
This happens for example when the user creates the file
'/mydirname/text.txt' and '/mytext.txt' then marks both as favorite, and then navigates to the Favorites
and renames 'mytext.txt' to 'text.txt'

https://github.com/owncloud/core/pull/39315
https://github.com/owncloud/core/issues/20722
https://github.com/owncloud/core/issues/35174
6 changes: 3 additions & 3 deletions tests/acceptance/features/lib/FavoritesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class FavoritesPage extends FilesPageBasic {
* @var string $path
*/
protected $path = '/index.php/apps/files/?view=favorites';
protected $fileNamesXpath = "//span[@class='nametext']";
protected $fileNameMatchXpath = "//span[@class='nametext' and .=%s]";
protected $fileNamesXpath = "//span[@class='nametext extra-data']";
protected $fileNameMatchXpath = "//span[contains(@class,'nametext') and not(contains(@class,'innernametext')) and .=%s]";
protected $fileListXpath = ".//div[@id='app-content-favorites']//tbody[@id='fileList']";
protected $emptyContentXpath = ".//div[@id='app-content-favorites']//div[@id='emptycontent']";
protected $filePathInRowXpath = "//*[@data-tags='_\$!<Favorite>!\$_']";
protected $filePathInRowXpath = "//span[@class='nametext extra-data']";

/**
* @return string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* ownCloud
*
* @author Phil Davis <phil@jankaritech.com>
* @copyright Copyright (c) 2021 Phil Davis phil@jankaritech.com
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace Page\FilesPageElement;

/**
* Object of a row on the SharedByLinkPage
*/
class SharedByLinkFileRow extends FileRow {
/**
* @param string $xpath
*
* @return null|string
*/
public function getFilePath($xpath) {
$fileRowLabel = $this->rowElement->find("xpath", $xpath);
if ($fileRowLabel === null) {
// On the shared-by-link page, the xpath on the way to the
// data-original-title string only exists if the shared resource
// is not a resource from the root folder. For this case there is
// no "hover text" so return null.
return null;
}
$filePath = $fileRowLabel->getAttribute("data-original-title");
return ($filePath);
}
}
30 changes: 28 additions & 2 deletions tests/acceptance/features/lib/SharedByLinkPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
namespace Page;

use Behat\Mink\Session;
use Page\FilesPageElement\FileRow;
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;

/**
* Shared By Link page.
Expand All @@ -39,6 +41,7 @@ class SharedByLinkPage extends FilesPageCRUD {
protected $fileNameMatchXpath = "//span[contains(@class,'nametext') and not(contains(@class,'innernametext')) and .=%s]";
protected $fileListXpath = ".//div[@id='app-content-sharinglinks']//tbody[@id='fileList']";
protected $emptyContentXpath = ".//div[@id='app-content-sharinglinks']//div[@id='emptycontent']";
protected $filePathInRowXpath = "//span[@class='nametext extra-data']";
protected $deleteAllSelectedBtnXpath = ".//*[@id='app-content-files']//*[@class='delete-selected']";
/**
*
Expand Down Expand Up @@ -77,12 +80,12 @@ protected function getEmptyContentXpath() {
/**
* {@inheritDoc}
*
* @return void
* @return string
* @see \Page\FilesPageBasic::getFilePathInRowXpath()
*
*/
protected function getFilePathInRowXpath() {
throw new \Exception(__METHOD__ . " not implemented in SharedByLinkPage");
return $this->filePathInRowXpath;
}

/**
Expand All @@ -106,6 +109,29 @@ public function __construct(
);
}

/**
* finds all rows that have the given name
*
* @param string|array $name
* @param Session $session
*
* @return FileRow[]
* @throws ElementNotFoundException
*/
public function findAllFileRowsByName($name, Session $session) {
$fileRowElements = $this->getFileRowElementsByName($name, $session);
$fileRows = [];
foreach ($fileRowElements as $fileRowElement) {
$fileRow = $this->getPage('FilesPageElement\\SharedByLinkFileRow');
$fileRow->setElement($fileRowElement);
$fileRow->setName($name);
$fileRows[] = $fileRow;
}
$count = \count($fileRows);
echo "findAllFileRowsByName found $count\n";
return $fileRows;
}

/**
*
* @param string|array $name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,19 @@ Feature: Share by public link
And folder "newfolder" should be listed on the webUI
And folder "test" should be listed on the webUI

@skipOnOcV10 @issue-35174
@skipOnOcV10.6 @skipOnOcV10.7 @skipOnOcV10.8.0
Scenario: User renames folders with different path in Shared by link page
Given user "Alice" has created folder "nf1"
And user "Alice" has created folder "nf1/newfolder"
And user "Alice" has created folder "test"
And user "Alice" has created folder "nf1/test"
And user "Alice" has created folder "newfolder"
And user "Alice" has created a public link share with settings
| path | nf1/newfolder |
| path | nf1/test |
And user "Alice" has created a public link share with settings
| path | test |
| path | newfolder |
And user "Alice" has logged in using the webUI
And the user has browsed to the shared-by-link page
When the user renames folder "test" to "newfolder" using the webUI
Then the following folder should be listed on the webUI
| newfolder |
| newfolder |
Then folder "newfolder" with path "nf1/newfolder" should be listed on the webUI

@skipOnOcV10.3
Scenario: user tries to deletes the expiration date of already existing public link using webUI when expiration date is enforced
Expand Down

This file was deleted.

X Tutup