Delete guards

Fixes #24.
This commit is contained in:
Matthew Dillon 2015-11-13 13:02:12 -07:00
parent 548f65eeb7
commit 9b36644a31
4 changed files with 17 additions and 0 deletions

View file

@ -204,6 +204,10 @@ func (c CharacteristicService) Delete(id int64, genus string, claims *types.Clai
return newJSONError(err, http.StatusInternalServerError)
}
if !characteristic.CanEdit {
return newJSONError(errors.ErrCharacteristicNotDeleted, http.StatusForbidden)
}
if err := models.Delete(characteristic); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}

View file

@ -121,6 +121,11 @@ func (m MeasurementService) Delete(id int64, genus string, claims *types.Claims)
if err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
if !measurement.CanEdit {
return newJSONError(errors.ErrMeasurementNotDeleted, http.StatusForbidden)
}
if err := models.Delete(measurement.MeasurementBase); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}

View file

@ -164,6 +164,10 @@ func (s SpeciesService) Delete(id int64, genus string, claims *types.Claims) *ty
return newJSONError(err, http.StatusInternalServerError)
}
if !species.CanEdit {
return newJSONError(errors.ErrSpeciesNotDeleted, http.StatusForbidden)
}
if err := models.Delete(species.SpeciesBase); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}

View file

@ -227,6 +227,10 @@ func (s StrainService) Delete(id int64, genus string, claims *types.Claims) *typ
return newJSONError(err, http.StatusInternalServerError)
}
if !strain.CanEdit {
return newJSONError(errors.ErrStrainNotDeleted, http.StatusForbidden)
}
if err := models.Delete(strain); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}