How can I set permissions for create_operations()? What even is the correct way to use permissions in Python (using SDK version 13.4.1) ? In my cloud function creating a table works and sets the correct permissions:
database_id,
table_id=user_id,
name=user_name,
permissions=[
Permission.read(Role.user(user_id)),
Permission.write(Role.user(user_id)),
],
)```
but subsequently using `create_operations()` creates a row but does not see any permissions:
tablesDB.create_operations( transaction_id=transaction_id["$id"], operations=[ { "action": "create", "databaseId": userDB_id, "tableId": os.environ["POLICY_COLL_ID"], "rowId": f"{user_id}-policy", "data": { "acceptedTimestamp": datetime_truncated }, "permissions": [ Permission.read(Role.user(user_id)), Permission.write(Role.user(user_id)), ], }, ) ```
I realize this may be an older syntax since I can see this example in the docs at https://appwrite.io/docs/references/cloud/server-python/tablesDB:
result = tables_db.create_table(
database_id = '<DATABASE_ID>',
table_id = '<TABLE_ID>',
name = '<NAME>',
permissions = ["read("any")"], # optional
row_security = False, # optional
enabled = False # optional
)
I looked at https://github.com/appwrite/sdk-for-python/blob/main/appwrite/permission.py and https://github.com/appwrite/sdk-for-python/blob/main/appwrite/role.py.
The API documentations is a bit misleading since the "any" should not have any ticks. So my function now works like this:
table = tablesDB.create_table(
database_id,
table_id=user_id,
name=user_name,
permissions=[
f"read(user:{user_id})",
f"write(user:{user_id})",
],
)
but his gives me the error Invalid permissions param: Invalid permission string format: "read(user:68f23ce0001235******). Using the double quotes in string like in the documentations example leads to a formatting error, which then lead to me realizing I need to format them differently.
This now works:
tablesDB.create_operations(
transaction_id=transaction_id["$id"],
operations=[
{
"action": "create",
"databaseId": userDB_id,
"tableId": os.environ["POLICY_COLL_ID"],
"rowId": f"{user_id}-policy",
"data": {
"acceptedTimestamp": datetime.datetime.now(
datetime.timezone.utc
).isoformat()
},
"permissions": [
f'read("user:{user_id}")',
f'write("user:{user_id}")',
],
},
],
)
So use single quotes on the outside and double quotes on the inside!
[SOLVED] Permissions in create_operations() Python SDK
Permissions in create_operations() Python SDK
I now realized that this only worked for the create_table() function.
Using the working string for create_table does not work for create_operations() unfortunately...
Will move back away from create_operations() for now and might move the function to another runtime anyway, in Deno it works with like the documentation.
Recommended threads
- MongoDb Database Breaks integer[] & bigi...
I've got a table with the below column created. When I try to insert the value `[-3408048000]` into it, the dart sdk cloud function call is successful (no error...
- Missing Invoice
Hi! I need help with billing on my account (marelu@gmail.com). I have never received a single invoice by email. My organization has been on the Pro plan since...
- Appwrite Functions cold start
Hello. I'm seeing really long cold starts on Appwrite Cloud Functions and wanted to know if this is expected. My function just authenticates the user, fetches ...