implement safe deletion
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:
@@ -105,7 +105,7 @@ func DeleteGroupHandler(c *gin.Context) {
|
||||
//remove leading/trailing spaces in groupname
|
||||
g.GroupName = html.EscapeString(strings.TrimSpace(g.GroupName))
|
||||
|
||||
// Confirm user account exists
|
||||
// Confirm group exists
|
||||
testGroup, _ := models.GroupGetByName(g.GroupName)
|
||||
log.Printf("DeleteGroupHandler confirming group '%s' exists\n", g.GroupName)
|
||||
if (models.Group{} == testGroup) {
|
||||
|
@@ -67,7 +67,7 @@ func AddSafeHandler(c *gin.Context) {
|
||||
|
||||
s := models.Safe{SafeId: input.SafeId, SafeName: input.SafeName}
|
||||
|
||||
//remove leading/trailing spaces in groupname
|
||||
//remove leading/trailing spaces in safe name
|
||||
s.SafeName = html.EscapeString(strings.TrimSpace(s.SafeName))
|
||||
|
||||
// Check if safe already exists
|
||||
@@ -94,3 +94,44 @@ func AddSafeHandler(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "safe creation success"})
|
||||
}
|
||||
|
||||
func DeleteSafeHandler(c *gin.Context) {
|
||||
var input SafeInput
|
||||
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// Input validation
|
||||
if input.SafeId == 0 && len(input.SafeName) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "no safe name or id specified"})
|
||||
return
|
||||
}
|
||||
|
||||
s := models.Safe{SafeId: input.SafeId, SafeName: input.SafeName}
|
||||
|
||||
//remove leading/trailing spaces in safe name
|
||||
s.SafeName = html.EscapeString(strings.TrimSpace(s.SafeName))
|
||||
|
||||
// Confirm safe exists
|
||||
testSafe, _ := models.SafeGetByName(s.SafeName)
|
||||
log.Printf("DeleteSafeHandler confirming group '%s' exists\n", s.SafeName)
|
||||
if (models.Safe{} == testSafe) {
|
||||
errString := fmt.Sprintf("attempt to delete non-existing safe '%s'", s.SafeName)
|
||||
log.Printf("DeleteSafeHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
} else {
|
||||
err := s.SafeDelete()
|
||||
|
||||
if err != nil {
|
||||
errString := fmt.Sprintf("error deleting safe : '%s'", err)
|
||||
log.Printf("DeleteSafeHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "safe deletion success"})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user