From f1d161793d5ea5235f9ff8659959d8ce634227b0 Mon Sep 17 00:00:00 2001 From: Joel Wedemire Date: Wed, 8 Apr 2026 22:01:50 -0700 Subject: [PATCH] Add email connections to ticketing settings --- .../TicketingSettingsController.php | 67 +++++++++++++++++++ src/routes/ticketing.php | 3 + 2 files changed, 70 insertions(+) diff --git a/src/Http/Controllers/TicketingSettingsController.php b/src/Http/Controllers/TicketingSettingsController.php index 7f831c7..02ad33f 100644 --- a/src/Http/Controllers/TicketingSettingsController.php +++ b/src/Http/Controllers/TicketingSettingsController.php @@ -2,6 +2,7 @@ namespace Dashboard\Ticketing\Http\Controllers; +use Dashboard\Ticketing\Models\EmailConnection; use Dashboard\Ticketing\Models\PriorityLevel; use Dashboard\Ticketing\Models\TicketingAgentAccess; use Dashboard\Ticketing\Models\TicketingGroup; @@ -95,11 +96,16 @@ class TicketingSettingsController extends Controller ->orderBy('name') ->get(); + $emailConnections = $isBootstrap + ? collect() + : EmailConnection::whereIn('group_id', $myGroupIds)->get(); + return Inertia::render('Ticketing/Settings', [ 'groups' => $groups, 'agents' => $agents, 'priorities' => $priorities, 'projects' => $projects, + 'emailConnections' => $emailConnections, 'myGroupIds' => $myGroupIds, 'isBootstrap' => $isBootstrap, 'isSiteAdmin' => $this->isSiteAdmin(), @@ -323,4 +329,65 @@ class TicketingSettingsController extends Controller return back()->with('success', 'Project removed.'); } + + public function storeEmailConnection(Request $request) + { + $this->requireAgentAccess(); + + $validated = $request->validate([ + 'group_id' => 'required|exists:ticketing_groups,id', + 'type' => 'required|in:gmail,imap', + 'active' => 'boolean', + 'config.host' => 'nullable|string|max:255', + 'config.port' => 'nullable|integer', + 'config.username' => 'nullable|string|max:255', + 'config.password' => 'nullable|string|max:500', + 'config.encryption' => 'nullable|in:ssl,tls,none', + 'config.mailbox' => 'nullable|string|max:255', + ]); + + $this->requireManagerAccess($validated['group_id']); + + EmailConnection::create([ + 'group_id' => $validated['group_id'], + 'type' => $validated['type'], + 'active' => $request->boolean('active', true), + 'config' => $request->input('config', []), + ]); + + return back()->with('success', 'Email connection saved.'); + } + + public function updateEmailConnection(Request $request, EmailConnection $connection) + { + $this->requireAgentAccess(); + $this->requireManagerAccess($connection->group_id); + + $request->validate([ + 'type' => 'required|in:gmail,imap', + 'active' => 'boolean', + 'config.host' => 'nullable|string|max:255', + 'config.port' => 'nullable|integer', + 'config.username' => 'nullable|string|max:255', + 'config.password' => 'nullable|string|max:500', + 'config.encryption' => 'nullable|in:ssl,tls,none', + 'config.mailbox' => 'nullable|string|max:255', + ]); + + $connection->update([ + 'type' => $request->type, + 'active' => $request->boolean('active', true), + 'config' => $request->input('config', $connection->config), + ]); + + return back()->with('success', 'Email connection updated.'); + } + + public function destroyEmailConnection(EmailConnection $connection) + { + $this->requireAgentAccess(); + $this->requireManagerAccess($connection->group_id); + $connection->delete(); + return back()->with('success', 'Email connection removed.'); + } } diff --git a/src/routes/ticketing.php b/src/routes/ticketing.php index 63decdd..0668899 100644 --- a/src/routes/ticketing.php +++ b/src/routes/ticketing.php @@ -22,6 +22,9 @@ Route::middleware(['web', 'auth', 'app.access:ticketing'])->prefix('app/ticketin Route::post('/settings/projects', [TicketingSettingsController::class, 'storeProject'])->name('settings.projects.store'); Route::put('/settings/projects/{project}', [TicketingSettingsController::class, 'updateProject'])->name('settings.projects.update'); Route::delete('/settings/projects/{project}', [TicketingSettingsController::class, 'destroyProject'])->name('settings.projects.destroy'); + Route::post('/settings/email', [TicketingSettingsController::class, 'storeEmailConnection'])->name('settings.email.store'); + Route::put('/settings/email/{connection}', [TicketingSettingsController::class, 'updateEmailConnection'])->name('settings.email.update'); + Route::delete('/settings/email/{connection}', [TicketingSettingsController::class, 'destroyEmailConnection'])->name('settings.email.destroy'); // Ticket routes Route::get('/', [TicketController::class, 'index'])->name('index');