RavenDB Queries - Cross cutting concerns

57 views
Skip to first unread message

racielrod

unread,
Jun 1, 2012, 12:22:31 PM6/1/12
to ravendb
Hello,

I need to make sure certain constrains are applied to all my queries:

1) Every user in the system can see certain clients only, so every
query should only return documents for those clients.
2) Every user is in a role, if you are in the lowest role you can only
see the documents you created/

In the very first stage of this project I implemented this by using
the repository pattern and made sure this concerns were handled in the
base repository.
I had an horrible experience with this pattern and the worst part
about sharing this base queries is the impossibility of using specific
indexes if your queries are built upon this base queries.

So the question is, what is the best practice to deal with this cross
cutting concerns?

Matt Warren

unread,
Jun 1, 2012, 3:25:52 PM6/1/12
to rav...@googlegroups.com
Take a look at the Authorization bundle, it should handle these scenarios for you, see:

http://ravendb.net/docs/server/bundles/authorization
http://ravendb.net/docs/server/bundles/authorization-bundle-design

codin...@googlemail.com

unread,
Jun 1, 2012, 3:35:01 PM6/1/12
to rav...@googlegroups.com
Check out the bundles. There's one there which exactly fits your needs :)

Sent from my iPhone

racielrod

unread,
Jun 1, 2012, 3:45:17 PM6/1/12
to rav...@googlegroups.com
Thanks Matt,

While this would be a great fix for the scenario I described above I'm more interested on addressing common query concerns w/o having to repeat them over and over again.
In order to walk away of the authorization context I put as an example above, let's use another examples:

What if a set of pre-conditions are part of certain group of queries. For instance, for certain department they only need to deal with documents with the following characteristics:

1) Users are older than 18 yo.
2) Females.
3) Approved.
4) Living on certain area: state, city, etc...
...
n)...

What if you have several queries that use those pre-conditions; I don't want to repeat over and over the where clauses in my queries.

Oren Eini (Ayende Rahien)

unread,
Jun 1, 2012, 7:12:26 PM6/1/12
to rav...@googlegroups.com
Raciel,
You have IDocumentQueryListener, which allows you to modify each query before it is actually executed.

racielrod

unread,
Jun 2, 2012, 3:54:09 PM6/2/12
to rav...@googlegroups.com
Thanks, I'm going to take a look at this...


On Friday, June 1, 2012 7:12:26 PM UTC-4, Oren Eini wrote:
Raciel,
You have IDocumentQueryListener, which allows you to modify each query before it is actually executed.

Reply all
Reply to author
Forward
0 new messages