Prevent licenses, models and assets from being deleted if they are assigned to something else

This commit is contained in:
snipe
2013-11-20 06:48:25 -05:00
parent d46556a83d
commit f3114dec7a
7 changed files with 43 additions and 14 deletions
+12 -4
View File
@@ -202,11 +202,19 @@ class AssetsController extends AdminController {
return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found'));
}
// Delete the asset
$asset->delete();
if (isset($asset->assigneduser->id) && ($asset->assigneduser->id!=0)) {
// Redirect to the asset management page
return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.assoc_users'));
} else {
// Delete the asset
$asset->delete();
// Redirect to the asset management page
return Redirect::to('admin')->with('success', Lang::get('admin/assets/message.delete.success'));
}
// Redirect to the asset management page
return Redirect::to('admin')->with('success', Lang::get('admin/assets/message.delete.success'));
}
/**
+11 -4
View File
@@ -187,11 +187,18 @@ class LicensesController extends AdminController {
return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found'));
}
// Delete the license
$license->delete();
if (isset($license->assigneduser->id) && ($license->assigneduser->id!=0)) {
// Redirect to the asset management page
return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.assoc_users'));
} else {
// Delete the license
$license->delete();
// Redirect to the licenses management page
return Redirect::to('admin/licenses')->with('success', Lang::get('admin/licenses/message.delete.success'));
}
// Redirect to the licenses management page
return Redirect::to('admin/licenses')->with('success', Lang::get('admin/licenses/message.delete.success'));
}
+13 -4
View File
@@ -168,11 +168,20 @@ class ModelsController extends AdminController {
return Redirect::to('assets/models')->with('error', Lang::get('admin/models/message.not_found'));
}
// Delete the model
$model->delete();
if ($model->assets->count() > 0) {
// Throw an error that this model is associated with assets
return Redirect::to('assets/models')->with('error', Lang::get('admin/models/message.assoc_users'));
} else {
// Delete the model
$model->delete();
// Redirect to the models management page
return Redirect::to('assets/models')->with('success', Lang::get('admin/models/message.delete.success'));
}
// Redirect to the models management page
return Redirect::to('assets/models')->with('success', Lang::get('admin/models/message.delete.success'));
}
+1
View File
@@ -3,6 +3,7 @@
return array(
'does_not_exist' => 'Asset does not exist.',
'assoc_users' => 'This asset is currently checked out to a user and cannot be deleted. Please check the asset in first, and then try deleting again. ',
'create' => array(
'error' => 'Asset was not created, please try again. :(',
+2
View File
@@ -4,6 +4,8 @@ return array(
'does_not_exist' => 'License does not exist.',
'user_does_not_exist' => 'User does not exist.',
'assoc_users' => 'This license is currently checked out to a user and cannot be deleted. Please check the license in first, and then try deleting again. ',
'create' => array(
'error' => 'License was not created, please try again.',
+2
View File
@@ -3,6 +3,8 @@
return array(
'does_not_exist' => 'Model does not exist.',
'assoc_users' => 'This model is currently associated with one or more assets and cannot be deleted. Please delete the assets, and then try deleting again. ',
'create' => array(
'error' => 'Model was not created, please try again.',
+2 -2
View File
@@ -30,7 +30,7 @@ class License extends Elegant {
}
/**
* Get action logs for this asset
* Get asset logs for this asset
*/
public function assetlog()
{
@@ -38,7 +38,7 @@ class License extends Elegant {
}
/**
* Get action logs for this asset
* Get admin user for this asset
*/
public function adminuser()
{