Skip to content

Commit

Permalink
feat(pages): Don't revert subfolders for leaf pages
Browse files Browse the repository at this point in the history
We no longer change `page/Readme.md` back to `page.md` if `page` becomes
a leaf page (i.e. without children). In the long term we want to move to
the `page/Readme.md` format everywhere.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Dec 18, 2023
1 parent 8a6d0d2 commit a482f19
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 62 deletions.
28 changes: 0 additions & 28 deletions lib/Fs/NodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,32 +264,4 @@ public static function folderHasSubPage(Folder $folder, string $title): int {

return 0;
}

/**
* @param Folder $folder
*
* @throws NotFoundException
* @throws NotPermittedException
*/
public static function revertSubFolders(Folder $folder): void {
try {
foreach ($folder->getDirectoryListing() as $node) {
if ($node instanceof Folder) {
self::revertSubFolders($node);
} elseif ($node instanceof File) {
// Move index page without subpages into the parent folder (if's not the landing page)
if (self::isIndexPage($node) && !self::isLandingPage($node) && !self::indexPageHasOtherContent($node)) {
$filename = self::generateFilename($folder, $folder->getName(), PageInfo::SUFFIX);
$node->move($folder->getParent()->getPath() . '/' . $filename . PageInfo::SUFFIX);
$folder->delete();
break;
}
}
}
} catch (FilesNotFoundException | InvalidPathException $e) {
throw new NotFoundException($e->getMessage(), 0, $e);
} catch (FilesNotPermittedException | LockedException $e) {
throw new NotPermittedException($e->getMessage(), 0, $e);
}
}
}
5 changes: 0 additions & 5 deletions lib/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,6 @@ public function move(int $collectiveId, int $id, ?int $parentId, ?string $title,
// Page got moved: remove from subpage order of old parent page, add to new
$this->removeFromSubpageOrder($collectiveId, $oldParentId, $id, $userId);
$this->addToSubpageOrder($collectiveId, $parentId, $file->getId(), $index, $userId);

NodeHelper::revertSubFolders($collectiveFolder);
}

return $this->getPageByFile($file);
Expand Down Expand Up @@ -916,8 +914,6 @@ public function moveToCollective(int $collectiveId, int $id, int $newCollectiveI

$this->removeFromSubpageOrder($collectiveId, $oldParentId, $id, $userId);
$this->addToSubpageOrder($newCollectiveId, $parentId, $file->getId(), $index, $userId);

NodeHelper::revertSubFolders($collectiveFolder);
}

/**
Expand Down Expand Up @@ -1066,7 +1062,6 @@ public function trash(int $collectiveId, int $id, string $userId): PageInfo {
// Delete directly if trash is not available
$this->pageMapper->deleteByFileId($id);
$this->removeFromSubpageOrder($collectiveId, $parentId, $id, $userId);
NodeHelper::revertSubFolders($folder);
$this->notifyPush($collectiveId, $userId);
return $pageInfo;
}
Expand Down
19 changes: 0 additions & 19 deletions lib/Trash/PageTrashBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,6 @@ public function removeItem(ITrashItem $item): void {
throw new NotFoundException();
}

// Get original parent folder of item to revert subfolders further down
$collectiveFolder = $this->collectiveFolderManager->getFolder($collectiveId);
$targetFolderPath = substr($item->getOriginalLocation(), 0, -strlen($item->getName()));
if ($targetFolderPath) {
try {
$targetFolder = $collectiveFolder->get($targetFolderPath);
} catch (NotFoundException $e) {
$targetFolder = null;
}
}

// Get pageId for deleting page from collective page database
$deletePageId = $node->getId();
if ($node instanceof Folder) {
Expand Down Expand Up @@ -257,14 +246,6 @@ public function removeItem(ITrashItem $item): void {
if (null !== $attachmentsFolderItem = $this->findAttachmentFolderItem($user, $collectiveId, $item)) {
$this->removeItem($attachmentsFolderItem);
}

// Try to revert subfolders of target folder parent
if ($targetFolder && $targetFolder->getId() !== $collectiveFolder->getId()) {
try {
NodeHelper::revertSubFolders($targetFolder->getParent());
} catch (\OCA\Collectives\Service\NotFoundException | \OCA\Collectives\Service\NotPermittedException $e) {
}
}
}

/**
Expand Down
10 changes: 0 additions & 10 deletions tests/Integration/features/pages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ Feature: pages
And user "jane" doesn't see pagePath "parentpage/Readme.md" in "BehatPagesCollective"
Then user "jane" restores page "parentpage" from trash in "BehatPagesCollective"

Scenario: Trash and delete all subpages reverts subfolders
When user "jane" trashes page "subpage" in "BehatPagesCollective"
And user "jane" trashes page "subpage2" in "BehatPagesCollective"
And user "jane" trashes page "subpage3" in "BehatPagesCollective"
When user "jane" deletes page "subpage" from trash in "BehatPagesCollective"
When user "jane" deletes page "subpage2" from trash in "BehatPagesCollective"
When user "jane" deletes page "subpage3" from trash in "BehatPagesCollective"
Then user "jane" doesn't see pagePath "parentpage/Readme.md" in "BehatPagesCollective"
And user "jane" sees pagePath "parentpage.md" in "BehatPagesCollective"

Scenario: Fail to edit pages in read-only collective
When user "john" joins circle "BehatPagesCollective" with owner "jane"
And user "jane" sets "edit" level in collective "BehatPagesCollective" to "Admin"
Expand Down

0 comments on commit a482f19

Please sign in to comment.