Let's say I have three tables: users
, books
, and users_books
.
In one of my views, I want to display a list of all the books the current user has access to. A user has access to a book if a row matching a user and a book exists in users_books
.
There are (at least) two ways I can accomplish this:
- In my
fetchAll()
method in thebooks
model, execute ajoin
of some sort on theusers_books
table. - In an Acl plugin, first create a resource out of every book. Then, create a role out of every user. Next, allow or deny users access to each resource based on the
users_books
table. Finally, in thefetchAll()
method of thebooks
model, callisAllowed()
on each book we find, using the current user as the role.
I see the last option as the best, because then I could use the Acl in other places in my application. That would remove the need to perform duplicate access checks.
What would you suggest?