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
14 changes: 12 additions & 2 deletions lib/ACL/RuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ private function createRule(array $data): ?Rule {
(int)$data['mask'],
(int)$data['permissions']
);
} else {
return null;
}

return null;
}

/**
Expand Down Expand Up @@ -111,6 +111,9 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP
*/
public function getRulesForFilesByIds(IUser $user, array $fileIds): array {
$userMappings = $this->userMappingManager->getMappingsForUser($user);
if (empty($userMappings)) {
return [];
}

$rows = [];
foreach (array_chunk($fileIds, 1000) as $chunk) {
Expand All @@ -135,6 +138,9 @@ public function getRulesForFilesByIds(IUser $user, array $fileIds): array {
*/
public function getRulesForFilesByParent(IUser $user, int $storageId, int $parentId): array {
$userMappings = $this->userMappingManager->getMappingsForUser($user);
if (empty($userMappings)) {
return [];
}

$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'a.mapping_type', 'a.mapping_id', 'a.mask', 'a.permissions', 'f.path'])
Expand Down Expand Up @@ -177,6 +183,7 @@ public function getRulesForFilesByParent(IUser $user, int $storageId, int $paren
*/
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', 'f.path'])
->from('group_folders_acl', 'a')
Expand Down Expand Up @@ -245,6 +252,9 @@ public function getAllRulesForPrefix(int $storageId, string $prefix): array {
*/
public function getRulesForPrefix(IUser $user, int $storageId, string $prefix): array {
$userMappings = $this->userMappingManager->getMappingsForUser($user);
if (empty($userMappings)) {
return [];
}

$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
Expand Down
3 changes: 2 additions & 1 deletion lib/ACL/UserMapping/UserMappingManager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -54,6 +55,7 @@ public function mappingFromId(string $type, string $id): ?IUserMapping {
default:
return null;
}

if ($displayName === null) {
return null;
}
Expand All @@ -62,7 +64,6 @@ public function mappingFromId(string $type, string $id): ?IUserMapping {
}



/**
* returns the Circle from its single Id, or NULL if not available
*/
Expand Down
13 changes: 7 additions & 6 deletions lib/BackgroundJob/ExpireGroupVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(

// Run once per hour
$this->setInterval(60 * 60);

// But don't run if still running
$this->setAllowParallelRuns(false);
}
Expand All @@ -40,26 +41,26 @@ public function __construct(
*/
#[\Override]
protected function run(mixed $argument): void {
$lastFolder = $this->appConfig->getValueInt(Application::APP_ID, 'cron_last_folder_index', 0);
$folders = $this->folderManager->getAllFoldersWithSize();

$folderCount = count($folders);
$currentRunHour = (int)date('G', $this->time->getTime());

// Calculate folders to process in the remaining hours, ensure at least one folder is processed
$toDo = max(1, (int)ceil(($folderCount - $lastFolder) / (24 - $currentRunHour)));

// If there are no folders, we don't need to do anything
if ($folderCount === 0) {
$this->logger->debug('No folders to expire', ['app' => 'cron']);
return;
}

$lastFolder = $this->appConfig->getValueInt(Application::APP_ID, 'cron_last_folder_index', 0);

// If we would go over the end of the list, wrap around
if ($lastFolder >= $folderCount) {
$lastFolder = 0;
}

// Calculate folders to process in the remaining hours, ensure at least one folder is processed
$currentRunHour = (int)date('G', $this->time->getTime());
$toDo = max(1, (int)ceil(($folderCount - $lastFolder) / (24 - $currentRunHour)));

// Save the updated folder index BEFORE processing the folders
$this->appConfig->setValueInt(Application::APP_ID, 'cron_last_folder_index', $lastFolder + $toDo);

Expand Down
1 change: 1 addition & 0 deletions lib/CacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function onCacheEvent(ICacheEvent $event): void {
if (!$storage->instanceOfStorage(Jail::class)) {
return;
}

/** @var Jail $storage */
$path = $storage->getJailedPath($event->getPath());
if ($path !== null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Trashbin/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
) {
parent::__construct();
if (Server::get(IAppManager::class)->isEnabledForUser('files_trashbin')) {
$this->trashBackend = \OCP\Server::get(TrashBackend::class);
$this->trashBackend = Server::get(TrashBackend::class);
}
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ public function canManageACL(int $folderId, IUser $user, bool $excludeAdmins = f

public function mountPointExists(string $mountPoint): bool {
$query = $this->connection->getQueryBuilder();

$query->select($query->func()->count('*'))
->from('group_folders')
->where($query->expr()->eq('mount_point', $query->createNamedParameter($mountPoint)))
Expand All @@ -509,6 +510,7 @@ public function mountPointExists(string $mountPoint): bool {
*/
private function getManagerMappings(int $folderId): array {
$query = $this->connection->getQueryBuilder();

$query->select('mapping_type', 'mapping_id')
->from('group_folders_manage')
->where($query->expr()->eq('folder_id', $query->createNamedParameter($folderId, IQueryBuilder::PARAM_INT)));
Expand All @@ -518,6 +520,7 @@ private function getManagerMappings(int $folderId): array {
foreach ($rows as $manageRule) {
$managerMappings[] = new UserMapping($manageRule['mapping_type'], $manageRule['mapping_id']);
}

return $managerMappings;
}

Expand Down Expand Up @@ -858,6 +861,7 @@ public function setGroupPermissions(int $folderId, string $groupId, int $permiss
*/
public function setManageACL(int $folderId, string $type, string $id, bool $manageAcl): void {
$query = $this->connection->getQueryBuilder();

if ($manageAcl === true) {
$query->insert('group_folders_manage')
->values([
Expand Down Expand Up @@ -1092,11 +1096,13 @@ private function getRealQuota(int $quota): int {
*/
private function hasHomeFolderOverwriteMount(): bool {
$builder = $this->connection->getQueryBuilder();

$query = $builder->select('folder_id')
->from('group_folders')
->where($builder->expr()->eq('mount_point', $builder->createNamedParameter('/')))
->setMaxResults(1);
$result = $query->executeQuery();

return $result->rowCount() > 0;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Listeners/LoadAdditionalScriptsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\GroupFolders\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

/**
* @template-implements IEventListener<LoadAdditionalScriptsEvent|BeforeTemplateRenderedEvent>
Expand All @@ -25,7 +26,7 @@ public function handle(Event $event): void {
return;
}

\OCP\Util::addInitScript(Application::APP_ID, Application::APP_ID . '-initFiles');
\OCP\Util::addStyle(Application::APP_ID, Application::APP_ID . '-initFiles');
Util::addInitScript(Application::APP_ID, Application::APP_ID . '-initFiles');
Util::addStyle(Application::APP_ID, Application::APP_ID . '-initFiles');
}
}
32 changes: 18 additions & 14 deletions lib/Mount/FolderStorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public function getBaseStorageForFolder(
): IStorage {
if ($separateStorage) {
return $this->getBaseStorageForFolderSeparate($folderId, $folder, $user, $inShare, $type, $init, $options);
} else {
return $this->getBaseStorageForFolderRootJail($folderId, $folder, $user, $inShare, $type);
}

return $this->getBaseStorageForFolderRootJail($folderId, $folder, $user, $inShare, $type);
}

/**
Expand Down Expand Up @@ -113,12 +113,12 @@ private function getBaseStorageForFolderSeparate(
'storage' => $storage,
'root' => $type,
]);
} else {
return new Jail([
'storage' => $storage,
'root' => $type,
]);
}

return new Jail([
'storage' => $storage,
'root' => $type,
]);
}

private function getBaseStorageForFolderSeparateStorageLocal(
Expand All @@ -144,6 +144,7 @@ private function getBaseStorageForFolderSeparateStorageLocal(
if ($init) {
$storage->getScanner()->scan('');
}

return $storage;
}

Expand Down Expand Up @@ -179,6 +180,7 @@ private function getBaseStorageForFolderSeparateStorageObject(
throw new \Exception('Failed to create base directories for group folder ' . $folderId);
}
}

return $storage;
}

Expand Down Expand Up @@ -244,12 +246,12 @@ private function getBaseStorageForFolderRootJail(
'storage' => $rootStorage,
'root' => $rootPath,
]);
} else {
return new Jail([
'storage' => $rootStorage,
'root' => $rootPath,
]);
}

return new Jail([
'storage' => $rootStorage,
'root' => $rootPath,
]);
}

public function deleteStoragesForFolder(FolderDefinition $folder): void {
Expand All @@ -272,9 +274,9 @@ private function getObjectStorageKey(int $folderId): string {
$this->appConfig->setValueString(Application::APP_ID, $configKey, $storageConfigKey);
}
return $storageConfigKey;
} else {
return 'default';
}

return 'default';
}

private function getObjectStorageBucket(int $folderId, array $objectStoreConfig, ?string $overwriteBucket = null): string {
Expand All @@ -290,6 +292,7 @@ private function getObjectStorageBucket(int $folderId, array $objectStoreConfig,

$this->appConfig->setValueString(Application::APP_ID, $bucketKey, $bucket);
}

return $bucket;
}

Expand All @@ -303,6 +306,7 @@ private function calculateBucketNum(string $key, array $objectStoreConfig): stri

$hash = md5($key);
$num = hexdec(substr($hash, 0, 4));

return (string)(($num % ($numBuckets - $minBucket)) + $minBucket);
}
}
4 changes: 2 additions & 2 deletions lib/Mount/GroupMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function getSourcePath(): string {
if ($storage && $storage->instanceOfStorage(Jail::class)) {
/** @var Jail $storage */
return $storage->getUnJailedPath('');
} else {
return '';
}

return '';
}
}
20 changes: 10 additions & 10 deletions lib/Mount/RootPermissionsMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,45 @@ private function checkMask(int $permissions): bool {
public function isUpdatable(string $path): bool {
if ($path === '') {
return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path);
} else {
return parent::isUpdatable($path);
}

return parent::isUpdatable($path);
}

#[\Override]
public function isCreatable(string $path): bool {
if ($path === '') {
return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path);
} else {
return parent::isCreatable($path);
}

return parent::isCreatable($path);
}

#[\Override]
public function isDeletable(string $path): bool {
if ($path === '') {
return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path);
} else {
return parent::isDeletable($path);
}

return parent::isDeletable($path);
}

#[\Override]
public function isSharable(string $path): bool {
if ($path === '') {
return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path);
} else {
return parent::isSharable($path);
}

return parent::isSharable($path);
}

#[\Override]
public function getPermissions(string $path): int {
if ($path === '') {
return $this->storage->getPermissions($path) & $this->mask;
} else {
return $this->storage->getPermissions($path);
}

return $this->storage->getPermissions($path);
}

#[\Override]
Expand Down
8 changes: 6 additions & 2 deletions lib/Trash/TrashBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function setVersionsBackend(VersionsBackend $versionsBackend): void {
*/
public function listTrashRoot(IUser $user): array {
$folders = $this->folderManager->getFoldersForUser($user);

return $this->getTrashForFolders($user, $folders);
}

Expand Down Expand Up @@ -283,9 +284,9 @@ public function moveToTrash(IStorage $storage, string $internalPath): bool {
}

return true;
} else {
return false;
}

return false;
}

/**
Expand Down Expand Up @@ -322,6 +323,7 @@ private function moveFromEncryptedStorage(IStorage $sourceStorage, IStorage $tar
}
}
}

return $result;
}

Expand Down Expand Up @@ -403,6 +405,7 @@ private function getUnJailedPath(Node $node): string {
$path = $storage->getUnjailedPath($path);
$storage = $storage->getUnjailedStorage();
}

return $path;
}

Expand Down Expand Up @@ -529,6 +532,7 @@ public function cleanTrashFolder(FolderDefinitionWithPermissions $folder): void
public function expire(Expiration $expiration): array {
$size = 0;
$count = 0;

$folders = $this->folderManager->getAllFoldersWithSize();
$folders = array_map(fn (FolderWithMappingsAndCache $folder): FolderDefinitionWithPermissions => FolderDefinitionWithPermissions::fromFolder($folder, $folder->rootCacheEntry, Constants::PERMISSION_ALL), $folders);
foreach ($folders as $folder) {
Expand Down
Loading
Loading