
Hey, I just want to update the permission of a document in PHP for a user to for example read. How do I do that? I cant get it to work. My current solution is this: ```$databaseId = 'games'; $collectionId = 'pool'; $documentId = $_GET['document_id'] ?? null; $userId = $_GET['user_id'] ?? null;
$database = new Databases($client);
try {
// Retrieve the existing document
$document = $database->getDocument($databaseId, $collectionId, $documentId);
print_r($document);
$readPermissions = $document['$permissions']['read'] ?? [];
// Add the user to the read permissions if not already present
if (!in_array("user:$userId", $readPermissions)) {
$readPermissions[] = "user:$userId";
}
// Update the document with the new read permissions
$result = $database->updateDocument($databaseId, $collectionId, $documentId, $document, $readPermissions);
echo "Document updated successfully.";
} catch (Exception $e) {
echo "Error updating document: " . $e->getMessage();
}```

I get the error: Error updating document: Invalid permissions: Permission "user:X" is not allowed. Must be one of: read, update, delete, write.

Btw, it's best to use 3 back ticks with multi-line code. See https://www.markdownguide.org/extended-syntax/#syntax-highlighting

ah sorry

I think you should add him to the ['read']
part of the array
if (!in_array("user:$userId", $readPermissions)) {
$readPermissions['read'][] = "user:$userId";
}

And create this part if it doesn't exist

Error updating document: Invalid permissions: Every permission must be of type string.

I also tried it with the [] gone but then the same error occurs as in the question.

You might want to take a look at what $document['$permissions']
is. Also, see: https://appwrite.io/docs/permissions

So I basically have to add use Appwrite\Models\Permission;
and then use Permission::delete(Permission::ROLE_USER, '5c1f88b42259e'),
?

Erre

Close

Whats missing?

Role::User('id')
And, btw, permissions is a list (rather than associative array)

ah okay


thanks that helped a lot! its working now.

[SOLVED] PHP Update Document Permission
Recommended threads
- unexpected row_invalid_structure error
In images you can see both my code,error, column schema I do have timezone in table schema but still while creating a row i am receving row_invalid_structure e...
- Internal 500 Server Error
I don't have much information but I am unable to create anything on database, Auth users are creating but not able to fetch into database
- Data sending problem having
<#564161373148414012> 🚑│support <#564161373148414012> have few problems in my project running on appwrite . Data is not sending to database .is any update or...
