diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 89e26abafd..69d01e9dc7 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -232,6 +232,7 @@ $utopia->get('/v1/database/collections/:collectionId/logs') $response->json($output); } ); + $utopia->put('/v1/database/collections/:collectionId') ->desc('Update Collection') ->label('scope', 'collections.write') @@ -416,6 +417,18 @@ $utopia->post('/v1/database/collections/:collectionId/documents') $data = $parentDocument->getArrayCopy(); } + /** + * Set default collection values + */ + foreach ($collection->getAttribute('rules') as $key => $rule) { + $key = (isset($rule['key'])) ? $rule['key'] : ''; + $default = (isset($rule['default'])) ? $rule['default'] : null; + + if(!isset($data[$key])) { + $data[$key] = $default; + } + } + try { $data = $projectDB->createDocument($data); } catch (AuthorizationException $exception) { diff --git a/app/views/console/database/collection.phtml b/app/views/console/database/collection.phtml index f4de51589c..4375dd4f12 100644 --- a/app/views/console/database/collection.phtml +++ b/app/views/console/database/collection.phtml @@ -68,16 +68,20 @@
| + | |
|---|---|
| - + + + Linked Documents + Linked Document + |