Skip to content

Commit 4a97aca

Browse files
authored
Merge pull request #461 from pixlise/bugfix/allow-delete-fm
Allow deleting FM datasets that have no images/spectra
2 parents eaae175 + 7ad4060 commit 4a97aca

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

api/ws/handlers/scan.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,18 @@ func HandleScanDeleteReq(req *protos.ScanDeleteReq, hctx wsHelpers.HandlerContex
218218
return nil, errorwithstatus.MakeBadRequestError(fmt.Errorf("Specified title did not match scan title of: \"%v\"", dbItem.Title))
219219
}
220220

221-
// Check that it's not an FM dataset
222-
if dbItem.Instrument == protos.ScanInstrument_PIXL_FM {
223-
return nil, errorwithstatus.MakeBadRequestError(errors.New("Cannot delete FM datasets using this feature"))
221+
// Only allow deleting an FM dataset if it doesn't have any spectra or images - as it might be a safety survey or other failed scan
222+
// that we don't want to keep around
223+
imageCount := 0
224+
for _, dt := range dbItem.DataTypes {
225+
if dt.DataType == protos.ScanDataType_SD_IMAGE && dt.Count > 0 {
226+
imageCount = int(dt.Count)
227+
break
228+
}
229+
}
230+
231+
if dbItem.Instrument == protos.ScanInstrument_PIXL_FM && (dbItem.ContentCounts["BulkSpectra"] > 0 || dbItem.ContentCounts["NormalSpectra"] > 0 || imageCount > 0) {
232+
return nil, errorwithstatus.MakeBadRequestError(errors.New("Cannot delete FM datasets containing spectra or images using this feature"))
224233
}
225234

226235
// TODO: Should we stop deletion if images or quants reference it???

0 commit comments

Comments
 (0)