Back

[SOLVED] permission and membership

  • 0
  • Teams
  • Flutter
Mickaël LT
9 Aug, 2023, 08:53

Hi, I want to create a new document (from my flutter app) and share this document with another user. I can't do it quickly because user can't add permission to another user id. We have to be in a team. But now I have add all users to a team and if i want to add my permission, my user had to know the membership id of the other user... So I have to do a request to get the membership id, and then adding the permission with this team & membership id... Is there a way to add permission with only the other user id ?

TL;DR
The user wants to add permissions to a document for another user without using teams. However, this is not possible as permissions can only be added to teams or memberships. The user is suggested to create an Appwrite Function that retrieves the ID of the other user and then add permissions using that ID. The user expresses concern about having to know the membership ID of the other user. The solution provided is to make a request to get the membership ID and then add the permission using the team and membership ID. The user asks if there is a way to add permission using only the other user ID, but that is not possible.
joeyouss
9 Aug, 2023, 09:12

I am sorry if I don't understand correctly but, in your database, you do have the option to give permissions without using teams , is this something you need?

safwan
9 Aug, 2023, 09:13

Hey @Mickaël LT

safwan
9 Aug, 2023, 09:15

So just to make sure, you're having issues with document security right? If you want User A to be have full access to a document, while making sure User B only had viewing/reading permissions, you can assign the Permission.read(Role.user('[USER-B-ID]')) to the document

safwan
9 Aug, 2023, 09:16

You don't need to have both the users in the same team. If your worry is about getting User B's ID, you can create a small Appwrite Function that does it for you.

safwan
9 Aug, 2023, 09:18

You can accept an email in this function, and use the users.listUsers endpoint along with the email in the query, so get the correct user.

Mickaël LT
9 Aug, 2023, 09:35

Yes, User A create a document from the flutter mobile application (with client SDK). User A want to add user B permission for reading this document. I can do it if I use the server sdk and a function, but I prefere doing it from my app.

Mickaël LT
9 Aug, 2023, 09:36

List<String> perms = []; perms.add(Permission.read(Role.user(otherUserId))); final doc = await databases.createDocument( databaseId: databaseId, collectionId: collectionId, documentId: ID.unique(), data: data.toMap(), permissions: perms );

Mickaël LT
9 Aug, 2023, 09:37

If I do that, I got this error

Mickaël LT
9 Aug, 2023, 09:37

AppwriteException: user_unauthorized, Permissions must be one of: (any, users, user:63e501eb4d6310fbf62c, user:63e501eb4d6310fbf62c/verified, users/verified)

Mickaël LT
9 Aug, 2023, 09:39

And after searching, user can't add permission to other user directly, user can only add permission to team/membership

safwan
9 Aug, 2023, 09:41

Any reason why you want to do it from the client only? It's not possible right now, which is why I suggested an appwrite function instead

Mickaël LT
9 Aug, 2023, 09:49

Because the code already exist in my app 😅 so, don't want to put it in a function, but if this is the only way, I'll do it

Drake
10 Aug, 2023, 20:44

Is your problem resolved now?

Mickaël LT
11 Aug, 2023, 06:23

Yes, I've move my code to a function and now I can add custom permission

joeyouss
11 Aug, 2023, 10:53

[SOLVED] permission and membership

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