src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt

changeset 374
34abadbdd0e3
parent 367
0a9065936aac
--- a/src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt	Sun May 18 13:24:55 2025 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt	Wed May 21 14:19:07 2025 +0200
@@ -83,6 +83,13 @@
         }
     }
 
+    private fun forwardIfRequested(req: HttpServletRequest, resp: HttpServletResponse) {
+        val site = req.getAttribute(Constants.REQ_ATTR_JSP)
+        if (site != null) {
+            req.getRequestDispatcher(Constants.JSP_PATH_PREFIX + site + ".jsp").forward(req, resp)
+        }
+    }
+
     private fun invokeMapping(
         mapping: Pair<PathPattern, MappingMethod>,
         req: HttpServletRequest,
@@ -92,9 +99,10 @@
         val params = mapping.first.obtainPathParameters(sanitizedRequestPath(req))
         val method = mapping.second
         val authenticatedUser = req.remoteUser?.let(dao::findUserByName)
-        showWhatsNewPopup(authenticatedUser, req, dao)
         logger.trace("invoke {0}", method)
         method(HttpRequest(authenticatedUser, req, resp, params), dao)
+        showWhatsNewPopup(authenticatedUser, req, resp, dao)
+        forwardIfRequested(req, resp)
     }
 
     private fun sanitizedRequestPath(req: HttpServletRequest) = req.pathInfo ?: "/"
@@ -213,8 +221,17 @@
         }
     }
 
-    private fun showWhatsNewPopup(user: User?, req: HttpServletRequest, dao: DataAccessObject) {
+    private fun showWhatsNewPopup(user: User?, req: HttpServletRequest, resp: HttpServletResponse, dao: DataAccessObject) {
+        // don't show to anonymous users
         if (user == null) return
+
+        // don't show if we aren't going to forward to the site JSP
+        if (req.getAttribute(Constants.REQ_ATTR_JSP) != "site") return
+
+        // don't show for different sources
+        if (listOf("rss").contains(req.getParameter("source").orEmpty())) return
+
+        // show the popup and remember that we've shown it
         logger.trace("show user with ID {0} what's new", user.id)
         val userKnowsUpdatesUntil = dao.untilWhenUserKnowsUpdates(user)
         if (userKnowsUpdatesUntil == null || userKnowsUpdatesUntil.before(SqlDate.valueOf(Constants.VERSION_DATE))) {

mercurial