Back

[CLOSED] Document security based on attribute

  • 0
  • Web
rahul3v
12 Aug, 2023, 07:40

any example you can refer

TL;DR
The user is asking for an example of conditionally setting document security based on attributes. They want to restrict access to a document based on a specific attribute like 'isPublic'. The support suggests using role-based permissions and provides an example using the Supabase documentation. The user insists on attribute-based conditions and wants it to work on the client side. The support explains that using an attribute is not a good practice and suggests using role-based permissions. The user insists on attribute-based access and mentions that Supabase provides it. The support asks for clarification on where this is explained in Supabase and expresses confusion. Solution: The support
safwan
12 Aug, 2023, 07:40

Okay can you explain what you mean by conditionally setting document security?

safwan
12 Aug, 2023, 07:41

If you're trying to restrict access based on the user, it's possible.

safwan
12 Aug, 2023, 07:41

Have you looked at this by any chance? https://appwrite.io/docs/permissions#example-1

rahul3v
12 Aug, 2023, 07:42

i am taking about attribute based conditin, not role boesd

rahul3v
12 Aug, 2023, 07:43

role based examples are there, what I can tell from doc

safwan
12 Aug, 2023, 07:43

For example, if there is a user with name Safwan, email as safwan@example.com and user id as 7b9c24929ncnmc11, then you can use the Permission.role(Role.user('7b9c24929ncnmc11')) and only that user will be able to read the document

safwan
12 Aug, 2023, 07:43

Attribute as in?

rahul3v
12 Aug, 2023, 07:44

i need something like in a documnet an attribute called let say isPublic which set to boolean, and based on that i will enable the access

safwan
12 Aug, 2023, 07:45

so this isPublic attribute will be set for each document right?

rahul3v
12 Aug, 2023, 07:45

yup

safwan
12 Aug, 2023, 07:45

and do you plan on setting this attribute manually from the dashboard, or through your client side code, when using createDocument?

rahul3v
12 Aug, 2023, 07:46

any way, I don;t think that matters here

rahul3v
12 Aug, 2023, 07:46

while reading the documnet i need to check if anyone try to access the documnet

rahul3v
12 Aug, 2023, 07:47

I can omit it using serverside code

safwan
12 Aug, 2023, 07:47

It kind of does because if you're doing it through code, you can just create that document with Permission.read(Role.any())

rahul3v
12 Aug, 2023, 07:48

but I needed that to work on client, otherwise what; the use here using it , right

safwan
12 Aug, 2023, 07:48

I don't see why you need an attribute to do this? Even if you were to use an attribute, you'll have to fetch the document, see if it's isPublic is set to false or true, and based on that move forward. This isn't good practice I believe.

rahul3v
12 Aug, 2023, 07:48

but that's is role based, that's what I was trying to say

safwan
12 Aug, 2023, 07:49

This will work on client.

rahul3v
12 Aug, 2023, 07:49

I don;t think, is required, supabase is providing that

safwan
12 Aug, 2023, 07:49

Yes but the role is user. So every user will have to satisfy the condition.

rahul3v
12 Aug, 2023, 07:50

Sometime we need, is useful creating internal role based access in project

safwan
12 Aug, 2023, 07:50

Can I ask where this is explained in Supabase? I wanna make sure I understand what's happening

safwan
12 Aug, 2023, 07:51

I'm sorry I don't quite undersatnd what you meant

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