When building your query, you will have to consider which user is accessing. In my app, I store the role of the user along with the user itself at login time, so it’s always accessible (I don’t use the default roles ‘Guest’, ‘Admin’, ‘Authenticate’). The code will depend on the API you use to build your query.
For example:
(...)
$sessionUser = Yii::app()->user;
$where = '';
if( $sessionUser->role == 'Guest' )
$where = 'field = filter1';
else if( $sessionUser->role == 'Whatever' )
$where = 'field = filter2';
// For the sake of security
else if( $sessionUser != 'Admin' )
throw new Exception( 'Access forbidden' );
// Now you apply the where clause
I have several "companies" in my webapp, and I need to filter userA to company1 and company2, userB to company1 and company3 and so on.
I’d like to understand the proper way to do so. In a previous solution I used to filter EACH query, which is as you can imagine pretty time consuming and fail prone.
So if at login time I could filter some tables of my database with only the rows the user can see would be the best. Something like creating temporary tables or temporary views.