Wed, 21 May 2025 14:19:07 +0200
fix "what's new" not shown after redirects + do not show it when accessed via RSS
--- 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))) {
--- a/src/main/kotlin/de/uapcore/lightpit/Constants.kt Sun May 18 13:24:55 2025 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/Constants.kt Wed May 21 14:19:07 2025 +0200 @@ -26,6 +26,9 @@ package de.uapcore.lightpit object Constants { + /** + * A data in yyyy-mm-dd format to identify the release. + */ const val VERSION_DATE = "2025-05-18" /** @@ -54,6 +57,11 @@ const val CTX_ATTR_DB_DIALECT = "db-dialect" /** + * The name of the main JSP file the request has been forwarded to. + */ + const val REQ_ATTR_JSP = "jspFile" + + /** * Key for the request attribute containing the optional navigation menu. */ const val REQ_ATTR_NAVIGATION = "navMenu"
--- a/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt Sun May 18 13:24:55 2025 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt Wed May 21 14:19:07 2025 +0200 @@ -68,7 +68,8 @@ var contentPage = "" set(value) { field = value - request.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, jspPath(value)) + request.setAttribute(Constants.REQ_ATTR_CONTENT_PAGE, + Constants.JSP_PATH_PREFIX + value + ".jsp") } /** @@ -91,7 +92,7 @@ set(value) { field = value request.setAttribute(Constants.REQ_ATTR_STYLESHEET, - value.map { it.withExt(".css") } + value.map { "$it.css" } ) } @@ -104,7 +105,7 @@ set(value) { field = value request.setAttribute(Constants.REQ_ATTR_JAVASCRIPT, - value.withExt(".js") + "$value.js" ) } @@ -157,9 +158,6 @@ request.setAttribute(Constants.REQ_ATTR_BASE_HREF, baseHref) } - private fun String.withExt(ext: String) = if (endsWith(ext)) this else plus(ext) - private fun jspPath(name: String) = Constants.JSP_PATH_PREFIX.plus(name).withExt(".jsp") - fun paramIndexed(prefix: String): Map<Int, String> = buildMap { for (name in request.parameterNames) { if (name.startsWith(prefix)) { @@ -203,7 +201,7 @@ } private fun forward(jsp: String) { - request.getRequestDispatcher(jspPath(jsp)).forward(request, response) + request.setAttribute(Constants.REQ_ATTR_JSP, jsp) } fun renderFeed(page: String? = null) {
--- a/src/main/webapp/WEB-INF/jsp/issues-feed.jsp Sun May 18 13:24:55 2025 +0200 +++ b/src/main/webapp/WEB-INF/jsp/issues-feed.jsp Wed May 21 14:19:07 2025 +0200 @@ -34,8 +34,8 @@ </c:if> <c:if test="${empty viewmodel.project}"> <title><fmt:message key="feed.issues.title"/></title> - <link>${baseHref}issues/</link> <c:set var="issueHref" value="${baseHref}issues/"/> + <link>${issueHref}</link> </c:if> <description><fmt:message key="feed.issues.description"/></description> <language>${pageContext.response.locale.language}</language> @@ -77,7 +77,7 @@ <category><fmt:message key="feed.issues.type.${entry.type}"/></category> </c:when> </c:choose> - <link>${link}</link> + <link>${link}?source=rss</link> <guid isPermaLink="true">${link}</guid> <pubDate><fmt:formatDate value="${entry.time}" pattern="EEE, dd MMM yyyy HH:mm:ss zzz"/></pubDate> <c:if test="${not empty entry.author}">