Very large changes related to database and its interface
This commit is contained in:
parent
a51d984229
commit
ec138163c6
5 changed files with 179 additions and 148 deletions
|
@ -65,8 +65,8 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error {
|
|||
//check token and get username of current user
|
||||
user := c.Locals("user").(*jwt.Token)
|
||||
claims := user.Claims.(jwt.MapClaims)
|
||||
projectManagerUsername := claims["name"].(string)
|
||||
log.Info(projectManagerUsername)
|
||||
username := claims["name"].(string)
|
||||
|
||||
// Extract the necessary parameters from the request
|
||||
data := new(types.RoleChange)
|
||||
if err := c.BodyParser(data); err != nil {
|
||||
|
@ -74,18 +74,19 @@ func (gs *GState) ProjectRoleChange(c *fiber.Ctx) error {
|
|||
return c.Status(400).SendString(err.Error())
|
||||
}
|
||||
|
||||
// dubble diping and checcking if current user is
|
||||
log.Info("Changing role for user: ", username, " in project: ", data.Projectname, " to: ", data.Role)
|
||||
|
||||
if ismanager, err := gs.Db.IsProjectManager(projectManagerUsername, data.Projectname); err != nil {
|
||||
// Dubble diping and checcking if current user is
|
||||
if ismanager, err := gs.Db.IsProjectManager(username, data.Projectname); err != nil {
|
||||
log.Warn("Error checking if projectmanager:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
} else if !ismanager {
|
||||
log.Warn("tried chaning role when not projectmanager:", err)
|
||||
return c.Status(401).SendString("you can not change role when not projectManager")
|
||||
log.Warn("User is not projectmanager")
|
||||
return c.Status(401).SendString("User is not projectmanager")
|
||||
}
|
||||
|
||||
// Change the user's role within the project in the database
|
||||
if err := gs.Db.ChangeUserRole(data.Username, data.Projectname, data.Role); err != nil {
|
||||
if err := gs.Db.ChangeUserRole(username, data.Projectname, data.Role); err != nil {
|
||||
return c.Status(500).SendString(err.Error())
|
||||
}
|
||||
|
||||
|
@ -218,7 +219,9 @@ func (gs *GState) IsProjectManagerHandler(c *fiber.Ctx) error {
|
|||
username := claims["name"].(string)
|
||||
|
||||
// Extract necessary parameters from the request query string
|
||||
projectName := c.Query("projectName")
|
||||
projectName := c.Params("projectName")
|
||||
|
||||
log.Info("Checking if user ", username, " is a project manager for project ", projectName)
|
||||
|
||||
// Check if the user is a project manager for the specified project
|
||||
isManager, err := gs.Db.IsProjectManager(username, projectName)
|
||||
|
@ -228,10 +231,5 @@ func (gs *GState) IsProjectManagerHandler(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
// Return the result as JSON
|
||||
return c.JSON(map[string]bool{"isProjectManager": isManager})
|
||||
}
|
||||
|
||||
func (gs *GState) CreateTask(c *fiber.Ctx) error {
|
||||
|
||||
return nil
|
||||
return c.JSON(fiber.Map{"isProjectManager": isManager})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue