horizon
horizon copied to clipboard
Give some way for permissions to look at data other than the current document
There have been a couple of mentions about how the validators are a bit limited at the moment since you can only look at the document and the context. There are a couple ways I can think of to modify this:
- Allow whatever reql you want from the validator. This has the problem that validators would no longer be synchronous. It's also probably pretty hard to optimize, since the validator is a black box that can do basically anything.
- Allow specifying extra reql queries you want to be passed to the validator. This has the benefit of giving us more we can statically optimize (maybe creating a changefeed on the data so we don't have to run it each time data come through). But it extends the config language a bit more, pushing us into "huge bloated config language" territory (maybe).
- RethinkDB might grow
ref
types (see rethinkdb/rethinkdb#4853). This would keep everything mostly the same on the Horizon end, but users could get data from other tables in the document itself. (They'd have to add out-references though, so this may still put some restrictions on how the users design their data scheme) - Do nothing, say you need to do custom validation and write your own backend if you want this flexibility.
3 for me.
- It keeps everything synchronous
- It doesn't complicate anything for those who don't need relations
- It simplifies and solves relational permissions
- ref's could sort relational queries on the client?
- It seems like a best-practice approach to both permission configuration and client queries
sharing my use case - I'm trying to build a multi-tenant content management system, and want to make 'collections' of documents that can be edited only by some users. I store metadata regarding my collections in a table called 'collections', which contains which users are allowed to edit which docs. So I'd like to allow writes/reads to a collection(/table) only if the user is in a field in a corresponding field in the 'collections' table.
So 2 things prevent me from doing this in horizon right now -
- the ability to specify wildcards/regexes for collection names in query templates (since collections can be created on the fly)
- async/reql validation, based on data in another table
I'm ok with validation being asynchronous/a black box. As an example implementation detail, the validator function could take an optional done
callback, to be called by the validator when it's finished.
Looking forward to a solution for this too.
My use case is very similar to @threepointone's. The schema is pretty complex and has different layers of access.