Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Update nextcloud/coding-standard to v1.3.0 #3249

Merged
merged 1 commit into from
Sep 18, 2024
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
8 changes: 8 additions & 0 deletions lib/ACL/ACLCacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ private function getACLPermissionsForPath(string $path, array $rules = []) {
} else {
$minPermissions = Constants::PERMISSION_READ;
}

$canRead = ($permissions & $minPermissions) === $minPermissions;

return $canRead ? $permissions : 0;
}

Expand All @@ -49,12 +51,14 @@ protected function formatCacheEntry($entry, array $rules = []) {
return false;
}
}

return $entry;
}

public function getFolderContentsById($fileId) {
$results = $this->getCache()->getFolderContentsById($fileId);
$rules = $this->preloadEntries($results);

return array_filter(array_map(function ($entry) use ($rules) {
return $this->formatCacheEntry($entry, $rules);
}, $results));
Expand All @@ -63,18 +67,21 @@ public function getFolderContentsById($fileId) {
public function search($pattern) {
$results = $this->getCache()->search($pattern);
$this->preloadEntries($results);

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

public function searchByMime($mimetype) {
$results = $this->getCache()->searchByMime($mimetype);
$this->preloadEntries($results);

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

public function searchQuery(ISearchQuery $query) {
$results = $this->getCache()->searchQuery($query);
$this->preloadEntries($results);

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

Expand All @@ -86,6 +93,7 @@ private function preloadEntries(array $entries): array {
$paths = array_map(function (ICacheEntry $entry) {
return $entry->getPath();
}, $entries);

return $this->aclManager->getRelevantRulesForPath($paths, false);
}
}
5 changes: 5 additions & 0 deletions lib/ACL/ACLManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function getRules(array $paths, bool $cache = true): array {
if ($cache) {
$this->ruleCache->set($path, $rulesForPath);
}

$rules[$path] = $rulesForPath;
}
}
Expand Down Expand Up @@ -98,6 +99,7 @@ private function getRelevantPaths(string $path): array {
$rootTrashedItemDate = (int)substr($rootTrashedItemName, $separatorPos + 2);
$rootTrashedItemName = substr($rootTrashedItemName, 0, $separatorPos);
}

while ($path !== '') {
$paths[] = $path;
$path = dirname($path);
Expand Down Expand Up @@ -133,6 +135,7 @@ public function getRelevantRulesForPath(array $paths, bool $cache = true): array
foreach ($paths as $path) {
$allPaths = array_unique(array_merge($allPaths, $this->getRelevantPaths($path)));
}

return $this->getRules($allPaths, $cache);
}

Expand All @@ -152,6 +155,7 @@ public function getPermissionsForPathFromRules(string $path, array $rules): int
$path = ltrim($path, '/');
$relevantPaths = $this->getRelevantPaths($path);
$rules = array_intersect_key($rules, array_flip($relevantPaths));

return $this->calculatePermissionsForPath($rules);
}

Expand Down Expand Up @@ -194,6 +198,7 @@ private function calculatePermissionsForPath(array $rules): int {
}

$mergedRule = Rule::mergeRules($rulesPerMapping);

return $mergedRule->applyPermissions(Constants::PERMISSION_ALL);
} else {
// first combine all rules with the same path, then apply them on top of the current permissions
Expand Down
18 changes: 18 additions & 0 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private function getACLPermissionsForPath(string $path) {
} else {
$canRead = $permissions & Constants::PERMISSION_READ;
}

return $canRead ? $permissions : 0;
}

Expand Down Expand Up @@ -74,15 +75,18 @@ public function rename($source, $target) {
return $this->checkPermissions($target, Constants::PERMISSION_CREATE) && parent::rename($source, $target);
}
}

$permissions = $this->file_exists($target) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
$sourceParent = dirname($source);
if ($sourceParent === '.') {
$sourceParent = '';
}

$targetParent = dirname($target);
if ($targetParent === '.') {
$targetParent = '';
}

return ($sourceParent === $targetParent ||
$this->checkPermissions($sourceParent, Constants::PERMISSION_DELETE)) &&
$this->checkPermissions($source, Constants::PERMISSION_UPDATE & Constants::PERMISSION_READ) &&
Expand Down Expand Up @@ -158,6 +162,7 @@ public function fopen($path, $mode) {
} else {
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
}

return $this->checkPermissions($path, $permissions) ? parent::fopen($path, $mode) : false;
}

Expand All @@ -177,7 +182,9 @@ public function getCache($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}

$sourceCache = parent::getCache($path, $storage);

return new ACLCacheWrapper($sourceCache, $this->aclManager, $this->inShare);
}

Expand All @@ -188,13 +195,15 @@ public function getMetaData($path) {
$data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions'];
$data['permissions'] &= $this->getACLPermissionsForPath($path);
}

return $data;
}

public function getScanner($path = '', $storage = null) {
if (!$storage) {
$storage = $this->storage;
}

return parent::getScanner($path, $storage);
}

Expand All @@ -212,20 +221,23 @@ public function stat($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::stat($path);
}

public function filetype($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::filetype($path);
}

public function filesize($path): false|int|float {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::filesize($path);
}

Expand All @@ -238,41 +250,47 @@ public function filemtime($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::filemtime($path);
}

