From 9b36644a313e976cfd9d6225d354fe87764bc8a3 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 13 Nov 2015 13:02:12 -0700 Subject: [PATCH] Delete guards Fixes #24. --- api/characteristics.go | 4 ++++ api/measurements.go | 5 +++++ api/species.go | 4 ++++ api/strains.go | 4 ++++ 4 files changed, 17 insertions(+) diff --git a/api/characteristics.go b/api/characteristics.go index 11f2d52..7543329 100644 --- a/api/characteristics.go +++ b/api/characteristics.go @@ -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) } diff --git a/api/measurements.go b/api/measurements.go index 4201b70..507ab4f 100644 --- a/api/measurements.go +++ b/api/measurements.go @@ -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) } diff --git a/api/species.go b/api/species.go index 6d1516d..5318e90 100644 --- a/api/species.go +++ b/api/species.go @@ -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) } diff --git a/api/strains.go b/api/strains.go index 4789eaf..693b4c6 100644 --- a/api/strains.go +++ b/api/strains.go @@ -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) }