I am working on a social site where users can block other users. Throughout the site –dozens of places, user information is displayed. For example, user comments, reply forms, online user list.. etc etc.. The problem is that given the high number of places user info is displayed, it’s becoming very difficult to check each time if that user is blocked. For example:
<g:each var="comment" in="${comments}">
<g:if test="!${loggedInUser.blockedUsers.find { it == comment.user}">
show comment
</g:if>
</g:each>
Does Grails provide any functionality that would facilitate creating some kind of filter or intercepter where I could simply exclude blocked users when iterating lists, etc? If not, what would you suggest I do?
A good rule of thumb is to only load what you need, so your service method should filter out blocked users at the database level. Then your controllers will be simpler and views will only have to display what they are given.
But if you prefer interceptors, take a look here:
http://www.grails.org/Controllers+-+Interceptors