Skip to content
Open
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
4 changes: 4 additions & 0 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ private function formatFolder(array $folder): array {
$folder['group_details'] = $folder['groups'];
$folder['groups'] = array_map(fn (array $group): int => $group['permissions'], $folder['groups']);

// Remove fields that are not available on GroupFoldersFolder
unset($folder['root_id']);
unset($folder['storage_id']);

return $folder;
}

Expand Down
88 changes: 43 additions & 45 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
* permissions: int,
* quota: int,
* acl: bool,
* storage_id: int,
* root_id: int,
* rootCacheEntry: ?CacheEntry,
* }
* @psalm-type InternalFolderOut = array{
Expand All @@ -60,6 +62,8 @@
* quota: int,
* size: int,
* acl: bool,
* storage_id: int,
* root_id: int,
* manage: list<GroupFoldersAclManage>,
* }
* @psalm-type InternalFolderMapping = array{
Expand Down Expand Up @@ -92,7 +96,7 @@ public function getAllFolders(): array {

$query = $this->connection->getQueryBuilder();

$query->select('folder_id', 'mount_point', 'quota', 'acl')
$query->select('folder_id', 'mount_point', 'quota', 'acl', 'storage_id', 'root_id')
->from('group_folders', 'f');

$rows = $query->executeQuery()->fetchAll();
Expand All @@ -106,27 +110,15 @@ public function getAllFolders(): array {
'groups' => $applicableMap[$id] ?? [],
'quota' => $this->getRealQuota((int)$row['quota']),
'size' => 0,
'acl' => (bool)$row['acl']
'acl' => (bool)$row['acl'],
'storage_id' => (int)$row['storage_id'],
'root_id' => (int)$row['root_id'],
];
}

return $folderMap;
}

/**
* @throws Exception
*/
private function getGroupFolderRootId(int $rootStorageId): int {
$query = $this->connection->getQueryBuilder();

$query->select('fileid')
->from('filecache')
->where($query->expr()->eq('storage', $query->createNamedParameter($rootStorageId)))
->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders'))));

return (int)$query->executeQuery()->fetchOne();
}

