Feat: notify all administrators when a ticket is raised
- Updated `TicketService` to trigger notifications to all administrators upon ticket creation. - Added test to verify administrator notifications when a support ticket is raised. - Minor formatting adjustments in `Ticket` model's imports for consistency.
This commit is contained in:
parent
67002d6979
commit
04c62145b5
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\{Model, SoftDeletes};
|
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\{Model, SoftDeletes};
|
||||||
use Illuminate\Database\Eloquent\Relations\{BelongsTo, BelongsToMany, HasMany};
|
use Illuminate\Database\Eloquent\Relations\{BelongsTo, BelongsToMany, HasMany};
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
|||||||
@ -278,5 +278,16 @@ private function sendNotifications(Ticket $ticket): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always notify all administrators when a ticket is raised
|
||||||
|
$admins = User::whereHas('roles', function ($q): void {
|
||||||
|
$q->whereIn('name', ['Admin', 'admin']);
|
||||||
|
})->get();
|
||||||
|
foreach ($admins as $admin) {
|
||||||
|
if (! in_array($admin->id, $notifiedUserIds, true)) {
|
||||||
|
$admin->notify($notification);
|
||||||
|
$notifiedUserIds[] = $admin->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -356,3 +356,32 @@
|
|||||||
App\Notifications\TicketCommentedNotification::class
|
App\Notifications\TicketCommentedNotification::class
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('raising a support ticket always triggers a notification to all administrators', function (): void {
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$user->assignRole('user');
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$admin = User::where('email', 'admin@example.com')->firstOrFail();
|
||||||
|
|
||||||
|
$dto = new CreateTicketRequest(
|
||||||
|
userId: $user->id,
|
||||||
|
connectedAppId: null,
|
||||||
|
issueCategory: 'Technical Issue',
|
||||||
|
description: 'SSO log-in error.',
|
||||||
|
notifiedRoleIds: [],
|
||||||
|
notifiedUserIds: [],
|
||||||
|
attachment: null,
|
||||||
|
);
|
||||||
|
|
||||||
|
$service = app(TicketService::class);
|
||||||
|
$service->create($dto);
|
||||||
|
|
||||||
|
// Administrator should be notified of the new ticket
|
||||||
|
Notification::assertSentTo(
|
||||||
|
$admin,
|
||||||
|
TicketRaisedNotification::class
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user