From c13aed651ae811b71ff265032176e2df005d1050 Mon Sep 17 00:00:00 2001 From: shimon Date: Sun, 2 Nov 2025 21:24:11 +0200 Subject: [PATCH] Refactor storage file retrieval to use queries directly for counting, improving consistency in authorization handling. Update Action class to remove unnecessary authorization skip, and include authorization in Email/Create class constructor for better dependency management. --- app/controllers/api/storage.php | 6 ++---- .../Http/Databases/Collections/Attributes/Action.php | 4 ++-- .../Http/Databases/Collections/Attributes/Email/Create.php | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 9a211ba290..beb212b0ef 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -842,15 +842,13 @@ App::get('/v1/storage/buckets/:bucketId/files') $cursor->setValue($cursorDocument); } - $filterQueries = Query::groupByType($queries)['filters']; - try { if ($fileSecurity && !$valid) { $files = $dbForProject->find('bucket_' . $bucket->getSequence(), $queries); - $total = $includeTotal ? $dbForProject->count('bucket_' . $bucket->getSequence(), $filterQueries, APP_LIMIT_COUNT) : 0; + $total = $includeTotal ? $dbForProject->count('bucket_' . $bucket->getSequence(), $queries, APP_LIMIT_COUNT) : 0; } else { $files = $authorization->skip(fn () => $dbForProject->find('bucket_' . $bucket->getSequence(), $queries)); - $total = $authorization->skip(fn () => $dbForProject->count('bucket_' . $bucket->getSequence(), $filterQueries, APP_LIMIT_COUNT)); + $total = $includeTotal ? $authorization->skip(fn () => $dbForProject->count('bucket_' . $bucket->getSequence(), $queries, APP_LIMIT_COUNT)) : 0; } } catch (NotFoundException) { throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 9bf487bca2..6c5305f299 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -614,7 +614,7 @@ abstract class Action extends UtopiaAction } } else { try { - $authorization->skip(fn () => $dbForProject->updateAttribute( + $dbForProject->updateAttribute( collection: $collectionId, id: $key, size: $size, @@ -622,7 +622,7 @@ abstract class Action extends UtopiaAction default: $default, formatOptions: $options, newKey: $newKey ?? null - )); + ); } catch (DuplicateException) { throw new Exception($this->getDuplicateException()); } catch (IndexException $e) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php index e848dec37c..c6dd85be75 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php @@ -91,7 +91,8 @@ class Create extends Action $response, $dbForProject, $queueForDatabase, - $queueForEvents + $queueForEvents, + $authorization ); $response