40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package projects
|
|
|
|
import (
|
|
db "ttime/internal/database"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/log"
|
|
"github.com/golang-jwt/jwt/v5"
|
|
)
|
|
|
|
func RemoveUserFromProject(c *fiber.Ctx) error {
|
|
user := c.Locals("user").(*jwt.Token)
|
|
claims := user.Claims.(jwt.MapClaims)
|
|
pm_name := claims["name"].(string)
|
|
|
|
project := c.Params("projectName")
|
|
username := c.Query("userName")
|
|
|
|
// Check if the user is a project manager
|
|
isPM, err := db.GetDb(c).IsProjectManager(pm_name, project)
|
|
if err != nil {
|
|
log.Info("Error checking if user is project manager:", err)
|
|
return c.Status(500).SendString(err.Error())
|
|
}
|
|
|
|
if !isPM {
|
|
log.Info("User: ", pm_name, " is not a project manager in project: ", project)
|
|
return c.Status(403).SendString("User is not a project manager")
|
|
}
|
|
|
|
// Remove the user from the project
|
|
if err = db.GetDb(c).RemoveUserFromProject(username, project); err != nil {
|
|
log.Info("Error removing user from project:", err)
|
|
return c.Status(500).SendString(err.Error())
|
|
}
|
|
|
|
// Return success message
|
|
log.Info("User : ", username, " removed from project: ", project)
|
|
return c.SendStatus(fiber.StatusOK)
|
|
}
|