[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-10 Thread desta
Thanks Anthony, indeed I will have to evaluate the tradeoff of speed for complexity. I don't think that our site will have the amount of traffic that this would be a problem but its always good to know good practices! A friend suggested to use db((db.task.id == 5) (db.task.ref_to_job ==

[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-10 Thread Anthony
db((db.task.id == 5) (db.task.ref_to_job == db.job.id) (db.job.ref_to_project == db.project.id) (db.project.owner == auth.user_id)) I tried it and it works, but I am not sure how different it is from the one Leonel suggested. How does this work? The above does a join, so it gets

[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread Leonel Câmara
Frankly, I would just store the user as the owner in all of those tables. Probably using auth.signature(). You could do a very inefficient recursive select but I don't see any advantage. Something like: task = db.tasks[5] if task.job.project.owner != auth.user_id: # You are doing a select

[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread desta
Thank you, so you mean is bad practice the way I implemented the tables? When I designed it like that, I thought it would be convenient in altering the relations between the records. On Monday, September 8, 2014 11:47:57 AM UTC+3, Leonel Câmara wrote: Frankly, I would just store the user as

[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread Leonel Câmara
It's not exactly bad practice, quite the contrary, usually you want to start with a database without redundancy. This is just a case where denormalization really yields fruits as it is very inefficient to have to query the jobs and projects table to know who is the owner of a task. An

Re: [web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread Marin Pranjić
Make sure to read Authorization chapter in book: http://web2py.com/books/default/chapter/29/09/access-control#Authorization -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list

Re: [web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread desta
Thank you guys for your valuable answers. On Monday, September 8, 2014 2:51:56 PM UTC+3, Marin Pranjić wrote: Make sure to read Authorization chapter in book: http://web2py.com/books/default/chapter/29/09/access-control#Authorization -- Resources: - http://web2py.com -

[web2py] Re: Check is user is the owner of row (help with db query)

2014-09-08 Thread Anthony
On Monday, September 8, 2014 4:47:57 AM UTC-4, Leonel Câmara wrote: Frankly, I would just store the user as the owner in all of those tables. Probably using auth.signature(). You could do a very inefficient recursive select but I don't see any advantage. Something like: task =