This commit is contained in:
Stefanescu Mihai
2026-03-19 19:47:06 +02:00
parent e8d2728d57
commit eb735a9a98
19 changed files with 860 additions and 9 deletions
+6 -6
View File
@@ -191,14 +191,14 @@ Clients configure this DSN in their Sentry SDK — no changes needed on the SDK
### 4.1 Notification Channels ### 4.1 Notification Channels
- [ ] **Email:** on first occurrence of a new issue (not on every event) - [x] **Email:** on first occurrence of a new issue (not on every event)
- [ ] **Database (in-app):** notification bell with unread count - [x] **Database (in-app):** notification bell with unread count
- [ ] Extensible to Slack/webhooks later - [ ] Extensible to Slack/webhooks later
### 4.2 Alert Rules (per project) ### 4.2 Alert Rules (per project)
- [ ] Notify on: new issue, regression, spike (N events in M minutes) - [x] Notify on: new issue, regression, spike (N events in M minutes)
- [ ] Per-user mute controls - [x] Per-user mute controls
--- ---
@@ -252,8 +252,8 @@ Clients configure this DSN in their Sentry SDK — no changes needed on the SDK
- [x] 13. Status management (resolve, ignore, mute, auto-regression detection) - [x] 13. Status management (resolve, ignore, mute, auto-regression detection)
### Milestone 3 — Notifications & dashboard ### Milestone 3 — Notifications & dashboard
- [ ] 14. Email notifications on new issue / regression - [x] 14. Email notifications on new issue / regression
- [ ] 15. In-app notification system - [x] 15. In-app notification system
- [x] 16. Overview dashboard with charts (events over time) - [x] 16. Overview dashboard with charts (events over time)
### Milestone 4 — Production-readiness ### Milestone 4 — Production-readiness
@@ -0,0 +1,77 @@
<?php
namespace App\Http\Controllers;
use App\Models\AlertRule;
use App\Models\Project;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class AlertRuleController extends Controller
{
public function edit(Request $request, Project $project): View
{
$this->authorizeProject($request, $project);
$rules = collect(['new_issue', 'regression', 'spike'])->map(function ($type) use ($project) {
return $project->alertRules()->firstOrCreate(
['type' => $type],
['enabled' => true, 'config' => $type === 'spike' ? ['threshold' => 10, 'window_minutes' => 5] : null],
);
});
$preference = $request->user()->notificationPreferenceFor($project);
return view('projects.alerts', [
'project' => $project,
'rules' => $rules->keyBy('type'),
'preference' => $preference,
]);
}
public function update(Request $request, Project $project): RedirectResponse
{
$this->authorizeProject($request, $project);
foreach (['new_issue', 'regression', 'spike'] as $type) {
$rule = $project->alertRules()->where('type', $type)->first();
if ($rule) {
$rule->update(['enabled' => $request->boolean("rules.{$type}.enabled")]);
if ($type === 'spike') {
$rule->update([
'config' => [
'threshold' => max(1, (int) $request->input('rules.spike.threshold', 10)),
'window_minutes' => max(1, (int) $request->input('rules.spike.window_minutes', 5)),
],
]);
}
}
}
return back()->with('status', 'Alert rules updated.');
}
public function updatePreference(Request $request, Project $project): RedirectResponse
{
$this->authorizeProject($request, $project);
$pref = $request->user()->notificationPreferenceFor($project);
$pref->update([
'email_enabled' => $request->boolean('email_enabled'),
'database_enabled' => $request->boolean('database_enabled'),
'muted' => $request->boolean('muted'),
]);
return back()->with('status', 'Notification preferences updated.');
}
private function authorizeProject(Request $request, Project $project): void
{
abort_unless(
$request->user()->projects()->where('projects.id', $project->id)->exists(),
403,
);
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class NotificationController extends Controller
{
public function index(Request $request): View
{
$notifications = $request->user()
->notifications()
->latest()
->cursorPaginate(20);
return view('notifications.index', compact('notifications'));
}
public function markAsRead(Request $request, string $id): RedirectResponse
{
$notification = $request->user()->notifications()->findOrFail($id);
$notification->markAsRead();
$data = $notification->data;
if (! empty($data['project_id']) && ! empty($data['issue_id'])) {
return redirect()->route('projects.issues.show', [$data['project_id'], $data['issue_id']]);
}
return back();
}
public function markAllAsRead(Request $request): RedirectResponse
{
$request->user()->unreadNotifications->markAsRead();
return back()->with('status', 'All notifications marked as read.');
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AlertRule extends Model
{
use HasUlids;
protected $fillable = [
'project_id',
'type',
'enabled',
'config',
];
protected function casts(): array
{
return [
'enabled' => 'boolean',
'config' => 'array',
];
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
public function getSpikeThreshold(): int
{
return $this->config['threshold'] ?? 10;
}
public function getSpikeWindowMinutes(): int
{
return $this->config['window_minutes'] ?? 5;
}
}
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NotificationPreference extends Model
{
protected $fillable = [
'user_id',
'project_id',
'email_enabled',
'database_enabled',
'muted',
];
protected function casts(): array
{
return [
'email_enabled' => 'boolean',
'database_enabled' => 'boolean',
'muted' => 'boolean',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
}
+5
View File
@@ -50,6 +50,11 @@ class Project extends Model
return $this->hasMany(Event::class); return $this->hasMany(Event::class);
} }
public function alertRules(): HasMany
{
return $this->hasMany(AlertRule::class);
}
public function regenerateKeys(): void public function regenerateKeys(): void
{ {
$this->update([ $this->update([
+15
View File
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden; use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
@@ -37,4 +38,18 @@ class User extends Authenticatable
{ {
return $this->projects()->wherePivot('role', 'owner'); return $this->projects()->wherePivot('role', 'owner');
} }
public function notificationPreferences(): HasMany
{
return $this->hasMany(NotificationPreference::class);
}
public function notificationPreferenceFor(Project $project): NotificationPreference
{
return $this->notificationPreferences()
->firstOrCreate(
['project_id' => $project->id],
['email_enabled' => true, 'database_enabled' => true, 'muted' => false],
);
}
} }
@@ -0,0 +1,63 @@
<?php
namespace App\Notifications;
use App\Models\Issue;
use App\Models\Project;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class EventSpikeNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public Project $project,
public Issue $issue,
public int $eventCount,
public int $windowMinutes,
) {}
public function via(object $notifiable): array
{
$pref = $notifiable->notificationPreferenceFor($this->project);
$channels = [];
if ($pref->database_enabled) {
$channels[] = 'database';
}
if ($pref->email_enabled) {
$channels[] = 'mail';
}
return $channels;
}
public function toMail(object $notifiable): MailMessage
{
$url = route('projects.issues.show', [$this->project, $this->issue]);
return (new MailMessage)
->subject("[{$this->project->name}] Spike: {$this->eventCount} events in {$this->windowMinutes}m")
->greeting("Event spike in {$this->project->name}")
->line("{$this->eventCount} events received in the last {$this->windowMinutes} minutes for:")
->line($this->issue->title)
->action('View Issue', $url);
}
public function toArray(object $notifiable): array
{
return [
'type' => 'spike',
'project_id' => $this->project->id,
'project_name' => $this->project->name,
'issue_id' => $this->issue->id,
'issue_title' => $this->issue->title,
'event_count' => $this->eventCount,
'window_minutes' => $this->windowMinutes,
];
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Notifications;
use App\Models\Issue;
use App\Models\Project;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class IssueRegressionNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public Project $project,
public Issue $issue,
) {}
public function via(object $notifiable): array
{
$pref = $notifiable->notificationPreferenceFor($this->project);
$channels = [];
if ($pref->database_enabled) {
$channels[] = 'database';
}
if ($pref->email_enabled) {
$channels[] = 'mail';
}
return $channels;
}
public function toMail(object $notifiable): MailMessage
{
$url = route('projects.issues.show', [$this->project, $this->issue]);
return (new MailMessage)
->subject("[{$this->project->name}] Regression: {$this->issue->title}")
->greeting("Issue regressed in {$this->project->name}")
->line("A previously resolved issue has reappeared:")
->line($this->issue->title)
->action('View Issue', $url)
->line("Total occurrences: {$this->issue->times_seen}");
}
public function toArray(object $notifiable): array
{
return [
'type' => 'regression',
'project_id' => $this->project->id,
'project_name' => $this->project->name,
'issue_id' => $this->issue->id,
'issue_title' => $this->issue->title,
'level' => $this->issue->level,
];
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Notifications;
use App\Models\Issue;
use App\Models\Project;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class NewIssueNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public Project $project,
public Issue $issue,
) {}
public function via(object $notifiable): array
{
$pref = $notifiable->notificationPreferenceFor($this->project);
$channels = [];
if ($pref->database_enabled) {
$channels[] = 'database';
}
if ($pref->email_enabled) {
$channels[] = 'mail';
}
return $channels;
}
public function toMail(object $notifiable): MailMessage
{
$url = route('projects.issues.show', [$this->project, $this->issue]);
return (new MailMessage)
->subject("[{$this->project->name}] New issue: {$this->issue->title}")
->greeting("New issue in {$this->project->name}")
->line($this->issue->title)
->when($this->issue->culprit, fn ($mail) => $mail->line("in {$this->issue->culprit}"))
->action('View Issue', $url)
->line("Level: {$this->issue->level}");
}
public function toArray(object $notifiable): array
{
return [
'type' => 'new_issue',
'project_id' => $this->project->id,
'project_name' => $this->project->name,
'issue_id' => $this->issue->id,
'issue_title' => $this->issue->title,
'level' => $this->issue->level,
];
}
}
+35 -3
View File
@@ -12,6 +12,7 @@ class EventProcessor
public function __construct( public function __construct(
private Fingerprinter $fingerprinter, private Fingerprinter $fingerprinter,
private PayloadNormalizer $normalizer, private PayloadNormalizer $normalizer,
private NotificationDispatcher $notificationDispatcher,
) {} ) {}
/** /**
@@ -24,7 +25,9 @@ class EventProcessor
$fingerprint = $this->fingerprinter->compute($rawPayload); $fingerprint = $this->fingerprinter->compute($rawPayload);
$now = Carbon::now(); $now = Carbon::now();
$issue = $this->findOrCreateIssue($project, $data, $fingerprint, $now); $isNew = false;
$isRegression = false;
$issue = $this->findOrCreateIssue($project, $data, $fingerprint, $now, $isNew, $isRegression);
$event = Event::create([ $event = Event::create([
'issue_id' => $issue->id, 'issue_id' => $issue->id,
@@ -48,6 +51,8 @@ class EventProcessor
'raw_payload' => $rawPayload, 'raw_payload' => $rawPayload,
]); ]);
$this->dispatchNotifications($project, $issue, $isNew, $isRegression);
return $event; return $event;
} }
@@ -56,17 +61,23 @@ class EventProcessor
array $data, array $data,
string $fingerprint, string $fingerprint,
Carbon $now, Carbon $now,
bool &$isNew,
bool &$isRegression,
): Issue { ): Issue {
$issue = Issue::where('project_id', $project->id) $issue = Issue::where('project_id', $project->id)
->where('fingerprint', $fingerprint) ->where('fingerprint', $fingerprint)
->first(); ->first();
if ($issue) { if ($issue) {
$this->updateExistingIssue($issue, $data, $now); $isRegression = $this->updateExistingIssue($issue, $data, $now);
$isNew = false;
return $issue; return $issue;
} }
$isNew = true;
$isRegression = false;
return $this->createNewIssue($project, $data, $fingerprint, $now); return $this->createNewIssue($project, $data, $fingerprint, $now);
} }
@@ -101,7 +112,7 @@ class EventProcessor
]); ]);
} }
private function updateExistingIssue(Issue $issue, array $data, Carbon $now): void private function updateExistingIssue(Issue $issue, array $data, Carbon $now): bool
{ {
$wasResolved = $issue->status === 'resolved'; $wasResolved = $issue->status === 'resolved';
@@ -110,7 +121,11 @@ class EventProcessor
if ($wasResolved) { if ($wasResolved) {
$issue->markRegression(); $issue->markRegression();
return true;
} }
return false;
} }
private function buildTitle(?array $exception, ?string $message): string private function buildTitle(?array $exception, ?string $message): string
@@ -147,4 +162,21 @@ class EventProcessor
return $function ? "{$file} in {$function}" : $file; return $function ? "{$file} in {$function}" : $file;
} }
private function dispatchNotifications(
Project $project,
Issue $issue,
bool $isNew,
bool $isRegression,
): void {
if ($isNew) {
$this->notificationDispatcher->onNewIssue($project, $issue);
}
if ($isRegression) {
$this->notificationDispatcher->onRegression($project, $issue);
}
$this->notificationDispatcher->checkSpike($project, $issue);
}
} }
+97
View File
@@ -0,0 +1,97 @@
<?php
namespace App\Services;
use App\Models\AlertRule;
use App\Models\Event;
use App\Models\Issue;
use App\Models\Project;
use App\Notifications\EventSpikeNotification;
use App\Notifications\IssueRegressionNotification;
use App\Notifications\NewIssueNotification;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Notification;
class NotificationDispatcher
{
public function onNewIssue(Project $project, Issue $issue): void
{
if (! $this->ruleEnabled($project, 'new_issue')) {
return;
}
$recipients = $this->getRecipients($project);
Notification::send($recipients, new NewIssueNotification($project, $issue));
}
public function onRegression(Project $project, Issue $issue): void
{
if (! $this->ruleEnabled($project, 'regression')) {
return;
}
$recipients = $this->getRecipients($project);
Notification::send($recipients, new IssueRegressionNotification($project, $issue));
}
public function checkSpike(Project $project, Issue $issue): void
{
$rule = $project->alertRules()
->where('type', 'spike')
->where('enabled', true)
->first();
if (! $rule) {
return;
}
$threshold = $rule->getSpikeThreshold();
$windowMinutes = $rule->getSpikeWindowMinutes();
$recentCount = Event::where('issue_id', $issue->id)
->where('created_at', '>=', Carbon::now()->subMinutes($windowMinutes))
->count();
if ($recentCount < $threshold) {
return;
}
// Only send once per spike window — check if we already notified
$alreadyNotified = $project->users()
->first()
?->notifications()
->where('type', EventSpikeNotification::class)
->where('created_at', '>=', Carbon::now()->subMinutes($windowMinutes))
->whereJsonContains('data->issue_id', $issue->id)
->exists();
if ($alreadyNotified) {
return;
}
$recipients = $this->getRecipients($project);
Notification::send(
$recipients,
new EventSpikeNotification($project, $issue, $recentCount, $windowMinutes),
);
}
private function ruleEnabled(Project $project, string $type): bool
{
$rule = $project->alertRules()->where('type', $type)->first();
// Default: enabled if no rule exists (opt-out model)
return $rule === null || $rule->enabled;
}
private function getRecipients(Project $project)
{
return $project->users()
->get()
->filter(function ($user) use ($project) {
$pref = $user->notificationPreferenceFor($project);
return ! $pref->muted;
});
}
}
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('alert_rules', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignUlid('project_id')->constrained()->cascadeOnDelete();
$table->string('type'); // 'new_issue', 'regression', 'spike'
$table->boolean('enabled')->default(true);
$table->json('config')->nullable(); // e.g. {"threshold": 10, "window_minutes": 5} for spike
$table->timestamps();
$table->unique(['project_id', 'type']);
});
}
public function down(): void
{
Schema::dropIfExists('alert_rules');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('notification_preferences', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignUlid('project_id')->constrained()->cascadeOnDelete();
$table->boolean('email_enabled')->default(true);
$table->boolean('database_enabled')->default(true);
$table->boolean('muted')->default(false);
$table->timestamps();
$table->unique(['user_id', 'project_id']);
});
}
public function down(): void
{
Schema::dropIfExists('notification_preferences');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};
@@ -21,6 +21,9 @@
<x-nav-link :href="route('projects.issues.index', $currentProject)" :active="request()->routeIs('projects.issues.*')"> <x-nav-link :href="route('projects.issues.index', $currentProject)" :active="request()->routeIs('projects.issues.*')">
Issues Issues
</x-nav-link> </x-nav-link>
<x-nav-link :href="route('projects.alerts.edit', $currentProject)" :active="request()->routeIs('projects.alerts.*')">
Alerts
</x-nav-link>
<x-nav-link :href="route('projects.settings', $currentProject)" :active="request()->routeIs('projects.settings')"> <x-nav-link :href="route('projects.settings', $currentProject)" :active="request()->routeIs('projects.settings')">
Settings Settings
</x-nav-link> </x-nav-link>
@@ -55,6 +58,19 @@
</x-dropdown> </x-dropdown>
@endif @endif
{{-- Notification Bell --}}
@php($unreadCount = Auth::user()->unreadNotifications()->count())
<a href="{{ route('notifications.index') }}" class="relative p-2 text-gray-400 hover:text-gray-600 transition" title="Notifications">
<svg class="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.857 17.082a23.848 23.848 0 0 0 5.454-1.31A8.967 8.967 0 0 1 18 9.75V9A6 6 0 0 0 6 9v.75a8.967 8.967 0 0 1-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 0 1-5.714 0m5.714 0a3 3 0 1 1-5.714 0" />
</svg>
@if($unreadCount > 0)
<span class="absolute -top-0.5 -right-0.5 inline-flex items-center justify-center px-1.5 py-0.5 text-[10px] font-bold leading-none text-white bg-red-500 rounded-full">
{{ $unreadCount > 99 ? '99+' : $unreadCount }}
</span>
@endif
</a>
<x-dropdown align="right" width="48"> <x-dropdown align="right" width="48">
<x-slot name="trigger"> <x-slot name="trigger">
<button class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:text-gray-700 focus:outline-none transition ease-in-out duration-150"> <button class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-gray-500 bg-white hover:text-gray-700 focus:outline-none transition ease-in-out duration-150">
@@ -0,0 +1,75 @@
<x-app-layout>
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">Notifications</h2>
@if(Auth::user()->unreadNotifications->count() > 0)
<form method="POST" action="{{ route('notifications.mark-all-read') }}">
@csrf
<x-secondary-button type="submit">Mark All as Read</x-secondary-button>
</form>
@endif
</div>
</x-slot>
<div class="py-8">
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
@if(session('status'))
<div class="mb-4 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-md text-sm">
{{ session('status') }}
</div>
@endif
@if($notifications->isEmpty())
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-12 text-center text-gray-500">
No notifications yet.
</div>
@else
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg divide-y divide-gray-200">
@foreach($notifications as $notification)
@php
$data = $notification->data;
$isUnread = $notification->read_at === null;
$typeLabel = match($data['type'] ?? '') {
'new_issue' => 'New Issue',
'regression' => 'Regression',
'spike' => 'Spike',
default => 'Notification',
};
$typeColor = match($data['type'] ?? '') {
'new_issue' => 'bg-blue-100 text-blue-800',
'regression' => 'bg-orange-100 text-orange-800',
'spike' => 'bg-red-100 text-red-800',
default => 'bg-gray-100 text-gray-600',
};
@endphp
<a href="{{ route('notifications.read', $notification->id) }}"
class="block px-6 py-4 hover:bg-gray-50 transition {{ $isUnread ? 'bg-indigo-50/30' : '' }}">
<div class="flex items-start gap-3">
@if($isUnread)
<span class="mt-2 w-2 h-2 rounded-full bg-indigo-500 shrink-0"></span>
@else
<span class="mt-2 w-2 h-2 shrink-0"></span>
@endif
<div class="flex-1 min-w-0">
<div class="flex items-center gap-2 mb-1">
<span class="inline-flex px-2 py-0.5 rounded-full text-[10px] font-semibold {{ $typeColor }}">{{ $typeLabel }}</span>
<span class="text-xs text-gray-400">{{ $data['project_name'] ?? '' }}</span>
<span class="text-xs text-gray-400 ml-auto">{{ $notification->created_at->diffForHumans() }}</span>
</div>
<p class="text-sm text-gray-900 truncate">{{ $data['issue_title'] ?? '' }}</p>
@if(($data['type'] ?? '') === 'spike')
<p class="text-xs text-gray-500 mt-0.5">{{ $data['event_count'] ?? 0 }} events in {{ $data['window_minutes'] ?? 0 }}m</p>
@endif
</div>
</div>
</a>
@endforeach
</div>
<div class="mt-4">
{{ $notifications->links() }}
</div>
@endif
</div>
</div>
</x-app-layout>
+135
View File
@@ -0,0 +1,135 @@
<x-app-layout>
@php($currentProject = $project)
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">{{ $project->name }} &mdash; Alert Rules</h2>
</x-slot>
<div class="py-8">
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8 space-y-6">
@if(session('status'))
<div class="bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-md text-sm">
{{ session('status') }}
</div>
@endif
{{-- Alert Rules --}}
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
<h3 class="text-lg font-medium text-gray-900 mb-1">Alert Rules</h3>
<p class="text-sm text-gray-500 mb-6">Configure when notifications are sent for this project.</p>
<form method="POST" action="{{ route('projects.alerts.update', $project) }}" class="space-y-6">
@csrf
@method('PATCH')
{{-- New Issue --}}
<div class="flex items-center justify-between py-3 border-b border-gray-100">
<div>
<div class="font-medium text-gray-900">New Issue</div>
<div class="text-sm text-gray-500">Notify when a new issue is first seen.</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="rules[new_issue][enabled]" value="0">
<input type="checkbox" name="rules[new_issue][enabled]" value="1" class="sr-only peer" {{ ($rules['new_issue']->enabled ?? true) ? 'checked' : '' }}>
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
{{-- Regression --}}
<div class="flex items-center justify-between py-3 border-b border-gray-100">
<div>
<div class="font-medium text-gray-900">Regression</div>
<div class="text-sm text-gray-500">Notify when a resolved issue reappears.</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="rules[regression][enabled]" value="0">
<input type="checkbox" name="rules[regression][enabled]" value="1" class="sr-only peer" {{ ($rules['regression']->enabled ?? true) ? 'checked' : '' }}>
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
{{-- Spike --}}
<div class="py-3 border-b border-gray-100">
<div class="flex items-center justify-between">
<div>
<div class="font-medium text-gray-900">Event Spike</div>
<div class="text-sm text-gray-500">Notify when an issue receives many events in a short window.</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="rules[spike][enabled]" value="0">
<input type="checkbox" name="rules[spike][enabled]" value="1" class="sr-only peer" {{ ($rules['spike']->enabled ?? true) ? 'checked' : '' }}>
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
<div class="mt-4 flex items-center gap-4 text-sm">
<div class="flex items-center gap-2">
<x-input-label for="spike_threshold" value="Threshold" />
<x-text-input id="spike_threshold" name="rules[spike][threshold]" type="number" min="1" class="w-20"
:value="$rules['spike']->config['threshold'] ?? 10" />
<span class="text-gray-500">events in</span>
</div>
<div class="flex items-center gap-2">
<x-text-input id="spike_window" name="rules[spike][window_minutes]" type="number" min="1" class="w-20"
:value="$rules['spike']->config['window_minutes'] ?? 5" />
<span class="text-gray-500">minutes</span>
</div>
</div>
</div>
<x-primary-button>Save Alert Rules</x-primary-button>
</form>
</div>
{{-- Personal Notification Preferences --}}
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg p-6">
<h3 class="text-lg font-medium text-gray-900 mb-1">Your Notification Preferences</h3>
<p class="text-sm text-gray-500 mb-6">Control how you receive notifications for this project.</p>
<form method="POST" action="{{ route('projects.alerts.preference', $project) }}" class="space-y-6">
@csrf
@method('PATCH')
<div class="flex items-center justify-between py-3 border-b border-gray-100">
<div>
<div class="font-medium text-gray-900">Email Notifications</div>
<div class="text-sm text-gray-500">Receive alert emails for this project.</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="email_enabled" value="0">
<input type="checkbox" name="email_enabled" value="1" class="sr-only peer" {{ $preference->email_enabled ? 'checked' : '' }}>
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
<div class="flex items-center justify-between py-3 border-b border-gray-100">
<div>
<div class="font-medium text-gray-900">In-App Notifications</div>
<div class="text-sm text-gray-500">Show notifications in the bell icon.</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="database_enabled" value="0">
<input type="checkbox" name="database_enabled" value="1" class="sr-only peer" {{ $preference->database_enabled ? 'checked' : '' }}>
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-indigo-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
</label>
</div>
<div class="flex items-center justify-between py-3 border-b border-gray-100">
<div>
<div class="font-medium text-red-600">Mute All</div>
<div class="text-sm text-gray-500">Completely suppress all notifications from this project.</div>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="hidden" name="muted" value="0">
<input type="checkbox" name="muted" value="1" class="sr-only peer" {{ $preference->muted ? 'checked' : '' }}>
<div class="w-11 h-6 bg-gray-200 peer-focus:ring-2 peer-focus:ring-red-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-red-600"></div>
</label>
</div>
<x-primary-button>Save Preferences</x-primary-button>
</form>
</div>
</div>
</div>
</x-app-layout>
+10
View File
@@ -1,8 +1,10 @@
<?php <?php
use App\Http\Controllers\AlertRuleController;
use App\Http\Controllers\DashboardController; use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EventController; use App\Http\Controllers\EventController;
use App\Http\Controllers\IssueController; use App\Http\Controllers\IssueController;
use App\Http\Controllers\NotificationController;
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use App\Http\Controllers\ProjectController; use App\Http\Controllers\ProjectController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
@@ -28,6 +30,14 @@ Route::middleware(['auth', 'verified'])->group(function () {
Route::patch('/projects/{project}/issues/{issue}/status', [IssueController::class, 'updateStatus'])->name('projects.issues.status'); Route::patch('/projects/{project}/issues/{issue}/status', [IssueController::class, 'updateStatus'])->name('projects.issues.status');
Route::get('/projects/{project}/issues/{issue}/events/{event}', [EventController::class, 'show'])->name('projects.issues.events.show'); Route::get('/projects/{project}/issues/{issue}/events/{event}', [EventController::class, 'show'])->name('projects.issues.events.show');
Route::get('/projects/{project}/alerts', [AlertRuleController::class, 'edit'])->name('projects.alerts.edit');
Route::patch('/projects/{project}/alerts', [AlertRuleController::class, 'update'])->name('projects.alerts.update');
Route::patch('/projects/{project}/alerts/preference', [AlertRuleController::class, 'updatePreference'])->name('projects.alerts.preference');
Route::get('/notifications', [NotificationController::class, 'index'])->name('notifications.index');
Route::get('/notifications/{id}/read', [NotificationController::class, 'markAsRead'])->name('notifications.read');
Route::post('/notifications/mark-all-read', [NotificationController::class, 'markAllAsRead'])->name('notifications.mark-all-read');
}); });
Route::middleware('auth')->group(function () { Route::middleware('auth')->group(function () {