Skip to content

Commit

Permalink
Rewrote deleteUserFromUserGroup handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SystemsPurge committed Oct 15, 2024
1 parent f9a504b commit 3591f46
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion routes/usergroup/usergroup_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,34 @@ func deleteUserFromUserGroup(c *gin.Context) {
return
}

c.JSON(http.StatusOK, gin.H{"user": u})
for _, sm := range ug.ScenarioMappings {
var sc database.Scenario
err = db.Find(&sc, "ID = ?", sm.ScenarioID).Error
if sm.Duplicate {
//scenario not found, only referenced by id in group
if helper.DBError(c, err) {
continue
}

duplicateName := fmt.Sprintf("%s %s", sc.Name, username)
err = db.Find(&sc, "Name = ?", duplicateName).Error
//duplicate not found, likely does not exist, continue
if helper.DBError(c, err) {
continue
}

err = db.Delete(&sc).Error
//could not delete duplicate, highly unlikely after previous check
//check anyway
if helper.DBError(c, err) {
continue
}
} else {
err = db.Model(&sc).Association("Users").Delete(&u).Error
if helper.DBError(c, err) { // only if user already not associated, continue
continue
}
}
}
c.JSON(http.StatusOK, gin.H{"usergroup": ug})
}

0 comments on commit 3591f46

Please sign in to comment.