When sharing with the owner show the path
The error message should contain the path that is being shared not the numeric id.
This commit is contained in:
parent
9e6a4dce43
commit
9e86d71cc5
|
@ -619,10 +619,13 @@ class Share extends Constants {
|
||||||
if (is_null($itemSourceName)) {
|
if (is_null($itemSourceName)) {
|
||||||
$itemSourceName = $itemSource;
|
$itemSourceName = $itemSource;
|
||||||
}
|
}
|
||||||
|
$itemName = $itemSourceName;
|
||||||
|
|
||||||
// check if file can be shared
|
// check if file can be shared
|
||||||
if ($itemType === 'file' or $itemType === 'folder') {
|
if ($itemType === 'file' or $itemType === 'folder') {
|
||||||
$path = \OC\Files\Filesystem::getPath($itemSource);
|
$path = \OC\Files\Filesystem::getPath($itemSource);
|
||||||
|
$itemName = $path;
|
||||||
|
|
||||||
// verify that the file exists before we try to share it
|
// verify that the file exists before we try to share it
|
||||||
if (!$path) {
|
if (!$path) {
|
||||||
$message = 'Sharing %s failed, because the file does not exist';
|
$message = 'Sharing %s failed, because the file does not exist';
|
||||||
|
@ -678,7 +681,7 @@ class Share extends Constants {
|
||||||
if ($shareType === self::SHARE_TYPE_USER) {
|
if ($shareType === self::SHARE_TYPE_USER) {
|
||||||
if ($shareWith == $uidOwner) {
|
if ($shareWith == $uidOwner) {
|
||||||
$message = 'Sharing %s failed, because the user %s is the item owner';
|
$message = 'Sharing %s failed, because the user %s is the item owner';
|
||||||
$message_t = $l->t('Sharing %s failed, because the user %s is the item owner', array($itemSourceName, $shareWith));
|
$message_t = $l->t('Sharing %s failed, because the user %s is the item owner', array($itemName, $shareWith));
|
||||||
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG);
|
||||||
throw new \Exception($message_t);
|
throw new \Exception($message_t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1735,6 +1735,30 @@ class Test_Share extends \Test\TestCase {
|
||||||
);
|
);
|
||||||
$this->assertCount(4, $res);
|
$this->assertCount(4, $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testShareWithOwnerError() {
|
||||||
|
OC_User::setUserId($this->user1);
|
||||||
|
$view = new \OC\Files\View('/' . $this->user1 . '/');
|
||||||
|
$view->mkdir('files/folder1');
|
||||||
|
|
||||||
|
$fileInfo = $view->getFileInfo('files/folder1');
|
||||||
|
$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);
|
||||||
|
$fileId = $fileInfo->getId();
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_ALL),
|
||||||
|
'Failed asserting that user 1 successfully shared "test" with user 2.'
|
||||||
|
);
|
||||||
|
|
||||||
|
OC_User::setUserId($this->user1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
OCP\Share::shareItem('folder', $fileId, OCP\Share::SHARE_TYPE_USER, $this->user1, \OCP\Constants::PERMISSION_ALL);
|
||||||
|
$this->fail();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertEquals('Sharing /folder1 failed, because the user ' . $this->user1 . ' is the item owner', $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DummyShareClass extends \OC\Share\Share {
|
class DummyShareClass extends \OC\Share\Share {
|
||||||
|
|
Loading…
Reference in New Issue