Skip to content
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
41 changes: 21 additions & 20 deletions lib/ACL/RuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP
$rows = [];
foreach (array_chunk($hashes, 1000) as $chunk) {
$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->in('path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->where($query->expr()->in('f.path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->orX(...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
Expand Down Expand Up @@ -117,19 +117,20 @@ public function getRulesForFilesByParent(IUser $user, int $storageId, string $pa
}

$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
$query->select(['f.fileid', 'a.mapping_type', 'a.mapping_id', 'a.mask', 'a.permissions', 'f.path'])
->from('filecache', 'f')
->leftJoin('f', 'group_folders_acl', 'a', $query->expr()->eq('f.fileid', 'a.fileid'))
->andWhere($query->expr()->eq('parent', $query->createNamedParameter($parentId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('f.parent', $query->createNamedParameter($parentId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere(
$query->expr()->orX(
$query->expr()->andX(
$query->expr()->isNull('mapping_type'),
$query->expr()->isNull('mapping_id')
$query->expr()->isNull('a.mapping_type'),
$query->expr()->isNull('a.mapping_id')
),
...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
$query->expr()->eq('a.mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('a.mapping_id', $query->createNamedParameter($userMapping->getId()))
), $userMappings)
)
);
Expand Down Expand Up @@ -170,11 +171,11 @@ private function getId(int $storageId, string $path): int {
public function getAllRulesForPaths(int $storageId, array $filePaths): array {
$hashes = array_map(fn (string $path): string => md5(trim($path, '/')), $filePaths);
$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->in('path_hash', $query->createNamedParameter($hashes, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
->where($query->expr()->in('f.path_hash', $query->createNamedParameter($hashes, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));

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

Expand Down Expand Up @@ -203,14 +204,14 @@ private function rulesByPath(array $rows, array $result = []): array {
*/
public function getAllRulesForPrefix(int $storageId, string $prefix): array {
$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->orX(
$query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix)))
$query->expr()->like('f.path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('f.path_hash', $query->createNamedParameter(md5($prefix)))
))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));

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

Expand All @@ -224,14 +225,14 @@ public function getRulesForPrefix(IUser $user, int $storageId, string $prefix):
$userMappings = $this->userMappingManager->getMappingsForUser($user);

$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->orX(
$query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix)))
$query->expr()->like('f.path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('f.path_hash', $query->createNamedParameter(md5($prefix)))
))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->orX(...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
Expand Down
57 changes: 29 additions & 28 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId
$query->leftJoin('f', 'filecache', 'c', $query->expr()->andX(
// concat with empty string to work around missing cast to string
$query->expr()->eq('c.name', $query->func()->concat('f.folder_id', $query->expr()->literal(''))),
$query->expr()->eq('c.parent', $query->createNamedParameter($this->getGroupFolderRootId($rootStorageId)))
$query->expr()->eq('c.parent', $query->createNamedParameter($this->getGroupFolderRootId($rootStorageId))),
$query->expr()->eq('c.storage', $query->createNamedParameter($rootStorageId)),
));
}

Expand All @@ -136,7 +137,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array {

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

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

Expand Down Expand Up @@ -172,7 +173,7 @@ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): a

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

$query->select('f.folder_id', 'mount_point', 'quota', 'size', 'acl')
$query->select('f.folder_id', 'mount_point', 'quota', 'c.size', 'acl')
->from('group_folders', 'f')
->innerJoin(
'f',
Expand Down Expand Up @@ -285,7 +286,7 @@ public function getFolder(int $id, int $rootStorageId = 0): ?array {

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

$query->select('folder_id', 'mount_point', 'quota', 'size', 'acl')
$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
->from('group_folders', 'f')
->where($query->expr()->eq('folder_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$this->joinQueryWithFileCache($query, $rootStorageId);
Expand Down Expand Up @@ -496,18 +497,18 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
'mount_point',
'quota',
'acl',
'fileid',
'storage',
'path',
'name',
'mimetype',
'mimepart',
'size',
'mtime',
'storage_mtime',
'etag',
'encrypted',
'parent'
'c.fileid',
'c.storage',
'c.path',
'c.name',
'c.mimetype',
'c.mimepart',
'c.size',
'c.mtime',
'c.storage_mtime',
'c.etag',
'c.encrypted',
'c.parent'
)
->selectAlias('a.permissions', 'group_permissions')
->selectAlias('c.permissions', 'permissions')
Expand Down Expand Up @@ -546,18 +547,18 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
'mount_point',
'quota',
'acl',
'fileid',
'storage',
'path',
'name',
'mimetype',
'mimepart',
'size',
'mtime',
'storage_mtime',
'etag',
'encrypted',
'parent'
'c.fileid',
'c.storage',
'c.path',
'c.name',
'c.mimetype',
'c.mimepart',
'c.size',
'c.mtime',
'c.storage_mtime',
'c.etag',
'c.encrypted',
'c.parent'
)
->selectAlias('a.permissions', 'group_permissions')
->selectAlias('c.permissions', 'permissions')
Expand Down
Loading