Index: src/main/java/net/jforum/view/forum/common/TopicsCommon.java =================================================================== --- src/main/java/net/jforum/view/forum/common/TopicsCommon.java (revision 194) +++ src/main/java/net/jforum/view/forum/common/TopicsCommon.java (working copy) @@ -272,6 +272,10 @@ TopicDAO dao = DataAccessDriver.getInstance().newTopicDAO(); List usersToNotify = dao.notifyUsers(topic); + // filter users - don't send notifications if they are subscribed to a topic that has + // been moved to a restricted category / forum. + removeUsersWithNoAccessToTopic(topic, usersToNotify); + // We only have to send an email if there are users // subscribed to the topic if (usersToNotify != null && !usersToNotify.isEmpty()) { @@ -281,6 +285,39 @@ } /** + * If the user cannot access the topic (forum or category limits), then remove the user + * from the notification list. + * + * @param topic + * @param usersToNotify + */ + private static void removeUsersWithNoAccessToTopic(Topic topic, + List usersToNotify) { + + // If we got so far, this can't possibly be null. And if by chance it is, no need to notify, might as + // well just crash. + Forum forum = ForumRepository.getForum(topic.getForumId()); + + Iterator userIterator = usersToNotify.iterator(); + + while(userIterator.hasNext()) { + User user = userIterator.next(); + + // do same check as isTopicAccessible method above. if user doesn't have access to the category + // remove it from the list so that there are no categories sent. + if (!ForumRepository.isCategoryAccessible(user.getId(), forum.getCategoryId())) { + userIterator.remove(); + } + + // apparently, for forums you can disable access to some groups. Hopefully this method checks + // not tested. + if (!ForumRepository.isForumAccessible(user.getId(), forum.getCategoryId(), forum.getId())) { + userIterator.remove(); + } + } + } + + /** * Updates the board status after a new post is inserted. * This method is used in conjunct with moderation manipulation. * It will increase by 1 the number of replies of the tpoic, set the