Merge pull request #979 from appwrite/fix-update-doc-permissions

Allow permission reset
This commit is contained in:
Eldad A. Fux 2021-03-16 13:09:00 +02:00 committed by GitHub
commit 355cdd74a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 12 deletions

View file

@ -366,7 +366,6 @@ From time to time, our team will add tutorials that will help contributors find
* [Appwrite Environment Variables](./docs/tutorials/environment-variables.md)
* [Running in Production](./docs/tutorials/running-in-production.md)
## Other Ways to Help
Pull requests are great, but there are many other areas where you can help Appwrite.

View file

@ -535,20 +535,12 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId')
throw new Exception('No document found', 404);
}
//TODO check merge read write permissions
if (!empty($read)) { // Overwrite permissions only when passed
$data['$permissions']['read'] = $read;
}
if (!empty($write)) { // Overwrite permissions only when passed
$data['$permissions']['write'] = $write;
}
$data = \array_merge($document->getArrayCopy(), $data);
$data['$collection'] = $collection->getId(); // Make sure user don't switch collectionID
$data['$id'] = $document->getId(); // Make sure user don't switch document unique ID
$data['$permissions']['read'] = $read;
$data['$permissions']['write'] = $write;
if (empty($data)) {
throw new Exception('Missing payload', 400);

View file

@ -434,7 +434,9 @@ trait DatabaseBase
], $this->getHeaders()), [
'data' => [
'name' => 'Thor: Ragnarok'
]
],
'read' => ['user:'.$this->getUser()['$id']],
'write' => ['user:'.$this->getUser()['$id']],
]);
$this->assertEquals($document['headers']['status-code'], 200);