Allow 'unique()' for nested document IDs

This commit is contained in:
Jake Barnby
2023-03-31 17:33:21 +13:00
parent 05d7badd60
commit bf4e2df45b
2 changed files with 23 additions and 4 deletions
+21 -4
View File
@@ -2739,9 +2739,15 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents')
fn() => $dbForProject->getDocument('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(), $relation->getId())
);
$type = $current->isEmpty()
? Database::PERMISSION_CREATE
: Database::PERMISSION_UPDATE;
if ($current->isEmpty()) {
$type = Database::PERMISSION_CREATE;
if (isset($relation['$id']) && $relation['$id'] === 'unique()') {
$relation['$id'] = ID::unique();
}
} else {
$type = Database::PERMISSION_UPDATE;
}
$checkPermissions($relatedCollection, $relation, $type);
}
@@ -3304,7 +3310,18 @@ App::patch('/v1/databases/:databaseId/collections/:collectionId/documents/:docum
'database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId(),
$relation->getId()
));
$checkPermissions($relatedCollection, $relation, $oldDocument);
if ($oldDocument->isEmpty()) {
$type = Database::PERMISSION_CREATE;
if (isset($relation['$id']) && $relation['$id'] === 'unique()') {
$relation['$id'] = ID::unique();
}
} else {
$type = Database::PERMISSION_UPDATE;
}
$checkPermissions($relatedCollection, $relation, $oldDocument, $type);
}
}
}
+2
View File
@@ -217,7 +217,9 @@ class DatabaseV1 extends Worker
throw new Exception('Failed to delete Attribute');
}
}
$dbForProject->deleteDocument('attributes', $attribute->getId());
if (!$relatedAttribute->isEmpty()) {
$dbForProject->deleteDocument('attributes', $relatedAttribute->getId());
}