Show only user-specific rows


I made CRUD actions for a model and now there’s a question of showing only specific rows to the user (user’s group == group id in the table). Since the user can be in multiple groups, the user has a function getGroups() and a rule isGroupMember.

One way to do this is to remove the row info in the controller (actionIndex), the other is to make the check and return “” (?) in the index view (in GridView’s rowOptions maybe?).

It all feels a bit messy. Using roles (behaviors() {access…}) I can only give access to ‘full’ actions not only rows in index.

There’s a similar problem with groupAdmin role (who can be in other groups but a regular user there). groupAdmin should be able to create and modify only in the group where they have that role. Therefore groupAdmin role should contain somehow the info where is the user groupAdmin. Right now the table connecting groups and users have the columns user_id, group_id, is_accepted, is_group_admin. So the groupAdmin role is basically redundant but using that gives the opportunity to restrict actions in behaviours… access.

There’s bound to be a simple piece of the puzzle I am missing.

Help is much appreciated!