SaaS privacy rules

I’m building an app where a user can create one or multiple “companies”.

Inside each company it is data like customers, tasks, deals, contracts and files. (In separate data types with “company”-field connecting them to the company)

A user can create a company, or get access to companies (included everything connected to the company) created by other.

Each user gets an userRole for each company. (Admin, owner, user, guest).

I want the user to be able to see all data from the companies the user have access to.

Do anyone have a good solution for this with privacy rules?

When Current User’s Companies (list of Company) contains This X’s Company it should be visible should do the trick for this as all user roles should have the same view permissions?

Then you might have a Company Role data type which contains Company, User, and Role and on the User you have a list of Company Roles that keep track of all of the permissions for each company.

@georgecollier , Thank you for answering!

I agree on the first one, and this is something ive already got. But im still confused about the best way to make the userroles.

Today i have:
User (with a UserAccess)
UserAccess (with User, adminProperty, userProperty, guestProperty)
Property
Task (With a property field)

So today i have
Current UserS userAccesss adminCompany contains This X`s Company

This works, but i have to add new field of companies for every userRole i want to create.

I like your idea, but im wondering how the structure and privacy rules have to be here.

Any company a user should have access to should be on the Current User’s Companies. That’s for your privacy rules, because from the sound of your setup, all of your user roles should be able to view the data for the company.

Why do you need different privacy rules for each role? If different roles have different view permissions, then you do just need a user access data type and to define the rules for each rule.