[Sharing 2.0] Removed unused DI stuff
The share manager etc should not care about filtering stuff. They should return what is asked for them.
This commit is contained in:
parent
cb69e6c201
commit
aeae73b364
4 changed files with 34 additions and 176 deletions
|
@ -26,25 +26,22 @@ class OCSShareWrapper {
|
|||
* @return Share20OCS
|
||||
*/
|
||||
private function getShare20OCS() {
|
||||
return new Share20OCS(new \OC\Share20\Manager(
|
||||
\OC::$server->getUserSession()->getUser(),
|
||||
\OC::$server->getUserManager(),
|
||||
\OC::$server->getGroupManager(),
|
||||
\OC::$server->getLogger(),
|
||||
\OC::$server->getAppConfig(),
|
||||
\OC::$server->getUserFolder(),
|
||||
new \OC\Share20\DefaultShareProvider(
|
||||
\OC::$server->getDatabaseConnection(),
|
||||
\OC::$server->getUserManager(),
|
||||
\OC::$server->getGroupManager(),
|
||||
\OC::$server->getUserFolder()
|
||||
)
|
||||
),
|
||||
\OC::$server->getGroupManager(),
|
||||
\OC::$server->getUserManager(),
|
||||
\OC::$server->getRequest(),
|
||||
\OC::$server->getUserFolder(),
|
||||
\OC::$server->getURLGenerator());
|
||||
return new Share20OCS(
|
||||
new \OC\Share20\Manager(
|
||||
\OC::$server->getLogger(),
|
||||
\OC::$server->getAppConfig(),
|
||||
new \OC\Share20\DefaultShareProvider(
|
||||
\OC::$server->getDatabaseConnection(),
|
||||
\OC::$server->getUserManager(),
|
||||
\OC::$server->getGroupManager(),
|
||||
\OC::$server->getUserFolder()
|
||||
)
|
||||
),
|
||||
\OC::$server->getGroupManager(),
|
||||
\OC::$server->getUserManager(),
|
||||
\OC::$server->getRequest(),
|
||||
\OC::$server->getUserFolder(),
|
||||
\OC::$server->getURLGenerator());
|
||||
}
|
||||
|
||||
public function getAllShares($params) {
|
||||
|
|
|
@ -24,25 +24,25 @@ use OCA\Files_Sharing\API\Share20OCS;
|
|||
|
||||
class Share20OCSTest extends \Test\TestCase {
|
||||
|
||||
/** @var OC\Share20\Manager */
|
||||
/** @var \OC\Share20\Manager */
|
||||
private $shareManager;
|
||||
|
||||
/** @var OCP\IGroupManager */
|
||||
/** @var \OCP\IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var OCP\IUserManager */
|
||||
/** @var \OCP\IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var OCP\IRequest */
|
||||
/** @var \OCP\IRequest */
|
||||
private $request;
|
||||
|
||||
/** @var OCP\Files\Folder */
|
||||
/** @var \OCP\Files\Folder */
|
||||
private $userFolder;
|
||||
|
||||
/** @var OCP\IURLGenerator */
|
||||
/** @var \OCP\IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var OCS */
|
||||
/** @var Share20OCS */
|
||||
private $ocs;
|
||||
|
||||
protected function setUp() {
|
||||
|
|
|
@ -22,11 +22,7 @@ namespace OC\Share20;
|
|||
|
||||
|
||||
use OCP\IAppConfig;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\ILogger;
|
||||
use OCP\Files\Folder;
|
||||
|
||||
use OC\Share20\Exception\ShareNotFound;
|
||||
|
||||
|
@ -40,37 +36,19 @@ class Manager {
|
|||
*/
|
||||
private $defaultProvider;
|
||||
|
||||
/** @var IUser */
|
||||
private $currentUser;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/** @var IAppConfig */
|
||||
private $appConfig;
|
||||
|
||||
/** @var IFolder */
|
||||
private $userFolder;
|
||||
|
||||
public function __construct(IUser $user,
|
||||
IUserManager $userManager,
|
||||
IGroupManager $groupManager,
|
||||
ILogger $logger,
|
||||
IAppConfig $appConfig,
|
||||
Folder $userFolder,
|
||||
IShareProvider $defaultProvider) {
|
||||
$this->currentUser = $user;
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
public function __construct(
|
||||
ILogger $logger,
|
||||
IAppConfig $appConfig,
|
||||
IShareProvider $defaultProvider
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->appConfig = $appConfig;
|
||||
$this->userFolder = $userFolder;
|
||||
|
||||
// TEMP SOLUTION JUST TO GET STARTED
|
||||
$this->defaultProvider = $defaultProvider;
|
||||
|
@ -118,7 +96,7 @@ class Manager {
|
|||
/**
|
||||
* Delete a share
|
||||
*
|
||||
* @param Share $share
|
||||
* @param IShare $share
|
||||
* @throws ShareNotFound
|
||||
* @throws \OC\Share20\Exception\BackendError
|
||||
*/
|
||||
|
@ -126,7 +104,7 @@ class Manager {
|
|||
// Just to make sure we have all the info
|
||||
$share = $this->getShareById($share->getId());
|
||||
|
||||
$formatHookParams = function($share) {
|
||||
$formatHookParams = function(IShare $share) {
|
||||
// Prepare hook
|
||||
$shareType = $share->getShareType();
|
||||
$sharedWith = '';
|
||||
|
@ -203,12 +181,6 @@ class Manager {
|
|||
|
||||
$share = $this->defaultProvider->getShareById($id);
|
||||
|
||||
if ($share->getSharedWith() !== $this->currentUser &&
|
||||
$share->getSharedBy() !== $this->currentUser &&
|
||||
$share->getShareOwner() !== $this->currentUser) {
|
||||
throw new ShareNotFound();
|
||||
}
|
||||
|
||||
return $share;
|
||||
}
|
||||
|
||||
|
@ -246,7 +218,7 @@ class Manager {
|
|||
*
|
||||
* @return Share
|
||||
*
|
||||
* @throws ShareNotFoundException
|
||||
* @throws ShareNotFound
|
||||
*/
|
||||
public function getShareByToken($token, $password=null) {
|
||||
throw new \Exception();
|
||||
|
|
|
@ -23,64 +23,39 @@ namespace Test\Share20;
|
|||
use OC\Share20\Manager;
|
||||
use OC\Share20\Exception;
|
||||
|
||||
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\ILogger;
|
||||
use OCP\IAppConfig;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Share20\IShareProvider;
|
||||
use OC\Share20\IShareProvider;
|
||||
|
||||
class ManagerTest extends \Test\TestCase {
|
||||
|
||||
/** @var Manager */
|
||||
protected $manager;
|
||||
|
||||
/** @var IUser */
|
||||
protected $user;
|
||||
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
protected $groupManager;
|
||||
|
||||
/** @var ILogger */
|
||||
protected $logger;
|
||||
|
||||
/** @var IAppConfig */
|
||||
protected $appConfig;
|
||||
|
||||
/** @var Folder */
|
||||
protected $userFolder;
|
||||
|
||||
/** @var IShareProvider */
|
||||
protected $defaultProvider;
|
||||
|
||||
public function setUp() {
|
||||
|
||||
$this->user = $this->getMock('\OCP\IUser');
|
||||
$this->userManager = $this->getMock('\OCP\IUserManager');
|
||||
$this->groupManager = $this->getMock('\OCP\IGroupManager');
|
||||
$this->logger = $this->getMock('\OCP\ILogger');
|
||||
$this->appConfig = $this->getMock('\OCP\IAppConfig');
|
||||
$this->userFolder = $this->getMock('\OCP\Files\Folder');
|
||||
$this->defaultProvider = $this->getMock('\OC\Share20\IShareProvider');
|
||||
|
||||
$this->manager = new Manager(
|
||||
$this->user,
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->logger,
|
||||
$this->appConfig,
|
||||
$this->userFolder,
|
||||
$this->defaultProvider
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException OC\Share20\Exception\ShareNotFound
|
||||
* @expectedException \OC\Share20\Exception\ShareNotFound
|
||||
*/
|
||||
public function testDeleteNoShareId() {
|
||||
$share = $this->getMock('\OC\Share20\IShare');
|
||||
|
@ -115,12 +90,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testDelete($shareType, $sharedWith, $sharedWith_string) {
|
||||
$manager = $this->getMockBuilder('\OC\Share20\Manager')
|
||||
->setConstructorArgs([
|
||||
$this->user,
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->logger,
|
||||
$this->appConfig,
|
||||
$this->userFolder,
|
||||
$this->defaultProvider
|
||||
])
|
||||
->setMethods(['getShareById', 'deleteChildren'])
|
||||
|
@ -205,12 +176,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testDeleteNested() {
|
||||
$manager = $this->getMockBuilder('\OC\Share20\Manager')
|
||||
->setConstructorArgs([
|
||||
$this->user,
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->logger,
|
||||
$this->appConfig,
|
||||
$this->userFolder,
|
||||
$this->defaultProvider
|
||||
])
|
||||
->setMethods(['getShareById'])
|
||||
|
@ -349,12 +316,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
public function testDeleteChildren() {
|
||||
$manager = $this->getMockBuilder('\OC\Share20\Manager')
|
||||
->setConstructorArgs([
|
||||
$this->user,
|
||||
$this->userManager,
|
||||
$this->groupManager,
|
||||
$this->logger,
|
||||
$this->appConfig,
|
||||
$this->userFolder,
|
||||
$this->defaultProvider
|
||||
])
|
||||
->setMethods(['deleteShare'])
|
||||
|
@ -391,82 +354,8 @@ class ManagerTest extends \Test\TestCase {
|
|||
$this->assertSame($shares, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException OC\Share20\Exception\ShareNotFound
|
||||
*/
|
||||
public function testGetShareByIdNotFoundInBackend() {
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
->method('getShareById')
|
||||
->with(42)
|
||||
->will($this->throwException(new \OC\Share20\Exception\ShareNotFound()));
|
||||
|
||||
$this->manager->getShareById(42);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException OC\Share20\Exception\ShareNotFound
|
||||
*/
|
||||
public function testGetShareByIdNotAuthorized() {
|
||||
$otherUser1 = $this->getMock('\OCP\IUser');
|
||||
$otherUser2 = $this->getMock('\OCP\IUser');
|
||||
$otherUser3 = $this->getMock('\OCP\IUser');
|
||||
|
||||
public function testGetShareById() {
|
||||
$share = $this->getMock('\OC\Share20\IShare');
|
||||
$share
|
||||
->expects($this->once())
|
||||
->method('getSharedWith')
|
||||
->with()
|
||||
->willReturn($otherUser1);
|
||||
$share
|
||||
->expects($this->once())
|
||||
->method('getSharedBy')
|
||||
->with()
|
||||
->willReturn($otherUser2);
|
||||
$share
|
||||
->expects($this->once())
|
||||
->method('getShareOwner')
|
||||
->with()
|
||||
->willReturn($otherUser3);
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
->method('getShareById')
|
||||
->with(42)
|
||||
->willReturn($share);
|
||||
|
||||
$this->manager->getShareById(42);
|
||||
}
|
||||
|
||||
public function dataGetShareById() {
|
||||
return [
|
||||
['getSharedWith'],
|
||||
['getSharedBy'],
|
||||
['getShareOwner'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetShareById
|
||||
*/
|
||||
public function testGetShareById($currentUserIs) {
|
||||
$otherUser1 = $this->getMock('\OCP\IUser');
|
||||
$otherUser2 = $this->getMock('\OCP\IUser');
|
||||
$otherUser3 = $this->getMock('\OCP\IUser');
|
||||
|
||||
$share = $this->getMock('\OC\Share20\IShare');
|
||||
$share
|
||||
->method('getSharedWith')
|
||||
->with()
|
||||
->willReturn($currentUserIs === 'getSharedWith' ? $this->user : $otherUser1);
|
||||
$share
|
||||
->method('getSharedBy')
|
||||
->with()
|
||||
->willReturn($currentUserIs === 'getSharedBy' ? $this->user : $otherUser2);
|
||||
$share
|
||||
->method('getShareOwner')
|
||||
->with()
|
||||
->willReturn($currentUserIs === 'getShareOwner' ? $this->user : $otherUser3);
|
||||
|
||||
$this->defaultProvider
|
||||
->expects($this->once())
|
||||
|
|
Loading…
Reference in a new issue