Skip to content

A free open source IT asset/license management system

Another fix for status label types

snipe6d5bc64b2b8c
diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php
index aabb5e74f2..88fb6c0398 100755
--- a/app/Http/Controllers/StatuslabelsController.php
+++ b/app/Http/Controllers/StatuslabelsController.php
@@ -12,6 +12,7 @@ use Str;
use View;
use App\Helpers\Helper;
use Auth;
+use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -90,12 +91,17 @@ class StatuslabelsController extends Controller
*
* @return Redirect
*/
- public function postCreate()
+ public function postCreate(Request $request)
{
// create a new model instance
$statuslabel = new Statuslabel();
- $statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
+
+ if (!$request->has('statuslabel_types')) {
+ return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
+ }
+
+ $statustype = Statuslabel::getStatuslabelTypesForDB($request->input('statuslabel_types'));
// Save the Statuslabel data
$statuslabel->name = e(Input::get('name'));
@@ -116,11 +122,14 @@ class StatuslabelsController extends Controller
}
- public function store()
+ public function store(Request $request)
{
- // create a new status label instance
$statuslabel = new Statuslabel();
+ if (!$request->has('statuslabel_types')) {
+ return JsonResponse::create(["error" => trans('validation.statuslabel_type')], 500);
+ }
+
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
$statuslabel->name = e(Input::get('name'));
$statuslabel->user_id = Auth::user()->id;
@@ -135,7 +144,7 @@ class StatuslabelsController extends Controller
// Redirect to the new Statuslabel page
return JsonResponse::create($statuslabel);
}
- return JsonResponse::create(["error" => "Failed validation: ".print_r($statuslabel->getErrors()->first(), true)], 500);
+ return JsonResponse::create(["error" => $statuslabel->getErrors()->first()], 500);
}
@@ -168,7 +177,7 @@ class StatuslabelsController extends Controller
* @param int $statuslabelId
* @return Redirect
*/
- public function postEdit($statuslabelId = null)
+ public function postEdit(Request $request, $statuslabelId = null)
{
// Check if the Statuslabel exists
if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
@@ -176,6 +185,10 @@ class StatuslabelsController extends Controller
return redirect()->to('admin/settings/statuslabels')->with('error', trans('admin/statuslabels/message.does_not_exist'));
}
+ if (!$request->has('statuslabel_types')) {
+ return redirect()->back()->withInput()->withErrors(['statuslabel_types' => trans('validation.statuslabel_type')]);
+ }
+
// Update the Statuslabel data
$statustype = Statuslabel::getStatuslabelTypesForDB(Input::get('statuslabel_types'));
diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php
index a7a01be50f..e06dfc9b5d 100755
--- a/app/Models/Statuslabel.php
+++ b/app/Models/Statuslabel.php
@@ -16,9 +16,11 @@ class Statuslabel extends Model
protected $rules = array(
- 'name' => 'required|string|unique:status_labels,name,NULL,deleted_at',
- //'statuslabel_types' => 'required|in:deployable,pending,archived,undeployable',
- 'notes' => 'string',
+ 'name' => 'required|string|unique:status_labels,name,NULL,deleted_at',
+ 'notes' => 'string',
+ 'deployable' => 'required',
+ 'pending' => 'required',
+ 'archived' => 'required',
);
protected $fillable = ['name'];
@@ -47,14 +49,14 @@ class Statuslabel extends Model
public function getStatuslabelType()
{
- if ($this->pending == 1) {
+ if (($this->pending == '1') && ($this->archived == '0') && ($this->deployable == '0')) {
return 'pending';
- } elseif ($this->archived == 1) {
+ } elseif (($this->pending == '0') && ($this->archived == '1') && ($this->deployable == '0')) {
return 'archived';
- } elseif ($this->deployable == 1) {
- return 'deployable';
- } else {
+ } elseif (($this->pending == '0') && ($this->archived == '0') && ($this->deployable == '0')) {
return 'undeployable';
+ } else {
+ return 'deployable';
}
}
@@ -74,12 +76,13 @@ class Statuslabel extends Model
$statustype['pending'] = 0;
$statustype['deployable'] = 0;
$statustype['archived'] = 1;
-
+
} else {
$statustype['pending'] = 0;
$statustype['deployable'] = 0;
$statustype['archived'] = 0;
- }
+
+ }
return $statustype;
}
diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php
index 5e2deb1131..2d4fda6f7a 100644
--- a/resources/lang/en/validation.php
+++ b/resources/lang/en/validation.php
@@ -64,6 +64,7 @@ return array(
),
"unique" => "The :attribute has already been taken.",
"url" => "The :attribute format is invalid.",
+ "statuslabel_type" => "You must select a valid status label type",
/*