Refactor validator stuff and fix variable names in views
This commit is contained in:
@@ -64,10 +64,6 @@ class ComponentController extends AbstractApiController
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if (!$component->isValid()) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if (Binput::has('tags')) {
|
||||
// The component was added successfully, so now let's deal with the tags.
|
||||
$tags = preg_split('/ ?, ?/', Binput::get('tags'));
|
||||
@@ -94,9 +90,9 @@ class ComponentController extends AbstractApiController
|
||||
*/
|
||||
public function putComponent(Component $component)
|
||||
{
|
||||
$component->update(Binput::except('tags'));
|
||||
|
||||
if (!$component->isValid('updating')) {
|
||||
try {
|
||||
$component->update(Binput::except('tags'));
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
@@ -105,9 +101,7 @@ class ComponentController extends AbstractApiController
|
||||
|
||||
// For every tag, do we need to create it?
|
||||
$componentTags = array_map(function ($taggable) use ($component) {
|
||||
return Tag::firstOrCreate([
|
||||
'name' => $taggable,
|
||||
])->id;
|
||||
return Tag::firstOrCreate(['name' => $taggable])->id;
|
||||
}, $tags);
|
||||
|
||||
$component->tags()->sync($componentTags);
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Events\IncidentHasReportedEvent;
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use CachetHQ\Cachet\Models\Incident;
|
||||
use Exception;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
@@ -34,8 +33,7 @@ class IncidentController extends AbstractApiController
|
||||
{
|
||||
$incidentVisiblity = $auth->check() ? 0 : 1;
|
||||
|
||||
$incidents = Incident::where('visible', '>=', $incidentVisiblity)
|
||||
->paginate(Binput::get('per_page', 20));
|
||||
$incidents = Incident::where('visible', '>=', $incidentVisiblity)->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($incidents, $request);
|
||||
}
|
||||
@@ -73,20 +71,11 @@ class IncidentController extends AbstractApiController
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
$isEnabled = (bool) Setting::get('enable_subscribers', false);
|
||||
$mailAddress = env('MAIL_ADDRESS', false);
|
||||
$mailFrom = env('MAIL_NAME', false);
|
||||
$subscribersEnabled = $isEnabled && $mailAddress && $mailFrom;
|
||||
|
||||
if (array_get($incidentData, 'notify') && $subscribersEnabled) {
|
||||
if (array_get($incidentData, 'notify') && subscribers_enabled()) {
|
||||
event(new IncidentHasReportedEvent($incident));
|
||||
}
|
||||
|
||||
if ($incident->isValid()) {
|
||||
return $this->item($incident);
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
return $this->item($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,13 +87,13 @@ class IncidentController extends AbstractApiController
|
||||
*/
|
||||
public function putIncident(Incident $incident)
|
||||
{
|
||||
$incident->update(Binput::all());
|
||||
|
||||
if ($incident->isValid('updating')) {
|
||||
return $this->item($incident);
|
||||
try {
|
||||
$incident->update(Binput::all());
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
return $this->item($incident);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,11 +70,7 @@ class MetricController extends AbstractApiController
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if ($metric->isValid()) {
|
||||
return $this->item($metric);
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
return $this->item($metric);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,13 +82,13 @@ class MetricController extends AbstractApiController
|
||||
*/
|
||||
public function putMetric(Metric $metric)
|
||||
{
|
||||
$metric->update(Binput::all());
|
||||
|
||||
if ($metric->isValid('updating')) {
|
||||
return $this->item($metric);
|
||||
try {
|
||||
$metric->update(Binput::all());
|
||||
} catch (Exception $e) {
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
return $this->item($metric);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,16 +49,12 @@ class SubscriberController extends AbstractApiController
|
||||
throw new BadRequestHttpException();
|
||||
}
|
||||
|
||||
if ($subscriber->isValid()) {
|
||||
// If we're auto-verifying the subscriber, don't bother with this event.
|
||||
if (!(Binput::get('verify'))) {
|
||||
event(new CustomerHasSubscribedEvent($subscriber));
|
||||
}
|
||||
|
||||
return $this->item($subscriber);
|
||||
// If we're auto-verifying the subscriber, don't bother with this event.
|
||||
if (!(Binput::get('verify'))) {
|
||||
event(new CustomerHasSubscribedEvent($subscriber));
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException();
|
||||
return $this->item($subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user