more checking when creating ldap group
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -59,29 +59,45 @@ func AddGroupHandler(c *gin.Context) {
|
||||
//remove leading/trailing spaces in groupname
|
||||
g.GroupName = html.EscapeString(strings.TrimSpace(g.GroupName))
|
||||
|
||||
// Check if role already exists
|
||||
// Check if group already exists
|
||||
testGroup, _ := models.GroupGetByName(g.GroupName)
|
||||
log.Printf("AddGroup checking if group '%s' already exists\n", g.GroupName)
|
||||
log.Printf("AddGroupHandler checking if group '%s' already exists\n", g.GroupName)
|
||||
|
||||
if (models.Group{} == testGroup) {
|
||||
log.Printf("AddGroup confirmed no existing group name\n")
|
||||
log.Printf("AddGroupHandler confirmed no existing group name\n")
|
||||
} else {
|
||||
errorString := fmt.Sprintf("attempt to register conflicting groupname '%s'", g.GroupName)
|
||||
log.Printf("Register error : '%s'\n", errorString)
|
||||
log.Printf("AddGroupHandler error : '%s'\n", errorString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errorString})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := g.GroupAdd()
|
||||
// Check if there is already an LDAP group with the same Dn
|
||||
if g.LdapGroup {
|
||||
// TODO check for existing LDAP group
|
||||
testLdapGroup, _ := models.GroupGetByLdapDn(g.LdapDn)
|
||||
|
||||
if (models.Group{} == testLdapGroup) {
|
||||
log.Printf("AddGroupHandler confirmed no existing group for same LDAP DN\n")
|
||||
} else {
|
||||
errorString := fmt.Sprintf("attempt to register group with same ldap DN as existing group '%s'", g.GroupName)
|
||||
log.Printf("AddGroupHandler error : '%s'\n", errorString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errorString})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Verification checks passed, return group
|
||||
group, err := g.GroupAdd()
|
||||
|
||||
if err != nil {
|
||||
errString := fmt.Sprintf("error creating group : '%s'", err)
|
||||
log.Printf("AddGroup %s\n", errString)
|
||||
log.Printf("AddGroupHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "group creation success", "data": g})
|
||||
c.JSON(http.StatusOK, gin.H{"message": "group creation success", "data": group})
|
||||
}
|
||||
|
||||
func DeleteGroupHandler(c *gin.Context) {
|
||||
|
Reference in New Issue
Block a user