Added handler and corresponding test for the IsProjectManager function
This commit is contained in:
parent
5778d6e892
commit
ce4cf788ae
4 changed files with 39 additions and 0 deletions
|
@ -21,6 +21,7 @@ type GlobalState interface {
|
||||||
AddUserToProjectHandler(c *fiber.Ctx) error
|
AddUserToProjectHandler(c *fiber.Ctx) error
|
||||||
PromoteToAdmin(c *fiber.Ctx) error
|
PromoteToAdmin(c *fiber.Ctx) error
|
||||||
GetWeeklyReportsUserHandler(c *fiber.Ctx) error
|
GetWeeklyReportsUserHandler(c *fiber.Ctx) error
|
||||||
|
IsProjectManagerHandler(c *fiber.Ctx) error
|
||||||
// GetProject(c *fiber.Ctx) error // To get a specific project
|
// GetProject(c *fiber.Ctx) error // To get a specific project
|
||||||
// UpdateProject(c *fiber.Ctx) error // To update a project
|
// UpdateProject(c *fiber.Ctx) error // To update a project
|
||||||
// DeleteProject(c *fiber.Ctx) error // To delete a project
|
// DeleteProject(c *fiber.Ctx) error // To delete a project
|
||||||
|
|
|
@ -154,3 +154,20 @@ func (gs *GState) AddUserToProjectHandler(c *fiber.Ctx) error {
|
||||||
log.Info("User added to project successfully:", requestData.Username)
|
log.Info("User added to project successfully:", requestData.Username)
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// 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
|
||||||
|
isManager, err := gs.Db.IsProjectManager(username, projectName)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Error checking project manager status:", err)
|
||||||
|
return c.Status(500).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the result as JSON
|
||||||
|
return c.JSON(map[string]bool{"isProjectManager": isManager})
|
||||||
|
}
|
||||||
|
|
|
@ -95,6 +95,7 @@ func main() {
|
||||||
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
||||||
server.Get("/api/users/all", gs.ListAllUsers)
|
server.Get("/api/users/all", gs.ListAllUsers)
|
||||||
server.Get("/api/getWeeklyReportsUser", gs.GetWeeklyReportsUserHandler)
|
server.Get("/api/getWeeklyReportsUser", gs.GetWeeklyReportsUserHandler)
|
||||||
|
server.Get("api/checkIfProjectManager", gs.IsProjectManagerHandler)
|
||||||
|
|
||||||
// Announce the port we are listening on and start the server
|
// Announce the port we are listening on and start the server
|
||||||
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
||||||
|
|
20
testing.py
20
testing.py
|
@ -38,6 +38,7 @@ addUserToProjectPath = base_url + "/api/addUserToProject"
|
||||||
promoteToAdminPath = base_url + "/api/promoteToAdmin"
|
promoteToAdminPath = base_url + "/api/promoteToAdmin"
|
||||||
getUserProjectsPath = base_url + "/api/getUserProjects"
|
getUserProjectsPath = base_url + "/api/getUserProjects"
|
||||||
getWeeklyReportsUserPath = base_url + "/api/getWeeklyReportsUser"
|
getWeeklyReportsUserPath = base_url + "/api/getWeeklyReportsUser"
|
||||||
|
checkIfProjectManagerPath = base_url + "/api/checkIfProjectManager"
|
||||||
|
|
||||||
|
|
||||||
def test_get_user_projects():
|
def test_get_user_projects():
|
||||||
|
@ -292,6 +293,24 @@ def test_get_weekly_reports_user():
|
||||||
assert response.status_code == 200, "Get weekly reports for user failed"
|
assert response.status_code == 200, "Get weekly reports for user failed"
|
||||||
gprint("test_get_weekly_reports_user successful")
|
gprint("test_get_weekly_reports_user successful")
|
||||||
|
|
||||||
|
# Test function to check if a user is a project manager
|
||||||
|
def test_check_if_project_manager():
|
||||||
|
# Log in as the user
|
||||||
|
token = login(username, "always_same").json()["token"]
|
||||||
|
|
||||||
|
# Check if the user is a project manager for the project
|
||||||
|
response = requests.get(
|
||||||
|
checkIfProjectManagerPath,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
params={"username": username, "projectName": projectName},
|
||||||
|
)
|
||||||
|
|
||||||
|
dprint(response.text)
|
||||||
|
assert response.status_code == 200, "Check if project manager failed"
|
||||||
|
gprint("test_check_if_project_manager successful")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_get_user_projects()
|
test_get_user_projects()
|
||||||
|
@ -304,3 +323,4 @@ if __name__ == "__main__":
|
||||||
test_sign_report()
|
test_sign_report()
|
||||||
test_add_user_to_project()
|
test_add_user_to_project()
|
||||||
test_get_weekly_reports_user()
|
test_get_weekly_reports_user()
|
||||||
|
test_check_if_project_manager()
|
||||||
|
|
Loading…
Reference in a new issue