From 526063121974834e60f57394b403f0489d4753e0 Mon Sep 17 00:00:00 2001
From: Danae Natalie Savvidi <d.n.savvidi@student.tudelft.nl>
Date: Wed, 12 Feb 2025 17:33:10 +0100
Subject: [PATCH 1/4] validation for setup path

---
 .../gitbull/controller/SetupController.java   | 26 +++++++++++++++++
 .../resources/templates/setup/edition.html    | 28 +++++++++++++++++--
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/main/java/nl/tudelft/gitbull/controller/SetupController.java b/src/main/java/nl/tudelft/gitbull/controller/SetupController.java
index 91abeba7..8f5174e6 100644
--- a/src/main/java/nl/tudelft/gitbull/controller/SetupController.java
+++ b/src/main/java/nl/tudelft/gitbull/controller/SetupController.java
@@ -27,15 +27,19 @@ import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 import lombok.AllArgsConstructor;
 import nl.tudelft.gitbull.dto.setup.*;
+import nl.tudelft.gitbull.enums.PathType;
 import nl.tudelft.gitbull.exceptions.InvalidSetupSettingsException;
 import nl.tudelft.gitbull.model.setup.SetupMember;
+import nl.tudelft.gitbull.properties.GitLabProperties;
 import nl.tudelft.gitbull.service.CourseService;
 import nl.tudelft.gitbull.service.EditionService;
 import nl.tudelft.gitbull.service.EditionStatusService;
 import nl.tudelft.gitbull.service.SetupService;
+import nl.tudelft.gitbull.service.gitlab.GitlabPathService;
 import nl.tudelft.gitbull.service.labracore.LabracoreEditionService;
 import nl.tudelft.labracore.api.dto.EditionDetailsDTO;
 import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
