mirror of
https://github.com/nextcloud/server.git
synced 2026-02-20 00:12:30 -05:00
sharebymail: remove ILogger and upgrade to PHP 8 syntax
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
This commit is contained in:
parent
23197a840c
commit
303dadfaa9
4 changed files with 97 additions and 222 deletions
|
|
@ -55,7 +55,6 @@ use OCP\HintException;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -68,6 +67,7 @@ use OCP\Share\Exceptions\ShareNotFound;
|
|||
use OCP\Share\IManager as IShareManager;
|
||||
use OCP\Share\IShare;
|
||||
use OCP\Share\IShareProvider;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Class ShareByMail
|
||||
|
|
@ -75,100 +75,41 @@ use OCP\Share\IShareProvider;
|
|||
* @package OCA\ShareByMail
|
||||
*/
|
||||
class ShareByMailProvider implements IShareProvider {
|
||||
private IConfig $config;
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $dbConnection;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var IMailer */
|
||||
private $mailer;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IManager */
|
||||
private $activityManager;
|
||||
|
||||
/** @var SettingsManager */
|
||||
private $settingsManager;
|
||||
|
||||
/** @var Defaults */
|
||||
private $defaults;
|
||||
|
||||
/** @var IHasher */
|
||||
private $hasher;
|
||||
|
||||
/** @var IEventDispatcher */
|
||||
private $eventDispatcher;
|
||||
|
||||
/** @var IShareManager */
|
||||
private $shareManager;
|
||||
|
||||
/**
|
||||
* Return the identifier of this provider.
|
||||
*
|
||||
* @return string Containing only [a-zA-Z0-9]
|
||||
*/
|
||||
public function identifier() {
|
||||
public function identifier(): string {
|
||||
return 'ocMailShare';
|
||||
}
|
||||
|
||||
public function __construct(IConfig $config,
|
||||
IDBConnection $connection,
|
||||
ISecureRandom $secureRandom,
|
||||
IUserManager $userManager,
|
||||
IRootFolder $rootFolder,
|
||||
IL10N $l,
|
||||
ILogger $logger,
|
||||
IMailer $mailer,
|
||||
IURLGenerator $urlGenerator,
|
||||
IManager $activityManager,
|
||||
SettingsManager $settingsManager,
|
||||
Defaults $defaults,
|
||||
IHasher $hasher,
|
||||
IEventDispatcher $eventDispatcher,
|
||||
IShareManager $shareManager) {
|
||||
$this->config = $config;
|
||||
$this->dbConnection = $connection;
|
||||
$this->secureRandom = $secureRandom;
|
||||
$this->userManager = $userManager;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->l = $l;
|
||||
$this->logger = $logger;
|
||||
$this->mailer = $mailer;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->settingsManager = $settingsManager;
|
||||
$this->defaults = $defaults;
|
||||
$this->hasher = $hasher;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->shareManager = $shareManager;
|
||||
public function __construct(
|
||||
private IConfig $config,
|
||||
private IDBConnection $dbConnection,
|
||||
private ISecureRandom $secureRandom,
|
||||
private IUserManager $userManager,
|
||||
private IRootFolder $rootFolder,
|
||||
private IL10N $l,
|
||||
private LoggerInterface $logger,
|
||||
private IMailer $mailer,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private IManager $activityManager,
|
||||
private SettingsManager $settingsManager,
|
||||
private Defaults $defaults,
|
||||
private IHasher $hasher,
|
||||
private IEventDispatcher $eventDispatcher,
|
||||
private IShareManager $shareManager,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Share a path
|
||||
*
|
||||
* @param IShare $share
|
||||
* @return IShare The share object
|
||||
* @throws ShareNotFound
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function create(IShare $share) {
|
||||
public function create(IShare $share): IShare {
|
||||
$shareWith = $share->getSharedWith();
|
||||
/*
|
||||
* Check if file is not already shared with the remote user
|
||||
|
|
@ -213,11 +154,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* auto generate password in case of password enforcement on mail shares
|
||||
*
|
||||
* @param IShare $share
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function autoGeneratePassword($share) {
|
||||
protected function autoGeneratePassword(IShare $share): string {
|
||||
$initiatorUser = $this->userManager->get($share->getSharedBy());
|
||||
$initiatorEMailAddress = ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;
|
||||
$allowPasswordByMail = $this->settingsManager->sendPasswordByMail();
|
||||
|
|
@ -241,11 +180,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* create activity if a file/folder was shared by mail
|
||||
*
|
||||
* @param IShare $share
|
||||
* @param string $type
|
||||
*/
|
||||
protected function createShareActivity(IShare $share, string $type = 'share') {
|
||||
protected function createShareActivity(IShare $share, string $type = 'share'): void {
|
||||
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
|
||||
|
||||
$this->publishActivity(
|
||||
|
|
@ -273,12 +209,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* create activity if a file/folder was shared by mail
|
||||
*
|
||||
* @param IShare $share
|
||||
* @param string $sharedWith
|
||||
* @param bool $sendToSelf
|
||||
*/
|
||||
protected function createPasswordSendActivity(IShare $share, $sharedWith, $sendToSelf) {
|
||||
protected function createPasswordSendActivity(IShare $share, string $sharedWith, bool $sendToSelf): void {
|
||||
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
|
||||
|
||||
if ($sendToSelf) {
|
||||
|
|
@ -303,14 +235,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* publish activity if a file/folder was shared by mail
|
||||
*
|
||||
* @param string $subject
|
||||
* @param array $parameters
|
||||
* @param string $affectedUser
|
||||
* @param int $fileId
|
||||
* @param string $filePath
|
||||
*/
|
||||
protected function publishActivity(string $subject, array $parameters, string $affectedUser, int $fileId, string $filePath) {
|
||||
protected function publishActivity(string $subject, array $parameters, string $affectedUser, int $fileId, string $filePath): void {
|
||||
$event = $this->activityManager->generateEvent();
|
||||
$event->setApp('sharebymail')
|
||||
->setType('shared')
|
||||
|
|
@ -321,11 +247,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param IShare $share
|
||||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function createMailShare(IShare $share) {
|
||||
protected function createMailShare(IShare $share): int {
|
||||
$share->setToken($this->generateToken());
|
||||
$shareId = $this->addShareToDB(
|
||||
$share->getNodeId(),
|
||||
|
|
@ -366,18 +290,16 @@ class ShareByMailProvider implements IShareProvider {
|
|||
$share->getNote()
|
||||
);
|
||||
} catch (HintException $hintException) {
|
||||
$this->logger->logException($hintException, [
|
||||
'message' => 'Failed to send share by mail.',
|
||||
'level' => ILogger::ERROR,
|
||||
$this->logger->error('Failed to send share by mail.', [
|
||||
'app' => 'sharebymail',
|
||||
'exception' => $hintException,
|
||||
]);
|
||||
$this->removeShareFromTable($shareId);
|
||||
throw $hintException;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->logException($e, [
|
||||
'message' => 'Failed to send share by mail.',
|
||||
'level' => ILogger::ERROR,
|
||||
$this->logger->error('Failed to send share by mail.', [
|
||||
'app' => 'sharebymail',
|
||||
'exception' => $e,
|
||||
]);
|
||||
$this->removeShareFromTable($shareId);
|
||||
throw new HintException('Failed to send share by mail',
|
||||
|
|
@ -388,20 +310,16 @@ class ShareByMailProvider implements IShareProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param string $link
|
||||
* @param string $initiator
|
||||
* @param string $shareWith
|
||||
* @param \DateTime|null $expiration
|
||||
* @throws \Exception If mail couldn't be sent
|
||||
*/
|
||||
protected function sendMailNotification($filename,
|
||||
$link,
|
||||
$initiator,
|
||||
$shareWith,
|
||||
\DateTime $expiration = null,
|
||||
$note = ''
|
||||
) {
|
||||
protected function sendMailNotification(
|
||||
string $filename,
|
||||
string $link,
|
||||
string $initiator,
|
||||
string $shareWith,
|
||||
?\DateTime $expiration = null,
|
||||
string $note = '',
|
||||
): void {
|
||||
$initiatorUser = $this->userManager->get($initiator);
|
||||
$initiatorDisplayName = ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
|
||||
$message = $this->mailer->createMessage();
|
||||
|
|
@ -464,12 +382,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* send password to recipient of a mail share
|
||||
*
|
||||
* @param IShare $share
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
protected function sendPassword(IShare $share, $password) {
|
||||
protected function sendPassword(IShare $share, string $password): bool {
|
||||
$filename = $share->getNode()->getName();
|
||||
$initiator = $share->getSharedBy();
|
||||
$shareWith = $share->getSharedWith();
|
||||
|
|
@ -538,7 +452,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected function sendNote(IShare $share) {
|
||||
protected function sendNote(IShare $share): void {
|
||||
$recipient = $share->getSharedWith();
|
||||
|
||||
|
||||
|
|
@ -598,12 +512,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
* send auto generated password to the owner. This happens if the admin enforces
|
||||
* a password for mail shares and forbid to send the password by mail to the recipient
|
||||
*
|
||||
* @param IShare $share
|
||||
* @param string $password
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function sendPasswordToOwner(IShare $share, $password) {
|
||||
protected function sendPasswordToOwner(IShare $share, string $password): bool {
|
||||
$filename = $share->getNode()->getName();
|
||||
$initiator = $this->userManager->get($share->getSharedBy());
|
||||
$initiatorEMailAddress = ($initiator instanceof IUser) ? $initiator->getEMailAddress() : null;
|
||||
|
|
@ -665,10 +576,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* generate share token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateToken($size = 15) {
|
||||
protected function generateToken(int $size = 15): string {
|
||||
$token = $this->secureRandom->generate($size, ISecureRandom::CHAR_HUMAN_READABLE);
|
||||
return $token;
|
||||
}
|
||||
|
|
@ -676,10 +585,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* Get all children of this share
|
||||
*
|
||||
* @param IShare $parent
|
||||
* @return IShare[]
|
||||
*/
|
||||
public function getChildren(IShare $parent) {
|
||||
public function getChildren(IShare $parent): array {
|
||||
$children = [];
|
||||
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
|
@ -752,12 +660,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* Update a share
|
||||
*
|
||||
* @param IShare $share
|
||||
* @param string|null $plainTextPassword
|
||||
* @return IShare The share object
|
||||
*/
|
||||
public function update(IShare $share, $plainTextPassword = null) {
|
||||
public function update(IShare $share, ?string $plainTextPassword = null): IShare {
|
||||
$originalShare = $this->getShareById($share->getId());
|
||||
|
||||
// a real password was given
|
||||
|
|
@ -796,7 +700,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function move(IShare $share, $recipient) {
|
||||
public function move(IShare $share, $recipient): IShare {
|
||||
/**
|
||||
* nothing to do here, mail shares are only outgoing shares
|
||||
*/
|
||||
|
|
@ -808,7 +712,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
*
|
||||
* @param IShare $share
|
||||
*/
|
||||
public function delete(IShare $share) {
|
||||
public function delete(IShare $share): void {
|
||||
try {
|
||||
$this->createShareActivity($share, 'unshare');
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -820,7 +724,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function deleteFromSelf(IShare $share, $recipient) {
|
||||
public function deleteFromSelf(IShare $share, $recipient): void {
|
||||
// nothing to do here, mail shares are only outgoing shares
|
||||
}
|
||||
|
||||
|
|
@ -831,7 +735,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
|
||||
public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset): array {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('share');
|
||||
|
|
@ -887,7 +791,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getShareById($id, $recipientId = null) {
|
||||
public function getShareById($id, $recipientId = null): IShare {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
|
|
@ -915,10 +819,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* Get shares for a given path
|
||||
*
|
||||
* @param \OCP\Files\Node $path
|
||||
* @return IShare[]
|
||||
*/
|
||||
public function getSharesByPath(Node $path) {
|
||||
public function getSharesByPath(Node $path): array {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
$cursor = $qb->select('*')
|
||||
|
|
@ -939,7 +842,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
|
||||
public function getSharedWith($userId, $shareType, $node, $limit, $offset): array {
|
||||
/** @var IShare[] $shares */
|
||||
$shares = [];
|
||||
|
||||
|
|
@ -979,11 +882,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* Get a share by token
|
||||
*
|
||||
* @param string $token
|
||||
* @return IShare
|
||||
* @throws ShareNotFound
|
||||
*/
|
||||
public function getShareByToken($token) {
|
||||
public function getShareByToken($token): IShare {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
$cursor = $qb->select('*')
|
||||
|
|
@ -1009,8 +910,6 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* remove share from table
|
||||
*
|
||||
* @param int $shareId
|
||||
*/
|
||||
protected function removeShareFromTable(int $shareId): void {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
|
@ -1022,12 +921,10 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* Create a share object from an database row
|
||||
*
|
||||
* @param array $data
|
||||
* @return IShare
|
||||
* @throws InvalidShare
|
||||
* @throws ShareNotFound
|
||||
*/
|
||||
protected function createShareObject($data) {
|
||||
protected function createShareObject(array $data): IShare {
|
||||
$share = new Share($this->rootFolder, $this->userManager);
|
||||
$share->setId((int)$data['id'])
|
||||
->setShareType((int)$data['share_type'])
|
||||
|
|
@ -1078,12 +975,9 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* Get the node with file $id for $user
|
||||
*
|
||||
* @param string $userId
|
||||
* @param int $id
|
||||
* @return \OCP\Files\File|\OCP\Files\Folder
|
||||
* @throws InvalidShare
|
||||
*/
|
||||
private function getNode($userId, $id) {
|
||||
private function getNode(string $userId, int $id): Node {
|
||||
try {
|
||||
$userFolder = $this->rootFolder->getUserFolder($userId);
|
||||
} catch (NoUserException $e) {
|
||||
|
|
@ -1102,11 +996,8 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* A user is deleted from the system
|
||||
* So clean up the relevant shares.
|
||||
*
|
||||
* @param string $uid
|
||||
* @param int $shareType
|
||||
*/
|
||||
public function userDeleted($uid, $shareType) {
|
||||
public function userDeleted($uid, $shareType): void {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
|
||||
$qb->delete('share')
|
||||
|
|
@ -1117,29 +1008,22 @@ class ShareByMailProvider implements IShareProvider {
|
|||
|
||||
/**
|
||||
* This provider does not support group shares
|
||||
*
|
||||
* @param string $gid
|
||||
*/
|
||||
public function groupDeleted($gid) {
|
||||
public function groupDeleted($gid): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* This provider does not support group shares
|
||||
*
|
||||
* @param string $uid
|
||||
* @param string $gid
|
||||
*/
|
||||
public function userDeletedFromGroup($uid, $gid) {
|
||||
public function userDeletedFromGroup($uid, $gid): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* get database row of a give share
|
||||
*
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws ShareNotFound
|
||||
*/
|
||||
protected function getRawShare($id) {
|
||||
protected function getRawShare(int $id): array {
|
||||
// Now fetch the inserted share and create a complete share object
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
|
|
@ -1157,7 +1041,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
return $data;
|
||||
}
|
||||
|
||||
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
|
||||
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true): array {
|
||||
$qb = $this->dbConnection->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('share', 's')
|
||||
|
|
@ -1206,7 +1090,7 @@ class ShareByMailProvider implements IShareProvider {
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getAccessList($nodes, $currentAccess) {
|
||||
public function getAccessList($nodes, $currentAccess): array {
|
||||
$ids = [];
|
||||
foreach ($nodes as $node) {
|
||||
$ids[] = $node->getId();
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ use OCP\Files\IRootFolder;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
|
@ -54,6 +53,7 @@ use OCP\Security\IHasher;
|
|||
use OCP\Security\ISecureRandom;
|
||||
use OCP\Share\IManager;
|
||||
use OCP\Share\IShare;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -63,7 +63,6 @@ use Test\TestCase;
|
|||
* @group DB
|
||||
*/
|
||||
class ShareByMailProviderTest extends TestCase {
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l;
|
||||
|
||||
/** @var ILogger | \PHPUnit\Framework\MockObject\MockObject */
|
||||
/** @var LoggerInterface | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $logger;
|
||||
|
||||
/** @var IRootFolder | \PHPUnit\Framework\MockObject\MockObject */
|
||||
|
|
@ -123,7 +122,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->willReturnCallback(function ($text, $parameters = []) {
|
||||
return vsprintf($text, $parameters);
|
||||
});
|
||||
$this->logger = $this->getMockBuilder(ILogger::class)->getMock();
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
|
||||
$this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock();
|
||||
|
|
@ -210,19 +209,19 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
|
||||
$instance->expects($this->any())->method('sendPassword')->willReturn(true);
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
$this->shareManager->expects($this->any())->method('shareApiLinkEnforcePassword')->willReturn(false);
|
||||
$this->settingsManager->expects($this->any())->method('sendPasswordByMail')->willReturn(true);
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertInstanceOf(IShare::class, $instance->create($share));
|
||||
}
|
||||
|
||||
public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection() {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@examplelölöl.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
|
|
@ -236,8 +235,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($expectedShare);
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
// The autogenerated password should not be mailed.
|
||||
|
|
@ -247,9 +246,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
|
||||
$this->mailer->expects($this->never())->method('send');
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertSame($expectedShare, $instance->create($share));
|
||||
}
|
||||
|
||||
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword() {
|
||||
|
|
@ -266,8 +263,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
$share->expects($this->once())->method('getPassword')->willReturn('password');
|
||||
|
|
@ -280,9 +277,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->config->expects($this->once())->method('getSystemValue')->with('sharing.enable_mail_link_password_expiration')->willReturn(false);
|
||||
$instance->expects($this->never())->method('autoGeneratePassword');
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertInstanceOf(IShare::class, $instance->create($share));
|
||||
}
|
||||
|
||||
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword() {
|
||||
|
|
@ -299,8 +294,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
$share->expects($this->once())->method('getPassword')->willReturn('password');
|
||||
|
|
@ -321,9 +316,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
3600
|
||||
);
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertInstanceOf(IShare::class, $instance->create($share));
|
||||
}
|
||||
|
||||
public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword() {
|
||||
|
|
@ -348,8 +341,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
$share->expects($this->once())->method('getPassword')->willReturn(null);
|
||||
|
|
@ -373,9 +366,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
]);
|
||||
$this->mailer->expects($this->once())->method('send');
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertInstanceOf(IShare::class, $instance->create($share));
|
||||
}
|
||||
|
||||
public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword() {
|
||||
|
|
@ -392,8 +383,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
$share->expects($this->once())->method('getPassword')->willReturn('password');
|
||||
|
|
@ -419,9 +410,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
]);
|
||||
$this->mailer->expects($this->once())->method('send');
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertInstanceOf(IShare::class, $instance->create($share));
|
||||
}
|
||||
|
||||
public function testCreateSendPasswordByTalkWithEnforcedPasswordProtectionWithPermanentPassword() {
|
||||
|
|
@ -438,8 +427,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('getSharedWith')->willReturn([]);
|
||||
$instance->expects($this->once())->method('createMailShare')->with($share)->willReturn(42);
|
||||
$instance->expects($this->once())->method('createShareActivity')->with($share);
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn('rawShare');
|
||||
$instance->expects($this->once())->method('createShareObject')->with('rawShare')->willReturn('shareObject');
|
||||
$instance->expects($this->once())->method('getRawShare')->with(42)->willReturn(['rawShare']);
|
||||
$instance->expects($this->once())->method('createShareObject')->with(['rawShare'])->willReturn($this->createMock(IShare::class));
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
$share->expects($this->once())->method('getPassword')->willReturn(null);
|
||||
|
|
@ -469,9 +458,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$user->expects($this->once())->method('getDisplayName')->willReturn('Owner display name');
|
||||
$user->expects($this->once())->method('getEMailAddress')->willReturn('owner@example.com');
|
||||
|
||||
$this->assertSame('shareObject',
|
||||
$instance->create($share)
|
||||
);
|
||||
$this->assertInstanceOf(IShare::class, $instance->create($share));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -498,7 +485,9 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreateMailShare() {
|
||||
$this->share->expects($this->any())->method('getToken')->willReturn('token');
|
||||
$this->share->expects($this->once())->method('setToken')->with('token');
|
||||
$this->share->expects($this->any())->method('getSharedWith')->willReturn('valid@valid.com');
|
||||
$this->share->expects($this->any())->method('getSharedBy')->willReturn('validby@valid.com');
|
||||
$this->share->expects($this->any())->method('getSharedWith')->willReturn('validwith@valid.com');
|
||||
$this->share->expects($this->any())->method('getNote')->willReturn('Check this!');
|
||||
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
|
||||
$node->expects($this->any())->method('getName')->willReturn('fileName');
|
||||
$this->share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
|
@ -523,7 +512,9 @@ class ShareByMailProviderTest extends TestCase {
|
|||
|
||||
$this->share->expects($this->any())->method('getToken')->willReturn('token');
|
||||
$this->share->expects($this->once())->method('setToken')->with('token');
|
||||
$this->share->expects($this->any())->method('getSharedWith')->willReturn('valid@valid.com');
|
||||
$this->share->expects($this->any())->method('getSharedBy')->willReturn('validby@valid.com');
|
||||
$this->share->expects($this->any())->method('getSharedWith')->willReturn('validwith@valid.com');
|
||||
$this->share->expects($this->any())->method('getNote')->willReturn('Check this!');
|
||||
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
|
||||
$node->expects($this->any())->method('getName')->willReturn('fileName');
|
||||
$this->share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ class ProviderFactory implements IProviderFactory {
|
|||
$this->serverContainer->getUserManager(),
|
||||
$this->serverContainer->getLazyRootFolder(),
|
||||
$this->serverContainer->getL10N('sharebymail'),
|
||||
$this->serverContainer->getLogger(),
|
||||
$this->serverContainer->get(LoggerInterface::class),
|
||||
$this->serverContainer->getMailer(),
|
||||
$this->serverContainer->getURLGenerator(),
|
||||
$this->serverContainer->getActivityManager(),
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ use OCP\Files\IRootFolder;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Mail\IMailer;
|
||||
|
|
@ -43,6 +42,7 @@ use OCP\Security\IHasher;
|
|||
use OCP\Security\ISecureRandom;
|
||||
use OCP\Share\IShare;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
|
|
@ -79,7 +79,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
/** @var IConfig|MockObject */
|
||||
protected $config;
|
||||
|
||||
/** @var ILogger|MockObject */
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
|
||||
/** @var IHasher|MockObject */
|
||||
|
|
@ -108,7 +108,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->defaults = $this->getMockBuilder(Defaults::class)->disableOriginalConstructor()->getMock();
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->logger = $this->createMock(ILogger::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->activityManager = $this->createMock(\OCP\Activity\IManager::class);
|
||||
$this->settingsManager = $this->createMock(SettingsManager::class);
|
||||
$this->hasher = $this->createMock(IHasher::class);
|
||||
|
|
@ -162,8 +162,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
* @throws \OCP\DB\Exception
|
||||
*/
|
||||
private function addShareToDB($shareType, $sharedWith, $sharedBy, $shareOwner,
|
||||
$itemType, $fileSource, $fileTarget, $permissions, $token, $expiration,
|
||||
$parent) {
|
||||
$itemType, $fileSource, $fileTarget, $permissions, $token, $expiration,
|
||||
$parent) {
|
||||
$qb = $this->dbConn->getQueryBuilder();
|
||||
$qb->insert('share');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue