Feat - Appwrite Database using Utopia\Database - #1266
Conversation
… into feat-db-refactor-routes
This reverts commit 2c7e65a.
… into feat-db-refactor-routes
… into feat-db-refactor-routes
… into feat-db-refactor-routes
|
|
||
| $dbForExternal = null; | ||
|
|
||
| go(function() use ($register, $projectId, &$dbForExternal) { |
There was a problem hiding this comment.
@TorstenDittmann @kodumbeats are we sure this update has no side effects? Would it be safer to apply the go() function only on the db setup process instead of on any new connection?
… into feat-db-refactor-routes
|
edit: imported incorrect authorization validator - now fixed 👍🏻 Having some trouble with the decrementing team count when deleting a user and their membership. Tests fail because of failing the authorization check in deleteDocument, despite my setting stacktraceappwrite-worker-deletes | Deleting chunk #1. Found 1 documents
appwrite-worker-deletes | [critical] (Job{v1-deletes} | ID: b926c62c45289333ca66c3bcb7c71fad | DeletesV1 | [{"projectId":"60ecbb227e651","type":"document","document":{"$id":"60ecbb2588b9d","$read":["user:60ecbb2588b9d","role:all"],"$write":["user:60ecbb2588b9d"],"email":"[email protected]","emailVerification":false,"status":0,"password":"$2y$08$pOqqbbYadpbk4M3O03ZY9e.Z5.RVfOZb5otBeMwB3bsEI1G1xY8Ni","passwordUpdate":0,"registration":1626127141,"reset":false,"name":"Friend User","prefs":[],"sessions":[],"tokens":[],"memberships":[{"$id":"60ecbb258c770","$read":["role:all"],"$write":["user:60ecbb2588b9d","team:60ecbb249d495\/owner"],"userId":"60ecbb2588b9d","teamId":"60ecbb249d495","roles":["admin","editor"],"invited":1626127141,"joined":1626127141,"confirm":true,"secret":"40ef00d5ebe003b880be5707155f75596dde2a3f4f61eb88f1a55c8c9bb2b4fc","$collection":"memberships"}],"$collection":"users"}}])
has failed Utopia\Database\Exception\Authorization: Missing "write" permission for role "team:60ecbb249d495/owner". Only this scopes "["role:all"]" are given and only this are allowed "["user:60ecbb2588b9d","team:60ecbb249d495\/owner"]". in /usr/src/code/vendor/utopia-php/database/src/Database/Database.php:829
appwrite-worker-deletes | Stack trace:
appwrite-worker-deletes | #0 /usr/src/code/app/workers/deletes.php(271): Utopia\Database\Database->deleteDocument('memberships', '60ecbb258c770')
appwrite-worker-deletes | #1 /usr/src/code/app/workers/deletes.php(399): DeletesV1->deleteById2(Object(Utopia\Database\Document), Object(Utopia\Database\Database), Object(Closure))
appwrite-worker-deletes | #2 /usr/src/code/app/workers/deletes.php(168): DeletesV1->deleteByGroup2('memberships', Array, Object(Utopia\Database\Database), Object(Closure))
appwrite-worker-deletes | #3 /usr/src/code/app/workers/deletes.php(55): DeletesV1->deleteUser2(Object(Appwrite\Database\Document), '60ecbb227e651')
appwrite-worker-deletes | #4 /usr/src/code/src/Appwrite/Resque/Worker.php(22): DeletesV1->run()
appwrite-worker-deletes | #5 /usr/src/code/vendor/resque/php-resque/lib/Resque/Job.php(201): Appwrite\Resque\Worker->perform()
appwrite-worker-deletes | #6 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(303): Resque_Job->perform()
appwrite-worker-deletes | #7 /usr/src/code/vendor/resque/php-resque/lib/Resque/Worker.php(242): Resque_Worker->perform(Object(Resque_Job))
appwrite-worker-deletes | #8 /usr/src/code/vendor/resque/php-resque/bin/resque(185): Resque_Worker->work('1', false)
appwrite-worker-deletes | #9 {main}
|
|
|
||
| $task = new Document([ | ||
| '$id' => $dbForConsole->getId(), | ||
| '$projectId' => $project->getId(), |
There was a problem hiding this comment.
Why do we need this new attribute, and why does it have $ prefix?
There was a problem hiding this comment.
Can remove the $ prefix (used the $collection attribute from the Document model as inspiration):
https://github.com/appwrite/appwrite/blob/feat-db-refactor-routes/src/Appwrite/Utopia/Response/Model/Document.php#L38-L43
However, we do need to pass the projectID to the tasks worker because tasks are stored at the project level:
https://github.com/appwrite/appwrite/blob/feat-db-refactor-routes/app/workers/tasks.php#L70
| 'default' => '', | ||
| 'example' => '5e5ea5c16897e', | ||
| ]) | ||
| ->addRule('$projectId', [ |
There was a problem hiding this comment.
Again, not sure why we need this key.
What does this PR do?
This PR leverages the new Utopia\Database library for the Appwrite Database service.
Test Plan
Unit tests in
utopia-php/databaseand e2e tests hereRelated PRs and Issues
N/A
Have you read the Contributing Guidelines on issues?
Yes.