I want to create a role based application where there will be one user role and another one will be admin role. Admin will be able to add blogs to the website directly while the users have to send request to the admin via a contact form.
I haven't done this kind of thing before. It's gonna be a React app. So, need help and directions.
Summary
The user wants to create a role-based application where there are two roles: user and admin. The admin should be able to directly add blogs to the website, while users have to send a request to the admin via a contact form. They are seeking help and directions for this in a React app.
Solution:
- Create two collections: `posts` and `posts_submissions` for users.
- Create an admin team (`admin`) and add the admin user to this team.
- set permissions for the `posts` collection to allow any read and write access by the `team:admin`.
- Enable document security for the `posts_sub
Binyamin
May 16, 2023, 15:02
That's will probably be a more diffcult to demonstrate, but here's are main guidelines.
Teams & Rules
Appwrite offers two ways to separate users.
Admin runs function "A" (suppose) and this function allows the admin to post the blog directly.
So, for user:
User runs a function "B" and this function sends a call to a different function "C" which will act as the interface/connecting point between user and admin. Function C is called and it checks with admin for permissions, if the permission is granted, the function returns back to B and tells the user about permission being granted. Next lines in B are, using backend logic you can make the admin run their own logic of A to post the blog.
Does this logic help?
Using roles will be a very good help here.
Susmita
Rank 3: Container
May 18, 2023, 06:45
logic is good but I might get stuck.
Susmita
Rank 3: Container
May 18, 2023, 06:46
Let me first try with all users thing
Susmita
Rank 3: Container
May 18, 2023, 06:46
After that I'll think about the admin role
dlohani
May 18, 2023, 07:16
How I would do it
Create two collections (posts, posts_submissions for users)
create admin team (admin) and add admin user to this team
posts permission -> any read, write: team:admin
posts_submissions -> document security turned on, give create permission to any logged in users, and write permission to team:admin for document give read and write permission user:userId (creator)
When user log in, check if they are admin via team membership
If admin -> submit post should save to posts collection
if not admin -> submit post should save to posts_submissions collection
For this all you need to change is the collection ID based on if user is admin and server side permissions will validate if user try to mess around
you can make a admin panel where admins can see lists of posts in posts_submission and when they click publish/accept -> create on posts and delete from posts_submissions
Susmita
Rank 3: Container
May 18, 2023, 07:19
Great! I'll try this out
dlohani
May 18, 2023, 07:20
Do you like this solution ?
Susmita
Rank 3: Container
May 18, 2023, 07:20
Yes
dlohani
May 18, 2023, 08:24
Let me know how it goes when you do.
safwan
May 18, 2023, 09:24
pretty much the same thing I do for my mobile app. +1
Susmita
Rank 3: Container
May 18, 2023, 10:13
Sure!
joeyouss
Jun 1, 2023, 19:56
Hi @Susmita shall we close this if its resolved?
Susmita
Rank 3: Container
Jun 2, 2023, 05:34
Close this. I'll open later on if needed. Currently not working with roles.