Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
be769f4
Add collectives trash backend provider to files_trashbin
mejo- Apr 12, 2023
cecd019
Trash pages instead of deleting them when files_trashbin is enabled
mejo- May 19, 2023
e8978f4
Allow to restore/delete pages from trash via Collectives API
mejo- May 19, 2023
46874d2
Refactor: move node-related functions from PageService to NodeHelper
mejo- May 19, 2023
88042dd
Add behat tests for page trash
mejo- May 19, 2023
a19e0f7
Remove versions along with pages
mejo- May 22, 2023
d8bb2f7
Delete trash and versions when deleting a collective
mejo- May 22, 2023
8b6ac69
Add behat tests for collectives trash over webdav API
mejo- May 23, 2023
cb18b01
Revert subfolders of parent page when deleting from trash
mejo- May 24, 2023
6300d97
Don't grant access to trash of read-only collectives
mejo- May 24, 2023
bcac981
Restore attachments folder along with page if it exists
mejo- May 24, 2023
c089e16
Restore+remove attachments folder from trash along with page
mejo- May 24, 2023
e310a12
Add behat tests for page trash API in public shares
mejo- May 24, 2023
ea037d5
Add fixes detected by psalm
mejo- May 24, 2023
f935a7c
Call notifyPush when trashing a page also without files_trashbin
mejo- May 25, 2023
b894a77
Delete collective leftovers even if collective folder is already gone
mejo- May 25, 2023
235b4aa
Improve exception message when trashed page not found in database
mejo- May 25, 2023
93c8d63
Also return full PageInfo objects for page trash index
mejo- May 27, 2023
14967ef
Fix handling of deleted pages with subpages
mejo- May 30, 2023
d3a46c4
PageTrashCleanup: Different return values for different failure reasons
mejo- Jun 5, 2023
710a616
Code style fixes by php-cs-fixer
mejo- Jun 5, 2023
34b080a
Make sure long filenames are truncated in trashbin
mejo- Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add fixes detected by psalm
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Jun 5, 2023
commit ea037d5ef46806accf8fede97ca58521e9055f9b
4 changes: 2 additions & 2 deletions lib/Command/PageTrashCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace OCA\Collectives\Command;

