Skip to content

Commit bb5862e

Browse files
committed
fix: real types for folders
Signed-off-by: Robin Appelman <[email protected]>
1 parent e61c7e8 commit bb5862e

40 files changed

+711
-661
lines changed

β€Žlib/ACL/ACLManager.phpβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use OCA\GroupFolders\Trash\TrashManager;
1313
use OCP\Cache\CappedMemoryCache;
1414
use OCP\Constants;
15-
use OCP\Files\IRootFolder;
1615
use OCP\IUser;
1716
use Psr\Log\LoggerInterface;
1817
use RuntimeException;
@@ -111,6 +110,8 @@ private function getRelevantPaths(string $path): array {
111110
if ($separatorPos === false) {
112111
throw new RuntimeException('Invalid trash item name ' . $rootTrashedItemName);
113112
}
113+
$rootTrashedItemDate = (int)substr($rootTrashedItemName, $separatorPos + 2);
114+
$rootTrashedItemName = substr($rootTrashedItemName, 0, $separatorPos);
114115
}
115116

116117
while ($path !== '') {

β€Žlib/ACL/RuleManager.phpβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,21 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP
110110

111111
/**
112112
* @param int[] $fileIds
113-
* @return array<int, Rule[]>
113+
* @return array<string, Rule[]>
114114
*/
115115
public function getRulesForFilesByIds(IUser $user, array $fileIds): array {
116116
$userMappings = $this->userMappingManager->getMappingsForUser($user);
117117

118118
$rows = [];
119119
foreach (array_chunk($fileIds, 1000) as $chunk) {
120120
$query = $this->connection->getQueryBuilder();
121-
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
121+
$query->select(['f.fileid', 'a.mapping_type', 'a.mapping_id', 'a.mask', 'a.permissions', 'f.path'])
122122
->from('filecache', 'f')
123123
->leftJoin('f', 'group_folders_acl', 'a', $query->expr()->eq('f.fileid', 'a.fileid'))
124124
->where($query->expr()->in('f.fileid', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)))
125125
->andWhere($query->expr()->orX(...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
126-
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
127-
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
126+
$query->expr()->eq('a.mapping_type', $query->createNamedParameter($userMapping->getType())),
127+
$query->expr()->eq('a.mapping_id', $query->createNamedParameter($userMapping->getId()))
128128
), $userMappings)));
129129

130130
$rows = array_merge($rows, $query->executeQuery()->fetchAll());

β€Žlib/AppInfo/Application.phpβ€Ž

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
1616
use OCA\Files_Trashbin\Expiration;
1717
use OCA\GroupFolders\ACL\ACLManagerFactory;
18-
use OCA\GroupFolders\ACL\RuleManager;
1918
use OCA\GroupFolders\ACL\UserMapping\IUserMappingManager;
2019
use OCA\GroupFolders\ACL\UserMapping\UserMappingManager;
2120
use OCA\GroupFolders\AuthorizedAdminSettingMiddleware;
@@ -216,19 +215,6 @@ public function register(IRegistrationContext $context): void {
216215
return new ExpireGroupPlaceholder($c->get(ITimeFactory::class));
217216
});
218217

219-
$context->registerService(ACLManagerFactory::class, function (ContainerInterface $c): ACLManagerFactory {
220-
$rootFolderProvider = fn (): \OCP\Files\IRootFolder => $c->get(IRootFolder::class);
221-
222-
return new ACLManagerFactory(
223-
$c->get(RuleManager::class),
224-
$c->get(TrashManager::class),
225-
$c->get(IAppConfig::class),
226-
$c->get(LoggerInterface::class),
227-
$c->get(IUserMappingManager::class),
228-
$rootFolderProvider
229-
);
230-
});
231-
232218
$context->registerServiceAlias(IUserMappingManager::class, UserMappingManager::class);
233219

234220
$context->registerMiddleware(AuthorizedAdminSettingMiddleware::class);

β€Žlib/BackgroundJob/ExpireGroupVersions.phpβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\GroupFolders\BackgroundJob;
1010

