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.

This commit is contained in:
shimon
2025-11-02 21:24:11 +02:00
parent dbccb16784
commit c13aed651a
3 changed files with 6 additions and 7 deletions
+2 -4
View File
@@ -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);
@@ -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) {
@@ -91,7 +91,8 @@ class Create extends Action
$response,
$dbForProject,
$queueForDatabase,
$queueForEvents
$queueForEvents,
$authorization
);
$response