private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId): void {
$conditions = [
$query->expr()->eq('c.fileid', 'f.root_id'),
Expand All @@ -147,7 +139,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array {

$query = $this->connection->getQueryBuilder();

$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl', 'storage_id', 'root_id')
->from('group_folders', 'f');
$this->joinQueryWithFileCache($query, $rootStorageId);

Expand All @@ -166,6 +158,8 @@ public function getAllFoldersWithSize(int $rootStorageId): array {
'quota' => $this->getRealQuota((int)$row['quota']),
'size' => $row['size'] ? (int)$row['size'] : 0,
'acl' => (bool)$row['acl'],
'storage_id' => (int)$row['storage_id'],
'root_id' => (int)$row['root_id'],
'manage' => $this->getManageAcl($mappings)
];
}
Expand All @@ -183,7 +177,7 @@ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): a

$query = $this->connection->getQueryBuilder();

$query->select('f.folder_id', 'mount_point', 'quota', 'c.size', 'acl')
$query->select('f.folder_id', 'mount_point', 'quota', 'c.size', 'acl', 'storage_id', 'root_id')
->from('group_folders', 'f')
->innerJoin(
'f',
Expand All @@ -209,6 +203,8 @@ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): a
'quota' => $this->getRealQuota((int)$row['quota']),
'size' => $row['size'] ? (int)$row['size'] : 0,
'acl' => (bool)$row['acl'],
'storage_id' => (int)$row['storage_id'],
'root_id' => (int)$row['root_id'],
'manage' => $this->getManageAcl($mappings)
];
}
Expand Down Expand Up @@ -313,7 +309,7 @@ public function getFolder(int $id, int $rootStorageId = 0): ?array {

$query = $this->connection->getQueryBuilder();

$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl', 'storage_id', 'root_id')
->from('group_folders', 'f')
->where($query->expr()->eq('folder_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$this->joinQueryWithFileCache($query, $rootStorageId);
Expand All @@ -329,11 +325,14 @@ public function getFolder(int $id, int $rootStorageId = 0): ?array {

return [
'id' => $id,
'folder_id' => $id,
'mount_point' => (string)$row['mount_point'],
'groups' => $applicableMap[$id] ?? [],
'quota' => $this->getRealQuota((int)$row['quota']),
'size' => $row['size'] ?: 0,
'acl' => (bool)$row['acl'],
'storage_id' => (int)$row['storage_id'],
'root_id' => (int)$row['root_id'],
'manage' => $this->getManageAcl($folderMappings)
];
}
Expand Down Expand Up @@ -573,6 +572,22 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $
return array_values($users);
}

/**
* @return list<InternalFolder>
*/
private function rowsToFolders(array $rows): array {
return array_values(array_map(fn (array $folder): array => [
'folder_id' => (int)$folder['folder_id'],
'mount_point' => (string)$folder['mount_point'],
'permissions' => (int)$folder['group_permissions'],
'quota' => $this->getRealQuota((int)$folder['quota']),
'acl' => (bool)$folder['acl'],
'storage_id' => (int)$folder['storage_id'],
'root_id' => (int)$folder['root_id'],
'rootCacheEntry' => (isset($folder['fileid'])) ? Cache::cacheEntryFromData($folder, $this->mimeTypeLoader) : null
], $rows));
}

/**
* @return list<InternalFolder>
* @throws Exception
Expand All @@ -585,6 +600,8 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
'mount_point',
'quota',
'acl',
'storage_id',
'root_id',
'c.fileid',
'c.storage',
'c.path',
Expand All @@ -610,16 +627,7 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
->where($query->expr()->eq('a.group_id', $query->createNamedParameter($groupId)));
$this->joinQueryWithFileCache($query, $rootStorageId);

$result = $query->executeQuery()->fetchAll();

return array_values(array_map(fn (array $folder): array => [
'folder_id' => (int)$folder['folder_id'],
'mount_point' => (string)$folder['mount_point'],
'permissions' => (int)$folder['group_permissions'],
'quota' => $this->getRealQuota((int)$folder['quota']),
'acl' => (bool)$folder['acl'],
'rootCacheEntry' => (isset($folder['fileid'])) ? Cache::cacheEntryFromData($folder, $this->mimeTypeLoader) : null
], $result));
return $this->rowsToFolders($query->executeQuery()->fetchAll());
}

/**
Expand All @@ -635,6 +643,8 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
'mount_point',
'quota',
'acl',
'storage_id',
'root_id',
'c.fileid',
'c.storage',
'c.path',
Expand Down Expand Up @@ -667,14 +677,7 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
$result = array_merge($result, $query->executeQuery()->fetchAll());
}

return array_map(fn (array $folder): array => [
'folder_id' => (int)$folder['folder_id'],
'mount_point' => (string)$folder['mount_point'],
'permissions' => (int)$folder['group_permissions'],
'quota' => $this->getRealQuota((int)$folder['quota']),
'acl' => (bool)$folder['acl'],
'rootCacheEntry' => (isset($folder['fileid'])) ? Cache::cacheEntryFromData($folder, $this->mimeTypeLoader) : null
], array_values($result));
return $this->rowsToFolders($result);
}

/**
Expand All @@ -701,6 +704,8 @@ public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId
'f.mount_point',
'f.quota',
'f.acl',
'f.storage_id',
'f.root_id',
'c.fileid',
'c.storage',
'c.path',
Expand Down Expand Up @@ -733,14 +738,7 @@ public function getFoldersFromCircleMemberships(IUser $user, int $rootStorageId
}
$this->joinQueryWithFileCache($query, $rootStorageId);

return array_map(fn (array $folder): array => [
'folder_id' => (int)$folder['folder_id'],
'mount_point' => (string)$folder['mount_point'],
'permissions' => (int)$folder['group_permissions'],
'quota' => $this->getRealQuota((int)$folder['quota']),
'acl' => (bool)$folder['acl'],
'rootCacheEntry' => (isset($folder['fileid'])) ? Cache::cacheEntryFromData($folder, $this->mimeTypeLoader) : null
], array_values($query->executeQuery()->fetchAll()));
return $this->rowsToFolders($query->executeQuery()->fetchAll());
}


Expand Down
2 changes: 2 additions & 0 deletions lib/Mount/GroupMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ public function __construct(
?IStorageFactory $loader = null,
?array $mountOptions = null,
?int $mountId = null,
?int $rootId = null,
) {
/** @var Storage $storage */
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, MountProvider::class);
$this->rootId = $rootId;
}

public function getMountType(): string {
Expand Down
7 changes: 5 additions & 2 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
$folder['acl'],
$user,
$aclManager,
$rootRules
$rootRules,
$folder['root_id'],
);
}, $folders));
}
Expand Down Expand Up @@ -147,6 +148,7 @@ public function getMount(
?IUser $user = null,
?ACLManager $aclManager = null,
array $rootRules = [],
?int $rootId = null,
): ?IMountPoint {
if (!$cacheEntry) {
// trigger folder creation
Expand Down Expand Up @@ -199,7 +201,8 @@ public function getMount(
$maskedStore,
$mountPoint,
null,
$loader
$loader,
rootId: $rootId,
);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ private function assertHasFolders(array $folders): void {

foreach ($existingFolders as &$existingFolder) {
unset($existingFolder['id']);
unset($existingFolder['root_id']);
unset($existingFolder['storage_id']);
}

$this->assertEquals($folders, $existingFolders);
Expand Down
Loading