@@ -46,6 +50,8 @@ import nl.tudelft.labracore.lib.security.user.Person;
 @AllArgsConstructor
 public class SetupController {
 
+	private final GitLabProperties gitLabProperties;
+
 	private final SetupService setupService;
 
 	private final EditionService editionService;
@@ -54,6 +60,8 @@ public class SetupController {
 
 	private final CourseService courseService;
 
+	private final GitlabPathService gitlabPathService;
+
 	private final LabracoreEditionService labracoreEditionService;
 	private final ModelMapper mapper;
 
@@ -209,4 +217,22 @@ public class SetupController {
 		return "setup/progress";
 	}
 
+	@GetMapping("{editionId}/validate-path")
+	@PreAuthorize("@authorizationService.isApiKeySet()")
+	public String validatePath(@PathVariable Long editionId, SetupPathsDTO dto, RedirectAttributes attrs) {
+		String fullPath = dto.getCoursePath() + "/" + dto.getEditionPath();
+		PathType pathType = gitlabPathService.getPathType(fullPath);
+		String fullPathUrl = gitLabProperties.getUrl() + "/" + fullPath;
+
+		String validationMessage = switch (pathType) {
+			case null -> "We could not find the group. Full path: ";
+			case PROJECT -> "We found a project, but we need a group, not a project. Full path: ";
+			case GROUP -> "We have found the group! Full path: ";
+		};
+
+		attrs.addFlashAttribute("validationMessage", validationMessage);
+		attrs.addFlashAttribute("fullPath", fullPathUrl);
+		return "redirect:/setup/{editionId}/edition";
+	}
+
 }
diff --git a/src/main/resources/templates/setup/edition.html b/src/main/resources/templates/setup/edition.html
index 61238043..9fe62d55 100644
--- a/src/main/resources/templates/setup/edition.html
+++ b/src/main/resources/templates/setup/edition.html
@@ -32,7 +32,7 @@
                 class="font-800 mb-5"
                 th:text="|Set up ${edition.course.name} - ${edition.name}: Course Edition|"></h1>
 
-            <form th:action="@{/setup/{editionId}/edition(editionId=${edition.id})}" method="post">
+            <form>
                 <div
                     class="grid col-2 gap-3 align-center mb-5 | sm:col-1"
                     style="--col-1: minmax(0, 8rem); max-width: 25rem">
@@ -83,7 +83,31 @@
                         required />
                 </div>
 
-                <button type="submit" class="button">Next</button>
+                <div
+                    class="flex pb-5"
+                    th:unless="${validationMessage==null}"
+                    id="validation-message">
+                    <span th:text="${validationMessage}"></span>
+                    <a th:href="${fullPath}" th:text="${fullPath}"></a>
+                </div>
+
+                <div>
+                    <button
+                        type="submit"
+                        class="button"
+                        th:formaction="@{/setup/{editionId}/validate-path(editionId=${edition.id})}"
+                        th:formmethod="get">
+                        Validate
+                    </button>
+
+                    <button
+                        type="submit"
+                        class="button"
+                        th:formaction="@{/setup/{editionId}/edition(editionId=${edition.id})}"
+                        th:formmethod="post">
+                        Next
+                    </button>
+                </div>
             </form>
         </div>
     </body>
-- 
GitLab


From 7c0c0cc0d6370fc32bb70d0b2d8af20e13f3d3b2 Mon Sep 17 00:00:00 2001
From: Danae Natalie Savvidi <d.n.savvidi@student.tudelft.nl>
Date: Wed, 12 Feb 2025 17:39:39 +0100
Subject: [PATCH 2/4] disable next button if not valid path

---
 src/main/java/nl/tudelft/gitbull/controller/SetupController.java | 1 +
 src/main/resources/templates/setup/edition.html                  | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/main/java/nl/tudelft/gitbull/controller/SetupController.java b/src/main/java/nl/tudelft/gitbull/controller/SetupController.java
index 8f5174e6..749977da 100644
--- a/src/main/java/nl/tudelft/gitbull/controller/SetupController.java
+++ b/src/main/java/nl/tudelft/gitbull/controller/SetupController.java
@@ -232,6 +232,7 @@ public class SetupController {
 
 		attrs.addFlashAttribute("validationMessage", validationMessage);
 		attrs.addFlashAttribute("fullPath", fullPathUrl);
+		attrs.addFlashAttribute("allow", pathType == PathType.GROUP);
 		return "redirect:/setup/{editionId}/edition";
 	}
 
diff --git a/src/main/resources/templates/setup/edition.html b/src/main/resources/templates/setup/edition.html
index 9fe62d55..360b87aa 100644
--- a/src/main/resources/templates/setup/edition.html
+++ b/src/main/resources/templates/setup/edition.html
@@ -103,6 +103,7 @@
                     <button
                         type="submit"
                         class="button"
+                        th:disabled="${allow ==null || !allow}"
                         th:formaction="@{/setup/{editionId}/edition(editionId=${edition.id})}"
                         th:formmethod="post">
                         Next
-- 
GitLab


From 089144da6105c5a8cdbeccb440532639afd0561f Mon Sep 17 00:00:00 2001
From: Danae Natalie Savvidi <d.n.savvidi@student.tudelft.nl>
Date: Wed, 12 Feb 2025 21:19:35 +0100
Subject: [PATCH 3/4] bug fix with next button

---
 src/main/resources/templates/setup/edition.html | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/main/resources/templates/setup/edition.html b/src/main/resources/templates/setup/edition.html
index 360b87aa..71fc2c45 100644
--- a/src/main/resources/templates/setup/edition.html
+++ b/src/main/resources/templates/setup/edition.html
@@ -32,7 +32,7 @@
                 class="font-800 mb-5"
                 th:text="|Set up ${edition.course.name} - ${edition.name}: Course Edition|"></h1>
 
-            <form>
+            <form th:action="@{/setup/{editionId}/edition(editionId=${edition.id})}" method="post">
                 <div
                     class="grid col-2 gap-3 align-center mb-5 | sm:col-1"
                     style="--col-1: minmax(0, 8rem); max-width: 25rem">
@@ -96,16 +96,11 @@
                         type="submit"
                         class="button"
                         th:formaction="@{/setup/{editionId}/validate-path(editionId=${edition.id})}"
-                        th:formmethod="get">
+                        formmethod="get">
                         Validate
                     </button>
 
-                    <button
-                        type="submit"
-                        class="button"
-                        th:disabled="${allow ==null || !allow}"
-                        th:formaction="@{/setup/{editionId}/edition(editionId=${edition.id})}"
-                        th:formmethod="post">
+                    <button type="submit" class="button" th:disabled="${allow == null || !allow}">
                         Next
                     </button>
                 </div>
-- 
GitLab


From c32ce63661544286a3bd80ca8004117fb3eaa505 Mon Sep 17 00:00:00 2001
From: Danae Natalie Savvidi <d.n.savvidi@student.tudelft.nl>
Date: Wed, 12 Feb 2025 22:01:00 +0100
Subject: [PATCH 4/4] css fixes

---
 .../resources/templates/setup/edition.html    |  4 +-
 .../resources/templates/setup/groups.html     | 56 ++++++++++++++-----
 2 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/src/main/resources/templates/setup/edition.html b/src/main/resources/templates/setup/edition.html
index 71fc2c45..f9c4fb74 100644
--- a/src/main/resources/templates/setup/edition.html
+++ b/src/main/resources/templates/setup/edition.html
@@ -40,7 +40,7 @@
                         <label for="course-path">Course path</label>
                         <div class="tooltip">
                             <span class="fa-solid fa-question tooltip__control"></span>
-                            <p role="tooltip">
+                            <p role="tooltip" style="white-space: initial; min-width: 30rem">
                                 This is the part of the path that already exists. For example, if
                                 your course is located at
                                 <code>https://gitlab.ewi.tudelft.nl/course</code>
@@ -62,7 +62,7 @@
                         <label for="edition-path">Edition path</label>
                         <div class="tooltip">
                             <span class="fa-solid fa-question tooltip__control"></span>
-                            <p role="tooltip">
+                            <p role="tooltip" style="white-space: initial; min-width: 30rem">
                                 This is the part of the path that will be created. For example, if
                                 the groups should be created in
                                 <code>/course/23-24</code>
diff --git a/src/main/resources/templates/setup/groups.html b/src/main/resources/templates/setup/groups.html
index bd7d2a5a..58af3163 100644
--- a/src/main/resources/templates/setup/groups.html
+++ b/src/main/resources/templates/setup/groups.html
@@ -75,7 +75,9 @@
                                 <label for="enable-group-repos">Create group repositories</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Select this if you want a repository to be created for every
                                         group. If you only want to create empty groups, uncheck this
                                         option and check 'Put every group in its own GitLab group'.
@@ -92,7 +94,9 @@
                                 <label for="initial-commit">Create initial commit</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Select this if a repository with an initial commit
                                         containing just an empty readme file should be created. If
                                         this is not selected, the created repository will be empty.
@@ -105,7 +109,9 @@
                                 <label for="fork-url">Fork path</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Fill in only the path to the repository to fork, e.g. if the
                                         fork is at
                                         <code>https://gitlab.ewi.tudelft.nl/fork</code>
@@ -130,7 +136,9 @@
                                 <label for="keep-fork">Keep fork relation</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         If the fork relation is kept, no merge requests can be
                                         created except to the original repository.
                                     </p>
@@ -162,7 +170,9 @@
                                 <label for="enable-clusters">Enable clusters</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Clusters are groups of groups. Enabling clusters creates a
                                         group for every cluster in which the group repositories will
                                         be created.
@@ -184,7 +194,9 @@
                                 </label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         If this is disabled, clusters have to be specified in the
                                         students file.
                                     </p>
@@ -217,7 +229,9 @@
                                 </label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         If this is enabled, a repository for every cluster will be
                                         created. All students in the cluster will have access to
                                         this repository.
@@ -243,7 +257,9 @@
                                 <label for="cluster-initial-commit">Create initial commit</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Select this if a repository with an initial commit
                                         containing just an empty readme file should be created. If
                                         this is not selected, the created repository will be empty.
@@ -256,7 +272,9 @@
                                 <label for="cluster-fork-url">Fork path</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Fill in only the path to the repository to fork, e.g. if the
                                         fork is at
                                         <code>https://gitlab.ewi.tudelft.nl/fork</code>
@@ -283,7 +301,9 @@
                                 <label for="cluster-keep-fork">Keep fork relation</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         If the fork relation is kept, no merge requests can be
                                         created except to the original repository.
                                     </p>
@@ -306,7 +326,9 @@
                                 </label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         If this is enabled, a repository for every student will be
                                         created in a separate group. Students have access to their
                                         own repository.
@@ -324,7 +346,9 @@
                                 <label for="individual-initial-commit">Create initial commit</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Select this if a repository with an initial commit
                                         containing just an empty readme file should be created. If
                                         this is not selected, the created repository will be empty.
@@ -339,7 +363,9 @@
                                 </label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         Fill in only the path to the repository to fork, e.g. if the
                                         fork is at
                                         <code>https://gitlab.ewi.tudelft.nl/fork</code>
@@ -366,7 +392,9 @@
                                 <label for="individual-keep-fork">Keep fork relation</label>
                                 <div class="tooltip">
                                     <span class="fa-solid fa-question tooltip__control"></span>
-                                    <p role="tooltip">
+                                    <p
+                                        role="tooltip"
+                                        style="white-space: initial; min-width: 30rem">
                                         If the fork relation is kept, no merge requests can be
                                         created except to the original repository.
                                     </p>
-- 
GitLab