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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm --threads=$(nproc) --no-cache",
"psalm:update-baseline": "psalm --threads=$(nproc) --no-cache --update-baseline",
"psalm:fix": "psalm --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm:fix": "psalm --no-cache --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType,MissingOverrideAttribute",
"test:unit": "phpunit -c tests/phpunit.xml",
"test:unit:coverage": "XDEBUG_MODE=coverage phpunit -c tests/phpunit.xml",
"rector": "rector && composer cs:fix",
Expand Down
5 changes: 5 additions & 0 deletions lib/ACL/ACLCacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private function getACLPermissionsForPath(string $path, array $rules = []): int
return $canRead ? $permissions : 0;
}

#[\Override]
protected function formatCacheEntry($entry, array $rules = []): ICacheEntry|false {
if (isset($entry['permissions'])) {
$entry['scan_permissions'] ??= $entry['permissions'];
Expand All @@ -55,27 +56,31 @@ protected function formatCacheEntry($entry, array $rules = []): ICacheEntry|fals
return $entry;
}

#[\Override]
public function getFolderContentsById($fileId): array {
$results = $this->getCache()->getFolderContentsById($fileId);
$rules = $this->preloadEntries($results);

return array_filter(array_map(fn (ICacheEntry $entry): ICacheEntry|false => $this->formatCacheEntry($entry, $rules), $results));
}

#[\Override]
public function search($pattern): array {
$results = $this->getCache()->search($pattern);
$this->preloadEntries($results);

return array_filter(array_map($this->formatCacheEntry(...), $results));
}

#[\Override]
public function searchByMime($mimetype): array {
$results = $this->getCache()->searchByMime($mimetype);
$this->preloadEntries($results);

return array_filter(array_map($this->formatCacheEntry(...), $results));
}

#[\Override]
public function searchQuery(ISearchQuery $query): array {
$results = $this->getCache()->searchQuery($query);
$this->preloadEntries($results);
Expand Down
32 changes: 32 additions & 0 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,39 @@ private function checkPermissions(string $path, int $permissions): bool {
return ($this->getACLPermissionsForPath($path) & $permissions) === $permissions;
}

#[\Override]
public function isReadable(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_READ) && parent::isReadable($path);
}

#[\Override]
public function isUpdatable(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_UPDATE) && parent::isUpdatable($path);
}

#[\Override]
public function isCreatable(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_CREATE) && parent::isCreatable($path);
}

#[\Override]
public function isDeletable(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_DELETE)
&& $this->canDeleteTree($path)
&& parent::isDeletable($path);
}

#[\Override]
public function isSharable(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_SHARE) && parent::isSharable($path);
}

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

