bugfix permission delete when only permissionId specified
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:
@@ -146,33 +146,47 @@ func DeletePermissionHandler(c *gin.Context) {
|
||||
p.Description = html.EscapeString(strings.TrimSpace(p.Description))
|
||||
|
||||
// Check if permission definition already exists
|
||||
testPermission, _ := models.PermissionGetByDesc(p.Description)
|
||||
log.Printf("DeletePermissionHandler confirming permission with description '%s' exists\n", p.Description)
|
||||
if (models.Permission{} == testPermission) {
|
||||
errString := fmt.Sprintf("attempt to delete non-existing permission with description '%s'", p.Description)
|
||||
log.Printf("DeletePermissionHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
} else {
|
||||
err := p.PermissionDelete()
|
||||
if len(p.Description) > 0 {
|
||||
log.Printf("DeletePermissionHandler confirming permission with description '%s' exists\n", p.Description)
|
||||
testPermission, _ := models.PermissionGetByDesc(p.Description)
|
||||
|
||||
// Create audit record
|
||||
a := models.Audit{
|
||||
UserId: RequestingUserId,
|
||||
IpAddress: c.ClientIP(),
|
||||
EventText: fmt.Sprintf("Deleted Permission '%s' with id %d", p.Description, p.PermissionId),
|
||||
}
|
||||
a.AuditLogAdd()
|
||||
|
||||
if err != nil {
|
||||
errString := fmt.Sprintf("error deleting permission : '%s'", err)
|
||||
if (models.Permission{} == testPermission) {
|
||||
errString := fmt.Sprintf("attempt to delete non-existing permission with description '%s'", p.Description)
|
||||
log.Printf("DeletePermissionHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
log.Printf("DeletePermissionHandler confirming permission with id '%d' exists\n", p.PermissionId)
|
||||
testPermission, _ := models.PermissionGetById(p.PermissionId)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "permission deletion success"})
|
||||
if (models.Permission{} == testPermission) {
|
||||
errString := fmt.Sprintf("attempt to delete non-existing permission with id '%d'", p.PermissionId)
|
||||
log.Printf("DeletePermissionHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err := p.PermissionDelete()
|
||||
|
||||
// Create audit record
|
||||
a := models.Audit{
|
||||
UserId: RequestingUserId,
|
||||
IpAddress: c.ClientIP(),
|
||||
EventText: fmt.Sprintf("Deleted Permission '%s' with id %d", p.Description, p.PermissionId),
|
||||
}
|
||||
a.AuditLogAdd()
|
||||
|
||||
if err != nil {
|
||||
errString := fmt.Sprintf("error deleting permission : '%s'", err)
|
||||
log.Printf("DeletePermissionHandler %s\n", errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "permission deletion success"})
|
||||
|
||||
}
|
||||
|
||||
func UpdatePermissionHandler(c *gin.Context) {
|
||||
|
Reference in New Issue
Block a user