~jan0sch/smederee

Showing details for patch 4ee922c097b6893e93b6650503223d8c7d53ccd6.
2024-02-15 (Thu), 8:03 PM - Jens Grassel - 4ee922c097b6893e93b6650503223d8c7d53ccd6

VCS: Better error message if user or organisation cannot be displayed.

Display a dedicated error page if a user or organisation can either not be
found or is private and the user has no permissions to view their repositories.

Until now the regular user page but without repositories was displayed while
using a 404 response code.
Summary of changes
1 files added
  • modules/hub/src/main/twirl/de/smederee/hub/views/errors/userOrOrganisationNotFound.scala.html
2 files modified with 5 lines added and 4 lines removed
  • modules/hub/src/main/resources/messages.properties with 2 added and 0 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 3 added and 4 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/messages.properties new-smederee/modules/hub/src/main/resources/messages.properties
--- old-smederee/modules/hub/src/main/resources/messages.properties	2025-01-12 15:45:29.601015102 +0000
+++ new-smederee/modules/hub/src/main/resources/messages.properties	2025-01-12 15:45:29.601015102 +0000
@@ -16,6 +16,8 @@
 errors.forbidden.title=403 - Forbidden
 errors.internal-server-error.title=500 - Internal Server Error
 errors.internal-server-error.message=An error occured while processing the request.
+errors.user-or-organisation.not-found.title=Not found
+errors.user-or-organisation.not-found.message=No user or organisation named "{0}" could be found!
 
 # Forms
 form.account.delete.button.submit=Delete my account!
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-01-12 15:45:29.601015102 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-01-12 15:45:29.601015102 +0000
@@ -335,14 +335,13 @@
                             user
                         )(repos.getOrElse(List.empty), repositoriesOwnerName)
                     )
-                case _ => // TODO: Better error message...
+                case _ =>
                     NotFound(
-                        views.html.showRepositories(lang = language)(
-                            actionBaseUri,
+                        views.html.errors.userOrOrganisationNotFound(lang = language)(
                             csrf,
                             s"Smederee/~$repositoriesOwnerName".some,
                             user
-                        )(repos.getOrElse(List.empty), repositoriesOwnerName)
+                        )(repositoriesOwnerName)
                     )
             }
         } yield resp
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/userOrOrganisationNotFound.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/userOrOrganisationNotFound.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/userOrOrganisationNotFound.scala.html	1970-01-01 00:00:00.000000000 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/errors/userOrOrganisationNotFound.scala.html	2025-01-12 15:45:29.601015102 +0000
@@ -0,0 +1,21 @@
+@import de.smederee.hub.*
+@import de.smederee.hub.views.html.*
+
+@(baseUri: Uri = Uri(path = Uri.Path.Root), lang: LanguageCode = LanguageCode("en"))(csrf: Option[CsrfToken] = None, title: Option[String] = None, user: Option[Account])(repositoriesOwner: Username)
+@main(baseUri, lang)()(csrf, title, user) {
+@defining(lang.toLocale) { implicit locale =>
+  <div class="content">
+    <div class="pure-g">
+      <div class="pure-u-1-1 pure-u-md-1-1">
+        <div class="l-box">
+          <p class="alert alert-error">
+            <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
+            <span class="sr-only">@Messages("errors.user-or-organisation.not-found.title"):</span>
+            @Messages("errors.user-or-organisation.not-found.message", repositoriesOwner.toString)
+          </p>
+        </div>
+      </div>
+    </div>
+  </div>
+}
+}