atomicdata-dev / atomic-server

An open source headless CMS / real-time database. Powerful table editor, full-text search, and SDKs for JS / React / Svelte.
https://atomicserver.eu
MIT License
964 stars 45 forks source link

Refactor grants / rights - don't use a ResourceArray #476

Open joepio opened 2 years ago

joepio commented 2 years ago

The Document demo invite is becoming slow. It starts impacting the tests. This is because the ResourceArray of write Agents in the document is starting to contain a lot of URLs. Every time we add one item to it, the back-end has to process quite a bit of data. I know I can find some ways to improve this performance, but the architecture is fundamentally unscalable. Keeping Agent references inside Resources will severely limit how many people will get access to one document.

Basically, currently we use node-based rights. We should consider going to edge-based rights.

One solution is to introduce Groups or Roles.

Another solutions is to put the relationship of Resource :write -> User in a seperate Grant resource: Resource <- :forResource Grant :forUser -> User.

This will be quite the refactor! But I think it needs to be done...

Grant Datamodel

Thoughts:

Editing, querying and viewing Grants

Inspiration for testing scenarios:

What needs to be changed

joepio commented 2 years ago

Design session with @Polleps

Screenshot 2022-08-12 at 17 19 08
joepio commented 2 years ago

Let's walk through how a rights query would be resolved using the graph above. We start with an Agent and a Resource - how do we answer the question if some Agent A has a specific right at a specific resource X?

This is very computationally expensive! How do we make this a tad easier?

But I think we can speed this up more:

This seems to be decently fast on paper. But would it allow users to set rights wihout roles? E.g. John gives Sarah read access? Some solutions:

Should links from Resource to Grant be defined in the Grant or in the Resource? If it's in the Resource, we often get slightly better performance - no need to hit the value index. However, this is not a big impact. Also, it becomes easier to reason about write access to the Grant, because it is in the Resource itself. On the other hand, it will be harder to query on Grants or find all Grants for a person.