Fix tests

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2021-01-04 15:55:42 +01:00
parent 482a679cef
commit 08842d239e
7 changed files with 63 additions and 450 deletions

View File

@@ -118,7 +118,7 @@ class AttachmentService {
/** @var IAttachmentService $service */
$service = $this->getService($attachmentType);
if ($service instanceof ICustomAttachmentService) {
$attachments = array_merge($attachments, $service->listAttachments($cardId));
$attachments = array_merge($attachments, $service->listAttachments((int)$cardId));
}
}
@@ -151,7 +151,7 @@ class AttachmentService {
foreach (array_keys($this->services) as $attachmentType) {
$service = $this->getService($attachmentType);
if ($service instanceof ICustomAttachmentService) {
$count += $service->getAttachmentCount($cardId);
$count += $service->getAttachmentCount((int)$cardId);
}
}

View File

@@ -77,11 +77,11 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
$shares = array_filter($shares, function ($share) {
return $share->getPermissions() > 0;
});
return array_map(function (IShare $share) use ($cardId, $userFolder) {
return array_map(function (IShare $share) use ($cardId) {
$file = $share->getNode();
$attachment = new Attachment();
$attachment->setType('file');
$attachment->setId($share->getId());
$attachment->setId((int)$share->getId());
$attachment->setCardId($cardId);
$attachment->setCreatedBy($share->getSharedBy());
$attachment->setData($file->getName());
@@ -179,18 +179,16 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
throw new StatusException('Could not read file');
}
$target->putContent($content);
if (is_resource($content)) {
fclose($content);
}
fclose($content);
$share = $this->shareManager->newShare();
$share->setNode($target);
$share->setShareType(Share::SHARE_TYPE_DECK);
$share->setShareType(ISHARE::TYPE_DECK);
$share->setSharedWith((string)$attachment->getCardId());
$share->setPermissions(Constants::PERMISSION_READ);
$share->setSharedBy($this->userId);
$share = $this->shareManager->createShare($share);
$attachment->setId($share->getId());
$attachment->setId((int)$share->getId());
$attachment->setData($target->getName());
return $attachment;
}
@@ -237,9 +235,7 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
throw new StatusException('Could not read file');
}
$target->putContent($content);
if (is_resource($content)) {
fclose($content);
}
fclose($content);
$attachment->setLastModified(time());
return $attachment;
@@ -249,9 +245,6 @@ class FilesAppService implements IAttachmentService, ICustomAttachmentService {
$share = $this->shareProvider->getShareById($attachment->getId());
$file = $share->getNode();
$attachment->setData($file->getName());
if ($file === null) {
throw new NotFoundException('File not found');
}
if ($file->getOwner() !== null && $file->getOwner()->getUID() === $this->userId) {
$file->delete();

View File

@@ -114,7 +114,7 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
try {
$board = $this->boardMapper->find($boardId);
$valid &= !$board->getArchived();
$valid = $valid && !$board->getArchived();
} catch (DoesNotExistException | MultipleObjectsReturnedException $e) {
$valid = false;
}
@@ -234,7 +234,7 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
*/
private function createShareObject(array $data): IShare {
$share = $this->shareManager->newShare();
$share->setId((int)$data['id'])
$share->setId($data['id'])
->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions'])
->setTarget($data['file_target'])
@@ -401,7 +401,7 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
$qb->execute();
return $this->getShareById($share->getId(), $recipient);
return $this->getShareById((int)$share->getId(), $recipient);
}
/**
@@ -456,6 +456,7 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
/**
* @inheritDoc
* @returns
*/
public function getSharesInFolder($userId, Folder $node, $reshares) {
$qb = $this->dbConnection->getQueryBuilder();
@@ -755,14 +756,13 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
/**
* Get shared with the card
*
* @param string $userId get shares where this user is the recipient
* @param int $cardId
* @param int $shareType
* @param Node|null $node
* @param int $limit The max number of entries returned, -1 for all
* @param int $offset
* @return IShare[]
*/
public function getSharedWithByType(string $cardId, int $shareType, $limit, $offset): array {
public function getSharedWithByType(int $cardId, int $shareType, $limit, $offset): array {
/** @var IShare[] $shares */
$shares = [];

View File

@@ -32,6 +32,7 @@ use OCA\Deck\NoPermissionException;
use OCA\Deck\Service\PermissionService;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Share\IShare;
@@ -40,12 +41,14 @@ class ShareAPIHelper {
private $timeFactory;
private $cardMapper;
private $permissionService;
private $l10n;
public function __construct(IURLGenerator $urlGenerator, ITimeFactory $timeFactory, CardMapper $cardMapper, PermissionService $permissionService) {
public function __construct(IURLGenerator $urlGenerator, ITimeFactory $timeFactory, CardMapper $cardMapper, PermissionService $permissionService, IL10N $l10n) {
$this->urlGenerator = $urlGenerator;
$this->timeFactory = $timeFactory;
$this->cardMapper = $cardMapper;
$this->permissionService = $permissionService;
$this->l10n = $l10n;
}
public function formatShare(IShare $share): array {
@@ -67,7 +70,7 @@ class ShareAPIHelper {
$expireDate = $this->parseDate($expireDate);
$share->setExpirationDate($expireDate);
} catch (\Exception $e) {
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
throw new OCSNotFoundException($this->l10n->t('Invalid date, date format must be YYYY-MM-DD'));
}
}
}
@@ -90,10 +93,6 @@ class ShareAPIHelper {
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
}
if ($date === false) {
throw new \Exception('Invalid date. Format must be YYYY-MM-DD');
}
$date->setTime(0, 0, 0);
return $date;