diff --git a/app/Livewire/LayoutPopups.php b/app/Livewire/LayoutPopups.php index dd7f14678..b6f06f808 100644 --- a/app/Livewire/LayoutPopups.php +++ b/app/Livewire/LayoutPopups.php @@ -17,10 +17,14 @@ public function testEvent() { $this->dispatch('success', 'Realtime events configured!'); } - public function disable() + public function disableSponsorship() { auth()->user()->update(['is_notification_sponsorship_enabled' => false]); } + public function disableNotifications() + { + auth()->user()->update(['is_notification_notifications_enabled' => false]); + } public function render() { return view('livewire.layout-popups'); diff --git a/app/Models/Team.php b/app/Models/Team.php index 656c4009b..7cb1601de 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -48,13 +48,15 @@ public function getRecepients($notification) } return explode(',', $recipients); } - static public function serverLimitReached() { + static public function serverLimitReached() + { $serverLimit = Team::serverLimit(); $team = currentTeam(); $servers = $team->servers->count(); return $servers >= $serverLimit; } - public function serverOverflow() { + public function serverOverflow() + { if ($this->serverLimit() < $this->servers->count()) { return true; } @@ -170,4 +172,17 @@ public function trialEndedButSubscribed() ]); } } + public function isAnyNotificationEnabled() + { + if (isCloud()) { + return true; + } + if (!data_get(auth()->user(), 'is_notification_notifications_enabled')) { + return true; + } + if ($this->smtp_enabled || $this->resend_enabled || $this->discord_enabled || $this->telegram_enabled || $this->use_instance_email_settings) { + return true; + } + return false; + } } diff --git a/database/migrations/2024_03_07_115054_add_notifications_notification_disable.php b/database/migrations/2024_03_07_115054_add_notifications_notification_disable.php new file mode 100644 index 000000000..8633b971e --- /dev/null +++ b/database/migrations/2024_03_07_115054_add_notifications_notification_disable.php @@ -0,0 +1,28 @@ +boolean('is_notification_notifications_enabled')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('is_notification_notifications_enabled'); + }); + } +}; diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 3bd1730be..65d2f0736 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -150,7 +150,17 @@ class="{{ request()->is('subscription*') ? 'text-warning icon' : 'icon' }}" @endif - +
  • + + + + + Notifications + +
  • @if (isInstanceAdmin())
  • diff --git a/resources/views/components/notifications/navbar.blade.php b/resources/views/components/notifications/navbar.blade.php new file mode 100644 index 000000000..65b374249 --- /dev/null +++ b/resources/views/components/notifications/navbar.blade.php @@ -0,0 +1,25 @@ +
    +
    +

    Team Notifications

    +
    + +
    +
    diff --git a/resources/views/components/team/navbar.blade.php b/resources/views/components/team/navbar.blade.php index 971b9de85..a3f13b4af 100644 --- a/resources/views/components/team/navbar.blade.php +++ b/resources/views/components/team/navbar.blade.php @@ -1,7 +1,7 @@
    @endif @@ -20,4 +21,16 @@ class="text-white underline">/subscription to update your subscription or re @endif + @if (!currentTeam()->isAnyNotificationEnabled()) +
    +
    + WARNING: No notifications enabled.

    It is highly recommended to enable at least + one + notification channel to receive important alerts.
    Visit /notification to enable notifications.
    + Disable This + Popup +
    +
    + @endif diff --git a/resources/views/livewire/team/notification/index.blade.php b/resources/views/livewire/team/notification/index.blade.php index ed961deb0..e5eaffe17 100644 --- a/resources/views/livewire/team/notification/index.blade.php +++ b/resources/views/livewire/team/notification/index.blade.php @@ -1,5 +1,5 @@
    - +

    Notifications

    diff --git a/routes/web.php b/routes/web.php index f49d1b278..c442f6c75 100644 --- a/routes/web.php +++ b/routes/web.php @@ -121,11 +121,13 @@ Route::get('/', TagsIndex::class)->name('tags.index'); Route::get('/{tag_name}', TagsShow::class)->name('tags.show'); }); + Route::prefix('notifications')->group(function () { + Route::get('/', TeamNotificationIndex::class)->name('notification.index'); + }); Route::prefix('team')->group(function () { Route::get('/', TeamIndex::class)->name('team.index'); Route::get('/new', TeamCreate::class)->name('team.create'); Route::get('/members', TeamMemberIndex::class)->name('team.member.index'); - Route::get('/notifications', TeamNotificationIndex::class)->name('team.notification.index'); Route::get('/shared-variables', TeamSharedVariablesIndex::class)->name('team.shared-variables.index'); Route::get('/storages', TeamStorageIndex::class)->name('team.storage.index'); Route::get('/storages/new', TeamStorageCreate::class)->name('team.storage.create');