classes not hiding unpublished courses

Even though when a course is not published but attached to a class they still appear and thus when one clicks the link receives Access Denied. I understand the class view is hard coded. Any tips where changes would be needed to set an additional flag to hide unpublished courses?