public function file_get_contents($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::file_get_contents($path);
}

public function getMimeType($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::getMimeType($path);
}

public function hash($type, $path, $raw = false) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::hash($type, $path, $raw);
}

public function getETag($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::getETag($path);
}

public function getDirectDownload($path) {
if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) {
return false;
}

return parent::getDirectDownload($path);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/ACL/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function applyPermissions(int $permissions): int {

// a bitmask that has all allow bits set to 1 and all inherit and deny bits to 0
$allowMask = $this->mask & $this->permissions;

return $permissions | $allowMask;
}

Expand Down Expand Up @@ -185,6 +186,7 @@ public static function formatRulePermissions(int $mask, int $permissions): strin
$result[] = $type . $name;
}
}

return implode(', ', $result);
}

Expand Down
9 changes: 8 additions & 1 deletion lib/ACL/RuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ public function getRulesForFilesById(IUser $user, array $fileIds): array {
if (!isset($result[$row['fileid']])) {
$result[$row['fileid']] = [];
}

$rule = $this->createRule($row);
if ($rule) {
$result[$row['fileid']][] = $rule;
}
}

return $result;
}

Expand Down Expand Up @@ -106,11 +108,11 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP
$rows = array_merge($rows, $query->executeQuery()->fetchAll());
}


$result = [];
foreach ($filePaths as $path) {
$result[$path] = [];
}

return $this->rulesByPath($rows, $result);
}

Expand Down Expand Up @@ -155,13 +157,15 @@ public function getRulesForFilesByParent(IUser $user, int $storageId, string $pa
if (!isset($result[$row['path']])) {
$result[$row['path']] = [];
}

if ($row['mapping_type'] !== null) {
$rule = $this->createRule($row);
if ($rule) {
$result[$row['path']][] = $rule;
}
}
}

return $result;
}

Expand Down Expand Up @@ -201,11 +205,13 @@ private function rulesByPath(array $rows, array $result = []): array {
if (!isset($result[$row['path']])) {
$result[$row['path']] = [];
}

$rule = $this->createRule($row);
if ($rule) {
$result[$row['path']][] = $rule;
}
}

return $result;
}

Expand Down Expand Up @@ -267,6 +273,7 @@ private function hasRule(IUserMapping $mapping, int $fileId): bool {
->where($query->expr()->eq('fileid', $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('mapping_type', $query->createNamedParameter($mapping->getType())))
->andWhere($query->expr()->eq('mapping_id', $query->createNamedParameter($mapping->getId())));

return (bool)$query->executeQuery()->fetch();
}

Expand Down
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function register(IRegistrationContext $context): void {
$context->registerService('GroupAppFolder', function (ContainerInterface $c): Folder {
/** @var IRootFolder $rootFolder */
$rootFolder = $c->get(IRootFolder::class);

return new LazyFolder($rootFolder, function () use ($rootFolder) {
try {
return $rootFolder->get('__groupfolders');
Expand Down Expand Up @@ -136,6 +137,7 @@ public function register(IRegistrationContext $context): void {
if ($hasVersionApp) {
$trashBackend->setVersionsBackend($c->get(VersionsBackend::class));
}

return $trashBackend;
});

Expand Down Expand Up @@ -214,6 +216,7 @@ public function register(IRegistrationContext $context): void {
$rootFolderProvider = function () use ($c): \OCP\Files\IRootFolder {
return $c->get(IRootFolder::class);
};

return new ACLManagerFactory(
$c->get(RuleManager::class),
$c->get(TrashManager::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 getCapabilities(): array {
if (!$user) {
return [];
}

return [
Application::APP_ID => [
'appVersion' => $this->appManager->getAppVersion(Application::APP_ID),
Expand Down
3 changes: 2 additions & 1 deletion lib/AuthorizedAdminSettingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AuthorizedAdminSettingMiddleware extends Middleware {
public function __construct(
DelegationService $delegatedService,
IControllerMethodReflector $reflector,
IRequest $request
IRequest $request,
) {
$this->delegatedService = $delegatedService;
$this->reflector = $reflector;
Expand Down Expand Up @@ -63,6 +63,7 @@ public function afterException($controller, $methodName, \Exception $exception):
$response = new TemplateResponse('core', '403', ['message' => $exception->getMessage()], 'guest');
$response->setStatus((int)$exception->getCode());
}

return $response;
}
}
3 changes: 2 additions & 1 deletion lib/BackgroundJob/ExpireGroupTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
TrashBackend $trashBackend,
Expiration $expiration,
IConfig $config,
ITimeFactory $timeFactory
ITimeFactory $timeFactory,
) {
parent::__construct($timeFactory);
// Run once per hour
Expand All @@ -39,6 +39,7 @@ protected function run($argument) {
if ($backgroundJob === 'no') {
return;
}

$this->trashBackend->expire($this->expiration);
}
}
4 changes: 3 additions & 1 deletion lib/CacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use OCP\Files\Cache\ICacheEvent;

class CacheListener {
public function __construct(private IEventDispatcher $eventDispatcher) {
public function __construct(
private IEventDispatcher $eventDispatcher,
) {
}

public function listen(): void {
Expand Down
Loading
Loading