Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make compatible with app guests #2462

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions lib/Service/FolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUser;

Expand All @@ -43,6 +44,7 @@ public function __construct(
private IRootFolder $root,
private IUserMountCache $userMountCache,
protected IAppDataFactory $appDataFactory,
protected IGroupManager $groupManager,
private IAppConfig $appConfig,
private IL10N $l10n,
private ?string $userId,
Expand Down Expand Up @@ -91,14 +93,26 @@ public function getFolder(int $nodeId = null): Folder {
*/
private function getOrCreateFolder(): Folder {
$path = $this->getLibreSignDefaultPath();
$withoutPermission = false;
if ($this->getUserId()) {
$containerFolder = $this->root->getUserFolder($this->getUserId());
// TODO: retrieve guest group name from app once exposed
if ($this->groupManager->isInGroup($this->getUserId(), 'guest_app')) {
$withoutPermission = true;
} elseif (!$containerFolder->isUpdateable()) {
$withoutPermission = true;
}
} else {
$withoutPermission = true;
}
if ($withoutPermission) {
$containerFolder = $this->appData->getFolder('/');
$reflection = new \ReflectionClass($containerFolder);
$reflectionProperty = $reflection->getProperty('folder');
$reflectionProperty->setAccessible(true);
$containerFolder = $reflectionProperty->getValue($containerFolder);
} else {
$containerFolder = $this->root->getUserFolder($this->getUserId());
}
if ($containerFolder->nodeExists($path)) {
$folder = $containerFolder->get($path);
Expand All @@ -115,6 +129,10 @@ public function getLibreSignDefaultPath(): string {
if (!$this->userId) {
return 'unauthenticated';
}
// TODO: retrieve guest group name from app once exposed
if ($this->groupManager->isInGroup($this->getUserId(), 'guest_app')) {
return 'guest_app/' . $this->getUserId();
}
$path = $this->appConfig->getUserValue($this->userId, 'folder');

if (empty($path)) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Service/FolderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\IRootFolder;
use OCP\IGroupManager;
use OCP\IL10N;

final class FolderServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
Expand All @@ -21,13 +22,15 @@ public function testGetFolderWithInvalidNodeId() {
->method('getMountsForFileId')
->willreturn([]);
$appDataFactory = $this->createMock(IAppDataFactory::class);
$groupManager = $this->createMock(IGroupManager::class);
$appConfig = $this->createMock(IAppConfig::class);
$l10n = $this->createMock(IL10N::class);

$service = new FolderService(
$root,
$userMountCache,
$appDataFactory,
$groupManager,
$appConfig,
$l10n,
171
Expand All @@ -49,13 +52,15 @@ public function testGetFolderWithValidNodeId() {
$root->method('getById')
->willReturn([$node]);
$appDataFactory = $this->createMock(IAppDataFactory::class);
$groupManager = $this->createMock(IGroupManager::class);
$appConfig = $this->createMock(IAppConfig::class);
$l10n = $this->createMock(IL10N::class);

$service = new FolderService(
$root,
$userMountCache,
$appDataFactory,
$groupManager,
$appConfig,
$l10n,
1
Expand Down
Loading