summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files_sharing/lib/controllers/sharecontroller.php16
-rw-r--r--apps/files_sharing/tests/controller/sharecontroller.php42
2 files changed, 32 insertions, 26 deletions
diff --git a/apps/files_sharing/lib/controllers/sharecontroller.php b/apps/files_sharing/lib/controllers/sharecontroller.php
index 6ac585e275c..bbe68096b52 100644
--- a/apps/files_sharing/lib/controllers/sharecontroller.php
+++ b/apps/files_sharing/lib/controllers/sharecontroller.php
@@ -232,8 +232,8 @@ class ShareController extends Controller {
}
$shareTmpl = [];
- $shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName();
- $shareTmpl['owner'] = $share->getShareOwner()->getUID();
+ $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName();
+ $shareTmpl['owner'] = $share->getShareOwner();
$shareTmpl['filename'] = $share->getNode()->getName();
$shareTmpl['directory_path'] = $share->getTarget();
$shareTmpl['mimetype'] = $share->getNode()->getMimetype();
@@ -320,7 +320,7 @@ class ShareController extends Controller {
}
}
- $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID());
+ $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
$originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
// Single file share
@@ -330,7 +330,7 @@ class ShareController extends Controller {
$event->setApp('files_sharing')
->setType(Activity::TYPE_PUBLIC_LINKS)
->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getNode()->getPath())])
- ->setAffectedUser($share->getShareOwner()->getUID())
+ ->setAffectedUser($share->getShareOwner())
->setObject('files', $share->getNode()->getId(), $userFolder->getRelativePath($share->getNode()->getPath()));
$this->activityManager->publish($event);
}
@@ -356,7 +356,7 @@ class ShareController extends Controller {
$event->setApp('files_sharing')
->setType(Activity::TYPE_PUBLIC_LINKS)
->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())])
- ->setAffectedUser($share->getShareOwner()->getUID())
+ ->setAffectedUser($share->getShareOwner())
->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath()));
$this->activityManager->publish($event);
} else if (!empty($files_list)) {
@@ -369,7 +369,7 @@ class ShareController extends Controller {
$event = $this->activityManager->generateEvent();
$event->setApp('files_sharing')
->setType(Activity::TYPE_PUBLIC_LINKS)
- ->setAffectedUser($share->getShareOwner()->getUID())
+ ->setAffectedUser($share->getShareOwner())
->setObject('files', $subNode->getId(), $userFolder->getRelativePath($subNode->getPath()));
if ($subNode instanceof \OCP\Files\File) {
@@ -386,7 +386,7 @@ class ShareController extends Controller {
$event->setApp('files_sharing')
->setType(Activity::TYPE_PUBLIC_LINKS)
->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())])
- ->setAffectedUser($share->getShareOwner()->getUID())
+ ->setAffectedUser($share->getShareOwner())
->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath()));
$this->activityManager->publish($event);
}
@@ -394,7 +394,7 @@ class ShareController extends Controller {
/* FIXME: We should do this all nicely in OCP */
OC_Util::tearDownFS();
- OC_Util::setupFS($share->getShareOwner()->getUID());
+ OC_Util::setupFS($share->getShareOwner());
/**
* this sets a cookie to be able to recognize the start of the download
diff --git a/apps/files_sharing/tests/controller/sharecontroller.php b/apps/files_sharing/tests/controller/sharecontroller.php
index e36ee9e4914..22e15972cd6 100644
--- a/apps/files_sharing/tests/controller/sharecontroller.php
+++ b/apps/files_sharing/tests/controller/sharecontroller.php
@@ -35,6 +35,7 @@ use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\ISession;
+use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use OCP\IURLGenerator;
@@ -64,6 +65,8 @@ class ShareControllerTest extends \Test\TestCase {
private $config;
/** @var \OC\Share20\Manager | \PHPUnit_Framework_MockObject_MockObject */
private $shareManager;
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
+ private $userManager;
protected function setUp() {
$this->appName = 'files_sharing';
@@ -73,13 +76,14 @@ class ShareControllerTest extends \Test\TestCase {
$this->session = $this->getMock('\OCP\ISession');
$this->previewManager = $this->getMock('\OCP\IPreview');
$this->config = $this->getMock('\OCP\IConfig');
+ $this->userManager = $this->getMock('\OCP\IUserManager');
$this->shareController = new \OCA\Files_Sharing\Controllers\ShareController(
$this->appName,
$this->getMock('\OCP\IRequest'),
$this->config,
$this->urlGenerator,
- $this->getMock('\OCP\IUserManager'),
+ $this->userManager,
$this->getMock('\OCP\ILogger'),
$this->getMock('\OCP\Activity\IManager'),
$this->shareManager,
@@ -116,7 +120,7 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testShowAuthenticateNotAuthenticated() {
- $share = $this->getMock('\OCP\Share\IShare');
+ $share = \OC::$server->getShareManager()->newShare();
$this->shareManager
->expects($this->once())
@@ -130,8 +134,8 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testShowAuthenticateAuthenticatedForDifferentShare() {
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getId')->willReturn(1);
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(1);
$this->shareManager
->expects($this->once())
@@ -148,8 +152,8 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testShowAuthenticateCorrectShare() {
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getId')->willReturn(1);
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(1);
$this->shareManager
->expects($this->once())
@@ -183,8 +187,8 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testAuthenticateValidPassword() {
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getId')->willReturn(42);
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(42);
$this->shareManager
->expects($this->once())
@@ -214,8 +218,8 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testAuthenticateInvalidPassword() {
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getId')->willReturn(42);
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(42);
$this->shareManager
->expects($this->once())
@@ -252,8 +256,8 @@ class ShareControllerTest extends \Test\TestCase {
}
public function testShowShareNotAuthenticated() {
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getPassword')->willReturn('password');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setPassword('password');
$this->shareManager
->expects($this->once())
@@ -283,12 +287,12 @@ class ShareControllerTest extends \Test\TestCase {
$file->method('getMimetype')->willReturn('text/plain');
$file->method('getSize')->willReturn(33);
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getId')->willReturn('42');
- $share->method('getPassword')->willReturn('password');
- $share->method('getShareOwner')->willReturn($owner);
- $share->method('getNode')->willReturn($file);
- $share->method('getTarget')->willReturn('/file1.txt');
+ $share = \OC::$server->getShareManager()->newShare();
+ $share->setId(42);
+ $share->setPassword('password')
+ ->setShareOwner('ownerUID')
+ ->setNode($file)
+ ->setTarget('/file1.txt');
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
@@ -311,6 +315,8 @@ class ShareControllerTest extends \Test\TestCase {
->with('token')
->willReturn($share);
+ $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
+
$response = $this->shareController->showShare('token');
$sharedTmplParams = array(
'displayName' => 'ownerDisplay',