From 45761dadcb0df76979885c3f99c37b56edd93911 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 20 Mar 2024 17:50:51 +0100 Subject: [PATCH] Fix for checkProjectManager endpoint and test_check_if_project_manager --- backend/internal/handlers/handlers_project_related.go | 6 +++++- backend/main.go | 2 +- testing.py | 3 +-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/internal/handlers/handlers_project_related.go b/backend/internal/handlers/handlers_project_related.go index 7b95c26..99696e7 100644 --- a/backend/internal/handlers/handlers_project_related.go +++ b/backend/internal/handlers/handlers_project_related.go @@ -212,8 +212,12 @@ func (gs *GState) AddUserToProjectHandler(c *fiber.Ctx) error { // IsProjectManagerHandler is a handler that checks if a user is a project manager for a given project func (gs *GState) IsProjectManagerHandler(c *fiber.Ctx) error { + // Get the username from the token + user := c.Locals("user").(*jwt.Token) + claims := user.Claims.(jwt.MapClaims) + username := claims["name"].(string) + // Extract necessary parameters from the request query string - username := c.Query("username") projectName := c.Query("projectName") // Check if the user is a project manager for the specified project diff --git a/backend/main.go b/backend/main.go index dc4bf0a..ff6b94e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -98,7 +98,7 @@ func main() { server.Post("/api/promoteToAdmin", gs.PromoteToAdmin) server.Get("/api/users/all", gs.ListAllUsers) server.Get("/api/getWeeklyReportsUser/:projectName", gs.GetWeeklyReportsUserHandler) - server.Get("api/checkIfProjectManager", gs.IsProjectManagerHandler) + server.Get("/api/checkIfProjectManager/:projectName", gs.IsProjectManagerHandler) server.Post("/api/ProjectRoleChange", gs.ProjectRoleChange) server.Get("/api/getUsersProject/:projectName", gs.ListAllUsersProject) diff --git a/testing.py b/testing.py index 9181d39..568cb87 100644 --- a/testing.py +++ b/testing.py @@ -329,9 +329,8 @@ def test_check_if_project_manager(): # Check if the user is a project manager for the project response = requests.get( - checkIfProjectManagerPath, + checkIfProjectManagerPath + "/" + projectName, headers={"Authorization": "Bearer " + token}, - params={"username": username, "projectName": projectName}, ) dprint(response.text)