1111
use OCA\GroupFolders\AppInfo\Application;
12+
use OCA\GroupFolders\Folder\FolderDefinition;
1213
use OCA\GroupFolders\Folder\FolderManager;
1314
use OCA\GroupFolders\Versions\GroupVersionsExpireManager;
1415
use OCP\AppFramework\Utility\ITimeFactory;
@@ -39,7 +40,7 @@ public function __construct(
3940
*/
4041
protected function run(mixed $argument): void {
4142
$lastFolder = $this->appConfig->getValueInt(Application::APP_ID, 'cron_last_folder_index', 0);
42-
$folders = $this->folderManager->getAllFolders();
43+
$folders = $this->folderManager->getAllFoldersWithSize();
4344

4445
$folderCount = count($folders);
4546
$currentRunHour = (int)date('G', $this->time->getTime());
@@ -63,7 +64,7 @@ protected function run(mixed $argument): void {
6364

6465
// Determine the set of folders to process
6566
$folderSet = array_slice($folders, $lastFolder, $toDo);
66-
$folderIDs = array_map(fn (array $folder): int => $folder['id'], $folderSet);
67+
$folderIDs = array_map(fn (FolderDefinition $folder): int => $folder->id, $folderSet);
6768

6869
// Log and start the expiration process
6970
$this->logger->debug('Expiring versions for ' . count($folderSet) . ' folders', ['app' => 'cron', 'folders' => $folderIDs]);

β€Žlib/Command/ACL.phpβ€Ž

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use OCA\GroupFolders\ACL\Rule;
1313
use OCA\GroupFolders\ACL\RuleManager;
1414
use OCA\GroupFolders\ACL\UserMapping\UserMapping;
15+
use OCA\GroupFolders\Folder\FolderDefinition;
16+
use OCA\GroupFolders\Folder\FolderDefinitionWithPermissions;
1517
use OCA\GroupFolders\Folder\FolderManager;
1618
use OCA\GroupFolders\Mount\MountProvider;
1719
use OCP\Constants;
@@ -61,9 +63,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6163
}
6264

6365
if ($input->getOption('enable')) {
64-
$this->folderManager->setFolderACL($folder['id'], true);
66+
$this->folderManager->setFolderACL($folder->id, true);
6567
} elseif ($input->getOption('disable')) {
66-
$this->folderManager->setFolderACL($folder['id'], false);
68+
$this->folderManager->setFolderACL($folder->id, false);
6769
} elseif ($input->getOption('test')) {
6870
if ($input->getOption('user') && ($input->getArgument('path'))) {
6971
$mappingId = $input->getOption('user');
@@ -73,13 +75,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7375
return -1;
7476
}
7577

76-
$jailPath = $this->mountProvider->getJailPath((int)$folder['id']);
78+
$jailPath = $this->mountProvider->getJailPath($folder->id);
7779
$path = $input->getArgument('path');
7880
$aclManager = $this->aclManagerFactory->getACLManager($user);
79-
if ($this->folderManager->getFolderPermissionsForUser($user, $folder['id']) === 0) {
81+
if ($this->folderManager->getFolderPermissionsForUser($user, $folder->id) === 0) {
8082
$permissions = 0;
8183
} else {
82-
$permissions = $aclManager->getACLPermissionsForPath($folder['storage_id'], $jailPath . rtrim('/' . $path, '/'));
84+
$permissions = $aclManager->getACLPermissionsForPath($folder->storageId, $jailPath . rtrim('/' . $path, '/'));
8385
}
8486
$permissionString = Rule::formatRulePermissions(Constants::PERMISSION_ALL, $permissions);
8587
$output->writeln($permissionString);
@@ -89,8 +91,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8991
$output->writeln('<error>--user and <path> options needs to be set for permissions testing</error>');
9092
return -3;
9193
}
92-
} elseif (!$folder['acl']) {
93-
$output->writeln('<error>Advanced permissions not enabled for folder: ' . $folder['id'] . '</error>');
94+
} elseif (!$folder->acl) {
95+
$output->writeln('<error>Advanced permissions not enabled for folder: ' . $folder->id . '</error>');
9496
return -2;
9597
} elseif (
9698
!$input->getArgument('path')
@@ -102,10 +104,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102104
$this->printPermissions($input, $output, $folder);
103105
} elseif ($input->getOption('manage-add') && ($input->getOption('user') || $input->getOption('group') || $input->getOption('team'))) {
104106
[$mappingType, $mappingId] = $this->convertMappingOptions($input);
105-
$this->folderManager->setManageACL($folder['id'], $mappingType, $mappingId, true);
107+
$this->folderManager->setManageACL($folder->id, $mappingType, $mappingId, true);
106108
} elseif ($input->getOption('manage-remove') && ($input->getOption('user') || $input->getOption('group') || $input->getOption('team'))) {
107109
[$mappingType, $mappingId] = $this->convertMappingOptions($input);
108-
$this->folderManager->setManageACL($folder['id'], $mappingType, $mappingId, false);
110+
$this->folderManager->setManageACL($folder->id, $mappingType, $mappingId, false);
109111
} elseif (!$input->getArgument('path')) {
110112
$output->writeln('<error><path> argument has to be set when not using --enable or --disable</error>');
111113
return -3;
@@ -133,13 +135,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
133135
}
134136

135137
$mount = $this->mountProvider->getMount(
136-
$folder['id'],
137-
'/dummy/files/' . $folder['mount_point'],
138-
Constants::PERMISSION_ALL,
139-
$folder['quota'],
140-
null,
141-
null,
142-
$folder['acl']
138+
FolderDefinitionWithPermissions::fromFolder($folder, $folder->rootCacheEntry, Constants::PERMISSION_ALL),
139+
'/dummy/files/' . $folder->mountPoint,
143140
);
144141
$id = $mount->getStorage()->getCache()->getId($path);
145142
if ($id === -1) {
@@ -189,8 +186,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
189186
return 0;
190187
}
191188

192-
private function printPermissions(InputInterface $input, OutputInterface $output, array $folder): void {
193-
$jailPath = $this->mountProvider->getJailPath((int)$folder['id']);
189+
private function printPermissions(InputInterface $input, OutputInterface $output, FolderDefinition $folder): void {
190+
$jailPath = $this->mountProvider->getJailPath($folder->id);
194191
$rules = $this->ruleManager->getAllRulesForPrefix(
195192
$this->rootFolder->getMountPoint()->getNumericStorageId(),
196193
$jailPath

β€Žlib/Command/Create.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4141
// Check if mount point already exists
4242
$folders = $this->folderManager->getAllFolders();
4343
foreach ($folders as $folder) {
44-
if ($folder['mount_point'] === $name) {
44+
if ($folder->mountPoint === $name) {
4545
$output->writeln('<error>A Folder with the name ' . $name . ' already exists</error>');
4646
return 1;
4747
}

β€Žlib/Command/Delete.phpβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3131
}
3232

3333
$helper = $this->getHelper('question');
34-
$question = new ConfirmationQuestion('Are you sure you want to delete the Team folder ' . $folder['mount_point'] . ' and all files within, this cannot be undone (y/N).', false);
34+
$question = new ConfirmationQuestion('Are you sure you want to delete the Team folder ' . $folder->mountPoint . ' and all files within, this cannot be undone (y/N).', false);
3535
if ($input->getOption('force') || $helper->ask($input, $output, $question)) {
36-
$folderMount = $this->mountProvider->getFolder($folder['id']);
37-
$this->folderManager->removeFolder($folder['id']);
36+
$folderMount = $this->mountProvider->getFolder($folder->id);
37+
$this->folderManager->removeFolder($folder->id);
3838
$folderMount->delete();
3939
}
4040

β€Žlib/Command/ExpireGroup/ExpireGroupVersions.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function configure(): void {
3636

3737
protected function execute(InputInterface $input, OutputInterface $output): int {
3838
$this->eventDispatcher->addListener(GroupVersionsExpireEnterFolderEvent::class, function (GroupVersionsExpireEnterFolderEvent $event) use ($output): void {
39-
$output->writeln("<info>Expiring version in '{$event->folder['mount_point']}'</info>");
39+
$output->writeln("<info>Expiring version in '{$event->folder->mountPoint}'</info>");
4040
});
4141
$this->eventDispatcher->addListener(GroupVersionsExpireDeleteVersionEvent::class, function (GroupVersionsExpireDeleteVersionEvent $event) use ($output): void {
4242
$id = $event->version->getRevisionId();

β€Žlib/Command/FolderCommand.phpβ€Ž

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
use OC\Core\Command\Base;
1212
use OCA\GroupFolders\Folder\FolderManager;
13+
use OCA\GroupFolders\Folder\FolderWithMappingsAndCache;
1314
use OCA\GroupFolders\Mount\MountProvider;
1415
use OCP\Files\IRootFolder;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Output\OutputInterface;
1718

1819
/**
1920
* Base command for commands asking the user for a folder id.
20-
*
21-
* @psalm-import-type InternalFolderOut from FolderManager
2221
*/
2322
abstract class FolderCommand extends Base {
2423

@@ -30,10 +29,7 @@ public function __construct(
3029
parent::__construct();
3130
}
3231

33-
/**
34-
* @return ?InternalFolderOut
35-
*/
36-
protected function getFolder(InputInterface $input, OutputInterface $output): ?array {
32+
protected function getFolder(InputInterface $input, OutputInterface $output): ?FolderWithMappingsAndCache {
3733
$folderId = (int)$input->getArgument('folder_id');
3834
if ((string)$folderId !== $input->getArgument('folder_id')) {
3935
// Protect against removing folderId === 0 when typing a string (e.g. folder name instead of folder id)

β€Žlib/Command/Group.phpβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5656
$groupString = $input->getArgument('group');
5757
$group = $this->groupManager->get($groupString);
5858
if ($input->getOption('delete')) {
59-
$this->folderManager->removeApplicableGroup($folder['id'], $groupString);
59+
$this->folderManager->removeApplicableGroup($folder->id, $groupString);
6060
return 0;
6161
} elseif ($group || $this->folderManager->isACircle($groupString)) {
6262
$permissionsString = $input->getArgument('permissions');
6363
$permissions = $this->getNewPermissions($permissionsString);
6464
if ($permissions) {
65-
if (!isset($folder['groups'][$groupString])) {
66-
$this->folderManager->addApplicableGroup($folder['id'], $groupString);
65+
if (!isset($folder->groups[$groupString])) {
66+
$this->folderManager->addApplicableGroup($folder->id, $groupString);
6767
}
6868

69-
$this->folderManager->setGroupPermissions($folder['id'], $groupString, $permissions);
69+
$this->folderManager->setGroupPermissions($folder->id, $groupString, $permissions);
7070

7171
return 0;
7272
}

0 commit comments

Comments
Β (0)