Back

[SOLVED] Setting document permissions for another user when creating a document in a collection

  • 0
  • Databases
  • Users
Al
4 Feb, 2024, 21:28

I have document level security on and want to implement simple sharing mechanism in app I'm building when a record represented by Appwrite document can be made visible for another user. I created code for creating a document which works fine when operating logged user's ID (I can set permissions for logged user for read/update/delete without issues with this code), but as soon as I add a read permission for another user to the permissions array, I have appwrite exception, see the screenshot. Is it not allowed to set permissions for other users from client side even if it's read-only? If this is indeed the cause, what is the best way to implement per-user and per-document sharing mechanism? Thanks.

TL;DR
[SOLVED] When creating a document in a collection, you can set document permissions for another user. The solution is to use an Appwrite function, written in Dart, to set the permissions. This can be done in the Appwrite console without any restrictions. It is possible to create a team containing both the current user and the user with whom the document is to be shared, and set permissions for the team. However, this may not be ideal for a per-user sharing use case. It is suggested to add information about setting document permissions to the Permissions page in the Appwrite Docs.
Al
4 Feb, 2024, 21:30

Also, I am able to set the required permissions in Appwrite console without a problem, which leads to this suggestion that it might be some client side restriction.

Al
4 Feb, 2024, 21:35

I just tried to create a team which contains both current user and user with whom the document is to be shared with and then setting a permission for a team and it works. But this is clunky to apply to per-user sharing use case and I'm not sure about potential performance applications of always creating a team when doing a per-user sharing.

D5
4 Feb, 2024, 21:36

In the console you should not have restrictions when setting document/collection permissions

Al
4 Feb, 2024, 21:36

Thanks D5, the original issue is indeed about client side (I am working on Flutter app where there is a possibility to do per-user sharing of records).

D5
4 Feb, 2024, 21:37

For that case, if you want to set permissions for other users, you should use an appwrite function. You can write it in Dart too

D5
4 Feb, 2024, 21:38

By default, it's only "allowed" creating permissions for the team/s where the user is and for itself

Al
4 Feb, 2024, 21:40

Ok I see how I can do that with functions, perhaps based on an additional field in the collection, thanks.

Al
4 Feb, 2024, 21:40

And good to have confirmation on restrictions.

Al
4 Feb, 2024, 21:41

[SOLVED] Setting document permissions for another user when creating a document in a collection

D5
4 Feb, 2024, 21:41

Perfect. The restrictions are mainly for security reasons 😅

Al
4 Feb, 2024, 21:42

Some flexiblity in setting up securing restriction could be nice I guess, but I see how it is not a key priority right now as there are workarounds.

D5
4 Feb, 2024, 21:42

Well, the main priority is security, and that's why it has been set that way

Al
4 Feb, 2024, 21:43

May I also suggest adding this information to the Permissions page in Docs? I was reading it before posting the issue, but it's not mentioned there.

Al
4 Feb, 2024, 21:43

Not sure if I can contribute to it

D5
4 Feb, 2024, 21:43

It has been added

Al
4 Feb, 2024, 21:44

My apologies, just re-read that paragraph 😄

Al
4 Feb, 2024, 21:44

need to wake up, sorry for wasting your time

D5
4 Feb, 2024, 21:44

Nope, not wasting my time, I'm here to help 😁

Al
4 Feb, 2024, 21:45

thanks a million

D5
4 Feb, 2024, 21:45

Thanks to you! Great that solves your doubt and issue, if you face any other issues or need help while making the function don't hesitate to create another post and we will try to help 😁

D5
4 Feb, 2024, 21:45

I'm pinning the solution

D5
4 Feb, 2024, 21:46
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more