mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
API: Check there are no assets associated before allowing delete
This commit is contained in:
parent
d1de34394e
commit
707c4db881
|
@ -137,8 +137,14 @@ class StatuslabelsController extends Controller
|
||||||
$this->authorize('delete', Statuslabel::class);
|
$this->authorize('delete', Statuslabel::class);
|
||||||
$statuslabel = Statuslabel::findOrFail($id);
|
$statuslabel = Statuslabel::findOrFail($id);
|
||||||
$this->authorize('delete', $statuslabel);
|
$this->authorize('delete', $statuslabel);
|
||||||
$statuslabel->delete();
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/statuslabels/message.delete.success')));
|
// Check that there are no assets associated
|
||||||
|
if ($statuslabel->assets()->count() == 0) {
|
||||||
|
$statuslabel->delete();
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/statuslabels/message.delete.success')));
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/statuslabels/message.assoc_assets')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue