*/
public function index()
{
- // TODO - Get and pass webhooks
- return view('settings.webhooks.index');
+ $webhooks = Webhook::query()
+ ->orderBy('name', 'desc')
+ ->with('trackedEvents')
+ ->get();
+
+ $this->setPageTitle(trans('settings.webhooks'));
+
+ return view('settings.webhooks.index', ['webhooks' => $webhooks]);
}
/**
*/
public function create()
{
+ $this->setPageTitle(trans('settings.webhooks_create'));
+
return view('settings.webhooks.create');
}
*/
public function store(Request $request)
{
- // TODO - Create webhook
+ $validated = $this->validate($request, [
+ 'name' => ['required', 'max:150'],
+ 'endpoint' => ['required', 'url', 'max:500'],
+ 'events' => ['required', 'array'],
+ 'active' => ['required'],
+ 'timeout' => ['required', 'integer', 'min:1', 'max:600'],
+ ]);
+
+ $webhook = new Webhook($validated);
+ $webhook->active = $validated['active'] === 'true';
+ $webhook->save();
+ $webhook->updateTrackedEvents(array_values($validated['events']));
+
$this->logActivity(ActivityType::WEBHOOK_CREATE, $webhook);
+
return redirect('/settings/webhooks');
}
public function edit(string $id)
{
/** @var Webhook $webhook */
- $webhook = Webhook::query()->findOrFail($id);
+ $webhook = Webhook::query()
+ ->with('trackedEvents')
+ ->findOrFail($id);
+
+ $this->setPageTitle(trans('settings.webhooks_edit'));
return view('settings.webhooks.edit', ['webhook' => $webhook]);
}
*/
public function update(Request $request, string $id)
{
+ $validated = $this->validate($request, [
+ 'name' => ['required', 'max:150'],
+ 'endpoint' => ['required', 'url', 'max:500'],
+ 'events' => ['required', 'array'],
+ 'active' => ['required'],
+ 'timeout' => ['required', 'integer', 'min:1', 'max:600'],
+ ]);
+
/** @var Webhook $webhook */
$webhook = Webhook::query()->findOrFail($id);
- // TODO - Update
+ $webhook->active = $validated['active'] === 'true';
+ $webhook->fill($validated)->save();
+ $webhook->updateTrackedEvents($validated['events']);
$this->logActivity(ActivityType::WEBHOOK_UPDATE, $webhook);
+
return redirect('/settings/webhooks');
}
{
/** @var Webhook $webhook */
$webhook = Webhook::query()->findOrFail($id);
+
+ $this->setPageTitle(trans('settings.webhooks_delete'));
+
return view('settings.webhooks.delete', ['webhook' => $webhook]);
}
/** @var Webhook $webhook */
$webhook = Webhook::query()->findOrFail($id);
- // TODO - Delete event type relations
+ $webhook->trackedEvents()->delete();
$webhook->delete();
$this->logActivity(ActivityType::WEBHOOK_DELETE, $webhook);
+
return redirect('/settings/webhooks');
}
}