use OC\App\AppManager;
use OC\Core\Command\Base;
use OCA\Collectives\Db\CollectiveMapper;
use OCA\Collectives\Service\MissingDependencyException;
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\NotPermittedException;
use OCA\Collectives\Trash\PageTrashBackend;
use OCP\App\IAppManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -22,7 +22,7 @@ class PageTrashCleanup extends Base {
private CollectiveMapper $collectiveMapper;

public function __construct(
AppManager $appManager,
IAppManager $appManager,
CollectiveMapper $collectiveMapper
) {
parent::__construct();
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/CollectiveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OCA\Collectives\Service;

use OC\App\AppManager;
use OC\Files\Node\File;
use OCA\Circles\Model\Member;
use OCA\Collectives\Db\Collective;
Expand All @@ -15,6 +14,7 @@
use OCA\Collectives\Mount\CollectiveFolderManager;
use OCA\Collectives\Trash\PageTrashBackend;
use OCA\Collectives\Versions\VersionsBackend;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\InvalidPathException;
Expand All @@ -23,7 +23,7 @@
use OCP\IL10N;

class CollectiveService extends CollectiveServiceBase {
private AppManager $appManager;
private IAppManager $appManager;
private CollectiveHelper $collectiveHelper;
private CollectiveFolderManager $collectiveFolderManager;
private CollectiveShareService $shareService;
Expand All @@ -35,7 +35,7 @@ class CollectiveService extends CollectiveServiceBase {
private ?VersionsBackend $pageVersionsBackend = null;

/**
* @param AppManager $appManager
* @param IAppManager $appManager
* @param CollectiveMapper $collectiveMapper
* @param CollectiveHelper $collectiveHelper
* @param CollectiveFolderManager $collectiveFolderManager
Expand All @@ -47,7 +47,7 @@ class CollectiveService extends CollectiveServiceBase {
* @param IEventDispatcher $eventDispatcher
*/
public function __construct(
AppManager $appManager,
IAppManager $appManager,
CollectiveMapper $collectiveMapper,
CollectiveHelper $collectiveHelper,
CollectiveFolderManager $collectiveFolderManager,
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OCA\Collectives\Service;

use OC\App\AppManager;
use OCA\Collectives\Db\Page;
use OCA\Collectives\Db\PageMapper;
use OCA\Collectives\Fs\NodeHelper;
Expand All @@ -11,6 +10,7 @@
use OCA\Collectives\Model\PageInfo;
use OCA\Collectives\Trash\PageTrashBackend;
use OCA\NotifyPush\Queue\IQueue;
use OCP\App\IAppManager;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\InvalidPathException;
Expand All @@ -25,7 +25,7 @@
class PageService {
private const DEFAULT_PAGE_TITLE = 'New Page';

private AppManager $appManager;
private IAppManager $appManager;
private PageMapper $pageMapper;
private NodeHelper $nodeHelper;
private CollectiveServiceBase $collectiveService;
Expand All @@ -37,7 +37,7 @@ class PageService {
private ?PageTrashBackend $trashBackend = null;

/**
* @param AppManager $appManager
* @param IAppManager $appManager
* @param PageMapper $pageMapper
* @param NodeHelper $nodeHelper
* @param CollectiveServiceBase $collectiveService
Expand All @@ -46,7 +46,7 @@ class PageService {
* @param IConfig $config
* @param ContainerInterface $container
*/
public function __construct(AppManager $appManager,
public function __construct(IAppManager $appManager,
PageMapper $pageMapper,
NodeHelper $nodeHelper,
CollectiveServiceBase $collectiveService,
Expand Down Expand Up @@ -410,7 +410,7 @@ public function findAll(int $collectiveId, string $userId): array {
* @param int $collectiveId
* @param string $userId
*
* @return PageInfo[]
* @return array[]
* @throws MissingDependencyException
* @throws NotFoundException
* @throws NotPermittedException
Expand Down
29 changes: 15 additions & 14 deletions lib/Trash/PageTrashBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Files_Trashbin\Expiration;
use OCA\Files_Trashbin\Trash\ITrashBackend;
use OCA\Files_Trashbin\Trash\ITrashItem;
use OCA\Files_Trashbin\Trash\TrashItem;
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Files\InvalidPathException;
Expand Down Expand Up @@ -67,7 +68,7 @@ public function setVersionsBackend(VersionsBackend $versionsBackend): void {
/**
* @param IUser $user
*
* @return array|ITrashItem[]
* @return array|CollectivePageTrashItem[]
* @throws NotFoundException
* @throws NotPermittedException
*/
Expand All @@ -79,7 +80,7 @@ public function listTrashRoot(IUser $user): array {
/**
* @param ITrashItem $trashItem
*
* @return array|ITrashItem[]
* @return array|TrashItem[]
* @throws NotFoundException
* @throws NotPermittedException
*/
Expand Down Expand Up @@ -231,14 +232,14 @@ public function removeItem(ITrashItem $item): void {
}

/**
* @param IUser $user
* @param int $collectiveId
* @param ITrashItem $item
* @param IUser $user
* @param int $collectiveId
* @param CollectivePageTrashItem $item
*
* @return ITrashItem|null
* @return TrashItem|null
* @throws NotPermittedException
*/
private function findAttachmentFolderItem(IUser $user, int $collectiveId, ITrashItem $item): ?ITrashItem {
private function findAttachmentFolderItem(IUser $user, int $collectiveId, CollectivePageTrashItem $item): ?TrashItem {
$attachmentsPrefix = ".attachments.";
if (strpos($item->getName(), $attachmentsPrefix) === 0) {
// Passed item is already an attachment folder
Expand Down Expand Up @@ -336,12 +337,12 @@ private function userHasAccessToFolder(IUser $user, int $collectiveId): bool {

/**
* @param IUser $user
* @param ITrashItem $trashItem
* @param TrashItem $trashItem
*
* @return Node|null
* @throws NotPermittedException
*/
private function getNodeForTrashItem(IUser $user, ITrashItem $trashItem): ?Node {
private function getNodeForTrashItem(IUser $user, TrashItem $trashItem): ?Node {
[, $collectiveId, $path] = explode('/', $trashItem->getTrashPath(), 3);
if (!$this->userHasAccessToFolder($user, (int)$collectiveId)) {
throw new NotPermittedException('No permission to trash for collective');
Expand Down Expand Up @@ -384,7 +385,7 @@ private function getTrashRoot(): Folder {
*/
private function getTrashFolder(int $collectiveId): Folder {
try {
$folder = $this->getTrashRoot()->get($collectiveId);
$folder = $this->getTrashRoot()->get((string)$collectiveId);
if (!$folder instanceof Folder) {
throw new NotPermittedException('Trash root is not a folder');
}
Expand Down Expand Up @@ -429,7 +430,7 @@ private function getTrashForFolders(IUser $user, array $folders): array {
$key = $collectiveId . '/' . $name . '/' . $timestamp;
$originalLocation = isset($indexedRows[$key]) ? $indexedRows[$key]['original_location'] : '';

if (null !== $info = $item->getFileInfo()) {
if (method_exists($item, 'getFileInfo') && null !== $info = $item->getFileInfo()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocker, but in general it seems that's method that would be good to have exposed in the API, on the server, no?

$info['name'] = $name;
$items[] = new CollectivePageTrashItem(
$this,
Expand Down Expand Up @@ -473,10 +474,10 @@ public function getTrashNodeById(IUser $user, int $fileId): ?Node {
* @param int $collectiveId
* @param int $fileId
*
* @return ITrashItem|null
* @return TrashItem|null
* @throws NotPermittedException
*/
public function getTrashItemByCollectiveAndId(IUser $user, int $collectiveId, int $fileId): ?ITrashItem {
public function getTrashItemByCollectiveAndId(IUser $user, int $collectiveId, int $fileId): ?TrashItem {
try {
if (!$this->userHasAccessToFolder($user, (int)$collectiveId)) {
return null;
Expand All @@ -486,7 +487,7 @@ public function getTrashItemByCollectiveAndId(IUser $user, int $collectiveId, in
$trashFolder = $this->getTrashFolder($collectiveId);
$trashNode = $this->getTrashNodeById($user, $fileId);
$trashItem = $this->trashManager->getTrashItemByFileId($fileId);
if ($trashItem && $trashNode) {
if ($trashItem && $trashNode && method_exists($trashNode, 'getFileInfo')) {
$pathParts = pathinfo($trashNode->getName());
$name = $pathParts['filename'];

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Service/CollectiveServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Unit\Service;

use OC\App\AppManager;
use OC\Files\Node\File;
use OC\Files\Node\Folder;
use OCA\Circles\Model\Circle;
Expand All @@ -20,6 +19,7 @@
use OCA\Collectives\Service\CollectiveShareService;
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\UnprocessableEntityException;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IL10N;
use PHPUnit\Framework\TestCase;
Expand All @@ -33,7 +33,7 @@ class CollectiveServiceTest extends TestCase {
private CollectiveService $service;

protected function setUp(): void {
$appManager = $this->getMockBuilder(AppManager::class)
$appManager = $this->getMockBuilder(IAppManager::class)
->disableOriginalConstructor()
->getMock();

Expand Down
55 changes: 55 additions & 0 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,61 @@ namespace OCA\Files_Versions {
}
}

namespace OCA\Files_Trashbin {
class Expiration {
/**
* @param int $timestamp
* @param bool $quotaExceeded
* @return bool
*/
public function isExpired($timestamp, $quotaExceeded = false) {}
}
}

namespace OCA\Files_Trashbin\Trash {
interface ITrashBackend {}

use OCP\Files\FileInfo;
interface ITrashItem extends FileInfo {
}

use OCP\IUser;
class TrashItem implements ITrashItem {
public function getOriginalLocation(): string {}
public function getDeletedTime(): int {}
public function getTrashPath(): string {}
public function getTrashPath(): string {}
public function getUser(): IUser {}
public function getEtag() {}
public function getSize($includeMounts = true) {}
public function getMtime() {}
public function getName() {}
public function getInternalPath() {}
public function getPath() {}
public function getMimetype() {}
public function getMimePart() {}
public function getStorage() {}
public function getId() {}
public function isEncrypted() {}
public function getPermissions() {}
public function getType() {}
public function isReadable() {}
public function isUpdateable() {}
public function isCreatable() {}
public function isDeletable() {}
public function isShareable() {}
public function isShared() {}
public function isMounted() {}
public function getMountPoint() {}
public function getOwner() {}
public function getChecksum() {}
public function getExtension(): string {}
public function getTitle(): string {}
public function getCreationTime(): int {}
public function getUploadTime(): int {}
}
}

namespace OCP\Files\Mount {
interface ISystemMountPoint {}
}