Merge pull request #10389 from appwrite/fix-request-filter

Fix request filter
This commit is contained in:
Jake Barnby 2025-08-27 17:18:34 +12:00 committed by GitHub
commit b783d81b7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 59 additions and 21 deletions

View file

@ -874,7 +874,7 @@ App::init()
}
if (version_compare($requestFormat, '1.8.0', '<')) {
$dbForProject = $getProjectDB($project);
$request->addFilter(new RequestV20($dbForProject, $request->getParams()));
$request->addFilter(new RequestV20($dbForProject, $route->getPathValues($request)));
}
}

View file

@ -179,7 +179,7 @@ $image = $this->getParam('image', '');
appwrite-console:
<<: *x-logging
container_name: appwrite-console
image: <?php echo $organization; ?>/console:6.2.0
image: <?php echo $organization; ?>/console:7.0.2
restart: unless-stopped
networks:
- appwrite

View file

@ -219,7 +219,7 @@ services:
appwrite-console:
<<: *x-logging
container_name: appwrite-console
image: appwrite/console:7.0.0-qa.8
image: appwrite/console:7.0.2
restart: unless-stopped
networks:
- appwrite

View file

@ -96,36 +96,74 @@ class V20 extends Filter
/**
* Returns all relationship attribute keys in `key.*` format for use with `Query::select`.
*/
private function getRelatedCollectionKeys(): array
{
$dbForProject = $this->getDbForProject();
private function getRelatedCollectionKeys(
?string $databaseId = null,
?string $collectionId = null,
?string $prefix = null,
int $depth = 1,
): array {
$databaseId ??= $this->getParamValue('databaseId');
$collectionId ??= $this->getParamValue('collectionId');
if (
empty($databaseId) ||
empty($collectionId) ||
$depth > Database::RELATION_MAX_DEPTH
) {
return [];
}
$dbForProject = $this->getDbForProject();
if ($dbForProject === null) {
return [];
}
$databaseId = $this->getParamValue('databaseId');
$collectionId = $this->getParamValue('collectionId');
if (empty($databaseId) || empty($collectionId)) {
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
return [];
}
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
$collection = $dbForProject->getDocument(
$collection = Authorization::skip(fn () => $dbForProject->getDocument(
'database_' . $database->getSequence(),
$collectionId
);
));
if ($collection->isEmpty()) {
return [];
}
$attributes = $collection->getAttribute('attributes', []);
$relationshipKeys = [];
return \array_values(\array_map(
fn ($attr) => $attr['key'] . '.*',
\array_filter(
$attributes,
fn ($attr) => ($attr['type'] ?? null) === Database::VAR_RELATIONSHIP
)
));
foreach ($attributes as $attr) {
if (
($attr['type'] ?? null) !== Database::VAR_RELATIONSHIP ||
$attr['status'] !== 'available'
) {
continue;
}
$key = $attr['key'];
$fullKey = $prefix ? $prefix . '.' . $key : $key;
// Add the wildcard select for this relationship
$relationshipKeys[] = $fullKey . '.*';
// Get the related collection for nested relationships
$relatedCollectionId = $attr['relatedCollection'] ?? null;
if ($relatedCollectionId) {
// Recursively get nested relationship keys
$nestedKeys = $this->getRelatedCollectionKeys(
$databaseId,
$relatedCollectionId,
$fullKey,
$depth + 1,
);
$relationshipKeys = \array_merge($relationshipKeys, $nestedKeys);
}
}
return \array_values(\array_unique($relationshipKeys));
}
}