#[\Override]
public function rename(string $source, string $target): bool {
if (str_starts_with($source, $target)) {
$part = substr($source, strlen($target));
Expand Down Expand Up @@ -100,6 +107,7 @@ public function rename(string $source, string $target): bool {
&& parent::rename($source, $target);
}

#[\Override]
public function opendir(string $path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -122,28 +130,33 @@ public function opendir(string $path) {
return IteratorDirectory::wrap($items);
}

#[\Override]
public function copy(string $source, string $target): bool {
$permissions = $this->file_exists($target) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkPermissions($target, $permissions)
&& $this->checkPermissions($source, Constants::PERMISSION_READ)
&& parent::copy($source, $target);
}

#[\Override]
public function touch(string $path, ?int $mtime = null): bool {
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkPermissions($path, $permissions) && parent::touch($path, $mtime);
}

#[\Override]
public function mkdir(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_CREATE) && parent::mkdir($path);
}

#[\Override]
public function rmdir(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_DELETE)
&& $this->canDeleteTree($path)
&& parent::rmdir($path);
}

#[\Override]
public function unlink(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_DELETE)
&& $this->canDeleteTree($path)
Expand All @@ -158,11 +171,13 @@ private function canDeleteTree(string $path): int {
return $this->aclManager->getPermissionsForTree($this->folderId, $this->storageId, $path) & Constants::PERMISSION_DELETE;
}

#[\Override]
public function file_put_contents(string $path, mixed $data): int|float|false {
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkPermissions($path, $permissions) ? parent::file_put_contents($path, $data) : false;
}

#[\Override]
public function fopen(string $path, string $mode) {
if ($mode === 'r' or $mode === 'rb') {
$permissions = Constants::PERMISSION_READ;
Expand All @@ -173,6 +188,7 @@ public function fopen(string $path, string $mode) {
return $this->checkPermissions($path, $permissions) ? parent::fopen($path, $mode) : false;
}

#[\Override]
public function writeStream(string $path, $stream, ?int $size = null): int {
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
return $this->checkPermissions($path, $permissions) ? parent::writeStream($path, $stream, $size) : 0;
Expand All @@ -181,6 +197,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int {
/**
* @inheritDoc
*/
#[\Override]
public function getCache(string $path = '', ?IStorage $storage = null): ICache {
if (!$storage) {
$storage = $this;
Expand All @@ -191,6 +208,7 @@ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
return new ACLCacheWrapper($sourceCache, $this->aclManager, $this->folderId, $this->inShare);
}

#[\Override]
public function getMetaData(string $path): ?array {
$data = parent::getMetaData($path);

Expand All @@ -205,6 +223,7 @@ public function getMetaData(string $path): ?array {
/**
* @inheritDoc
*/
#[\Override]
public function getScanner(string $path = '', ?IStorage $storage = null): IScanner {
if (!$storage) {
$storage = $this->storage;
Expand All @@ -213,16 +232,19 @@ public function getScanner(string $path = '', ?IStorage $storage = null): IScann
return parent::getScanner($path, $storage);
}

#[\Override]
public function is_dir(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_READ)
&& parent::is_dir($path);
}

#[\Override]
public function is_file(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_READ)
&& parent::is_file($path);
}

#[\Override]
public function stat(string $path): array|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -231,6 +253,7 @@ public function stat(string $path): array|false {
return parent::stat($path);
}

#[\Override]
public function filetype(string $path): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -239,6 +262,7 @@ public function filetype(string $path): string|false {
return parent::filetype($path);
}

#[\Override]
public function filesize(string $path): false|int|float {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -247,11 +271,13 @@ public function filesize(string $path): false|int|float {
return parent::filesize($path);
}

#[\Override]
public function file_exists(string $path): bool {
return $this->checkPermissions($path, Constants::PERMISSION_READ)
&& parent::file_exists($path);
}

#[\Override]
public function filemtime(string $path): int|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -260,6 +286,7 @@ public function filemtime(string $path): int|false {
return parent::filemtime($path);
}

#[\Override]
public function file_get_contents(string $path): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -268,6 +295,7 @@ public function file_get_contents(string $path): string|false {
return parent::file_get_contents($path);
}

#[\Override]
public function getMimeType(string $path): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -276,6 +304,7 @@ public function getMimeType(string $path): string|false {
return parent::getMimeType($path);
}

#[\Override]
public function hash(string $type, string $path, bool $raw = false): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -284,6 +313,7 @@ public function hash(string $type, string $path, bool $raw = false): string|fals
return parent::hash($type, $path, $raw);
}

#[\Override]
public function getETag(string $path): string|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -292,6 +322,7 @@ public function getETag(string $path): string|false {
return parent::getETag($path);
}

#[\Override]
public function getDirectDownload(string $path): array|false {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
Expand All @@ -300,6 +331,7 @@ public function getDirectDownload(string $path): array|false {
return parent::getDirectDownload($path);
}

#[\Override]
public function getDirectoryContent(string $directory): \Traversable {
$content = $this->getWrapperStorage()->getDirectoryContent($directory);
foreach ($content as $data) {
Expand Down
3 changes: 3 additions & 0 deletions lib/ACL/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function applyDenyPermissions(int $permissions): int {
return $permissions & $denyMask;
}

#[\Override]
public function xmlSerialize(Writer $writer): void {
$data = [
self::ACL => [
Expand All @@ -108,6 +109,7 @@ public function xmlSerialize(Writer $writer): void {
$writer->write($data);
}

#[\Override]
public function jsonSerialize(): array {
return [
'mapping' => [
Expand All @@ -119,6 +121,7 @@ public function jsonSerialize(): array {
];
}

#[\Override]
public static function xmlDeserialize(Reader $reader): Rule {
$elements = \Sabre\Xml\Deserializer\keyValue($reader);

Expand Down
4 changes: 4 additions & 0 deletions lib/ACL/UserMapping/UserMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ public function __construct(
$this->displayName = $displayName ?? $id;
}

#[\Override]
public function getType(): string {
return $this->type;
}

#[\Override]
public function getId(): string {
return $this->id;
}

#[\Override]
public function getDisplayName(): string {
return $this->displayName;
}

#[\Override]
public function getKey(): string {
return $this->getType() . ':' . $this->getId();
}
Expand Down
3 changes: 3 additions & 0 deletions lib/ACL/UserMapping/UserMappingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(
) {
}

#[\Override]
public function getMappingsForUser(IUser $user, bool $userAssignable = true): array {
$groupMappings = array_values(array_map(fn (IGroup $group): UserMapping => new UserMapping('group', $group->getGID(), $group->getDisplayName()), $this->groupManager->getUserGroups($user)));
$circleMappings = array_values(array_map(fn (Circle $circle): UserMapping => new UserMapping('circle', $circle->getSingleId(), $circle->getDisplayName()), $this->getUserCircles($user->getUID())));
Expand All @@ -38,6 +39,7 @@ public function getMappingsForUser(IUser $user, bool $userAssignable = true): ar
], $groupMappings, $circleMappings);
}

#[\Override]
public function mappingFromId(string $type, string $id): ?IUserMapping {
switch ($type) {
case 'group':
Expand Down Expand Up @@ -115,6 +117,7 @@ public function getCirclesManager(): ?CirclesManager {
}
}

#[\Override]
public function userInMappings(IUser $user, array $mappings): bool {
foreach ($mappings as $mapping) {
if ($mapping->getType() === 'user' && $mapping->getId() === $user->getUID()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function __construct(array $urlParams = []) {
'workspace'
];

#[\Override]
public function register(IRegistrationContext $context): void {
/** Register $principalBackend for the DAV collection */
$context->registerServiceAlias('principalBackend', Principal::class);
Expand Down Expand Up @@ -184,6 +185,7 @@ public function register(IRegistrationContext $context): void {
$context->registerMiddleware(AuthorizedAdminSettingMiddleware::class);
}

#[\Override]
public function boot(IBootContext $context): void {
$context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, IEventDispatcher $eventDispatcher): void {
$mountProviderCollection->registerProvider(Server::get(MountProvider::class));
Expand Down
1 change: 1 addition & 0 deletions lib/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(
* },
* }
*/
#[\Override]
public function getCapabilities(): array {
$user = $this->userSession->getUser();
if (!$user) {
Expand Down
2 changes: 2 additions & 0 deletions lib/AuthorizedAdminSettingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public function __construct(
/**
* Throws an error when the user is not allowed to use the app's APIs
*/
#[\Override]
public function beforeController(Controller $controller, string $methodName): void {
$method = new ReflectionMethod($controller, $methodName);
if ($method->getAttributes(RequireGroupFolderAdmin::class) !== [] && !$this->delegatedService->hasApiAccess()) {
throw new Exception('Logged in user must be an admin, a sub admin or gotten special right to access this setting');
}
}

#[\Override]
public function afterException(Controller $controller, string $methodName, Exception $exception): Response {
/** @var Http::STATUS_* $code */
$code = $exception->getCode();
Expand Down
1 change: 1 addition & 0 deletions lib/BackgroundJob/ExpireGroupPlaceholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(ITimeFactory $timeFactory) {
$this->setInterval(60 * 60 * 99999999);
}

#[\Override]
protected function run(mixed $argument): void {
// noop
}
Expand Down
Loading
Loading