Co-authored-by: al8763be <al8763be@users.noreply.github.com>
This commit is contained in:
parent
e1b410c850
commit
d4cc556366
8 changed files with 155 additions and 4 deletions
|
@ -29,6 +29,7 @@ type GlobalState interface {
|
|||
ChangeUserName(c *fiber.Ctx) error // WIP
|
||||
GetAllUsersProject(c *fiber.Ctx) error // WIP
|
||||
UpdateWeeklyReport(c *fiber.Ctx) error
|
||||
RemoveProject(c *fiber.Ctx) error
|
||||
}
|
||||
|
||||
// "Constructor"
|
||||
|
|
|
@ -286,4 +286,30 @@ func (gs *GState) GetProjectTimesHandler(c *fiber.Ctx) error {
|
|||
// Return project times as JSON
|
||||
log.Info("Returning project times for project:", projectName)
|
||||
return c.JSON(projectTimes)
|
||||
}
|
||||
|
||||
func (gs *GState) RemoveProject(c *fiber.Ctx) error {
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Check if the user is a site admin
|
||||
isAdmin, err := gs.Db.IsSiteAdmin(username)
|
||||
if err != nil {
|
||||
log.Info("Error checking admin status:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
if !isAdmin {
|
||||
log.Info("User is not a site admin:", username)
|
||||
return c.Status(403).SendString("User is not a site admin")
|
||||
}
|
||||
|
||||
projectName := c.Params("projectName")
|
||||
|
||||
if err := gs.Db.RemoveProject(projectName); err != nil {
|
||||
return c.Status(500).SendString((err.Error()))
|
||||
}
|
||||
|
||||
return c.Status(200).SendString("Project deleted")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue