]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/WebhookController.php
Initial controller/views for webhooks management
[bookstack] / app / Http / Controllers / WebhookController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Actions\ActivityType;
6 use BookStack\Actions\Webhook;
7 use Illuminate\Http\Request;
8
9 class WebhookController extends Controller
10 {
11     public function __construct()
12     {
13         $this->middleware([
14             'can:settings-manage',
15         ]);
16     }
17
18     /**
19      * Show all webhooks configured in the system.
20      */
21     public function index()
22     {
23         // TODO - Get and pass webhooks
24         return view('settings.webhooks.index');
25     }
26
27     /**
28      * Show the view for creating a new webhook in the system.
29      */
30     public function create()
31     {
32         return view('settings.webhooks.create');
33     }
34
35     /**
36      * Store a new webhook in the system.
37      */
38     public function store(Request $request)
39     {
40         // TODO - Create webhook
41         $this->logActivity(ActivityType::WEBHOOK_CREATE, $webhook);
42         return redirect('/settings/webhooks');
43     }
44
45     /**
46      * Show the view to edit an existing webhook.
47      */
48     public function edit(string $id)
49     {
50         /** @var Webhook $webhook */
51         $webhook = Webhook::query()->findOrFail($id);
52
53         return view('settings.webhooks.edit', ['webhook' => $webhook]);
54     }
55
56     /**
57      * Update an existing webhook with the provided request data.
58      */
59     public function update(Request $request, string $id)
60     {
61         /** @var Webhook $webhook */
62         $webhook = Webhook::query()->findOrFail($id);
63
64         // TODO - Update
65
66         $this->logActivity(ActivityType::WEBHOOK_UPDATE, $webhook);
67         return redirect('/settings/webhooks');
68     }
69
70     /**
71      * Show the view to delete a webhook.
72      */
73     public function delete(string $id)
74     {
75         /** @var Webhook $webhook */
76         $webhook = Webhook::query()->findOrFail($id);
77         return view('settings.webhooks.delete', ['webhook' => $webhook]);
78     }
79
80     /**
81      * Destroy a webhook from the system.
82      */
83     public function destroy(string $id)
84     {
85         /** @var Webhook $webhook */
86         $webhook = Webhook::query()->findOrFail($id);
87
88         // TODO - Delete event type relations
89         $webhook->delete();
90
91         $this->logActivity(ActivityType::WEBHOOK_DELETE, $webhook);
92         return redirect('/settings/webhooks');
93     }
94 }