-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
- Loading branch information
Showing
7 changed files
with
181 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Service\File; | ||
|
||
use OC\User\NoUserException; | ||
use OCP\Constants; | ||
use OCP\Files\File; | ||
use OCP\Files\InvalidPathException; | ||
use OCP\Files\IRootFolder; | ||
use OCP\Files\Node; | ||
use OCP\Files\NotFoundException; | ||
use OCP\Files\NotPermittedException; | ||
|
||
final class GetFileFromIdService implements GetFileService { | ||
public function __construct( | ||
private IRootFolder $rootFolder, | ||
Check failure on line 23 in lib/Service/File/GetFileFromIdService.php GitHub Actions / static-psalm-analysisMissingDependency
|
||
private string $userId, | ||
private int $fileId | ||
) { | ||
} | ||
|
||
/** | ||
* @throws NotFoundException | ||
* @throws NotPermittedException | ||
* @throws NoUserException | ||
Check failure on line 32 in lib/Service/File/GetFileFromIdService.php GitHub Actions / static-psalm-analysisUndefinedDocblockClass
|
||
* @throws InvalidPathException | ||
*/ | ||
public function getFile(): File { | ||
$userFolder = $this->rootFolder->getUserFolder($this->userId); | ||
Check failure on line 36 in lib/Service/File/GetFileFromIdService.php GitHub Actions / static-psalm-analysisMissingDependency
|
||
|
||
$file = $userFolder->getFirstNodeById($this->fileId); | ||
if ($file instanceof File && $file->getPermissions() & Constants::PERMISSION_UPDATE) { | ||
return $file; | ||
} | ||
|
||
$files = $userFolder->getById($this->fileId); | ||
if (empty($files)) { | ||
throw new NotFoundException('File not found'); | ||
} | ||
|
||
usort($files, static function (Node $a, Node $b) { | ||
return ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE); | ||
}); | ||
|
||
$file = $files[0]; | ||
if (!$file instanceof File) { | ||
throw new NotFoundException('Not a file'); | ||
} | ||
|
||
if (!($file->getPermissions() & Constants::PERMISSION_READ)) { | ||
throw new NotPermittedException('No read permission'); | ||
} | ||
|
||
return $file; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Service\File; | ||
|
||
use InvalidArgumentException; | ||
use OCP\Files\File; | ||
use OCP\Files\NotFoundException; | ||
use OCP\Share\Exceptions\ShareNotFound; | ||
use OCP\Share\IManager as ShareManager; | ||
|
||
final class GetFileFromPublicSharingTokenService implements GetFileService { | ||
public function __construct( | ||
private ShareManager $shareManager, | ||
private string $publicSharingToken | ||
) { | ||
} | ||
|
||
/** | ||
* @throws NotFoundException | ||
*/ | ||
public function getFile(): File { | ||
try { | ||
$share = $this->shareManager->getShareByToken($this->publicSharingToken); | ||
} catch (ShareNotFound) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
$node = $share->getNode(); | ||
|
||
if ($node instanceof File) { | ||
return $node; | ||
} | ||
|
||
throw new InvalidArgumentException('No proper share data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Service\File; | ||
|
||
use OCP\Files\File; | ||
|
||
interface GetFileService { | ||
public function getFile(): File; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Service\File; | ||
|
||
use OCA\Whiteboard\Exception\InvalidUserException; | ||
use OCA\Whiteboard\Model\AuthenticatedUser; | ||
use OCA\Whiteboard\Model\PublicSharingUser; | ||
use OCA\Whiteboard\Model\User; | ||
use OCP\Files\IRootFolder; | ||
use OCP\Share\IManager as ShareManager; | ||
|
||
final class GetFileServiceFactory { | ||
public function __construct( | ||
private IRootFolder $rootFolder, | ||
Check failure on line 21 in lib/Service/File/GetFileServiceFactory.php GitHub Actions / static-psalm-analysisMissingDependency
|
||
private ShareManager $shareManager | ||
) { | ||
} | ||
|
||
public function create(User $user, int $fileId): GetFileService { | ||
if ($user instanceof AuthenticatedUser) { | ||
return new GetFileFromIdService($this->rootFolder, $user->getUID(), $fileId); | ||
} | ||
|
||
if ($user instanceof PublicSharingUser) { | ||
return new GetFileFromPublicSharingTokenService($this->shareManager, $user->getPublicSharingToken()); | ||
} | ||
|
||
throw new InvalidUserException(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.