Skip to content

NOW MANAGED ON CODEBERG

Notifications: Reorgranised classes into domain specific folders

Dan Brown8e3f8de6278c
diff --git a/app/Access/EmailConfirmationService.php b/app/Access/EmailConfirmationService.php
index 79220f996..de9ea69b8 100644
--- a/app/Access/EmailConfirmationService.php
+++ b/app/Access/EmailConfirmationService.php
@@ -2,8 +2,8 @@
namespace BookStack\Access;
+use BookStack\Access\Notifications\ConfirmEmailNotification;
use BookStack\Exceptions\ConfirmationEmailException;
-use BookStack\Notifications\ConfirmEmail;
use BookStack\Users\Models\User;
class EmailConfirmationService extends UserTokenService
@@ -26,7 +26,7 @@ class EmailConfirmationService extends UserTokenService
$this->deleteByUser($user);
$token = $this->createTokenForUser($user);
- $user->notify(new ConfirmEmail($token));
+ $user->notify(new ConfirmEmailNotification($token));
}
/**
diff --git a/app/Notifications/ConfirmEmail.php b/app/Access/Notifications/ConfirmEmailNotification.php
similarity index 82%
rename from app/Notifications/ConfirmEmail.php
rename to app/Access/Notifications/ConfirmEmailNotification.php
index 6b395e137..c67e1cf62 100644
--- a/app/Notifications/ConfirmEmail.php
+++ b/app/Access/Notifications/ConfirmEmailNotification.php
@@ -1,11 +1,12 @@
<?php
-namespace BookStack\Notifications;
+namespace BookStack\Access\Notifications;
+use BookStack\App\MailNotification;
use BookStack\Users\Models\User;
use Illuminate\Notifications\Messages\MailMessage;
-class ConfirmEmail extends MailNotification
+class ConfirmEmailNotification extends MailNotification
{
public function __construct(
public string $token
diff --git a/app/Notifications/ResetPassword.php b/app/Access/Notifications/ResetPasswordNotification.php
similarity index 81%
rename from app/Notifications/ResetPassword.php
rename to app/Access/Notifications/ResetPasswordNotification.php
index 2d7e9c361..0a0f4ceb7 100644
--- a/app/Notifications/ResetPassword.php
+++ b/app/Access/Notifications/ResetPasswordNotification.php
@@ -1,11 +1,12 @@
<?php
-namespace BookStack\Notifications;
+namespace BookStack\Access\Notifications;
+use BookStack\App\MailNotification;
use BookStack\Users\Models\User;
use Illuminate\Notifications\Messages\MailMessage;
-class ResetPassword extends MailNotification
+class ResetPasswordNotification extends MailNotification
{
public function __construct(
public string $token
diff --git a/app/Notifications/UserInvite.php b/app/Access/Notifications/UserInviteNotification.php
similarity index 85%
rename from app/Notifications/UserInvite.php
rename to app/Access/Notifications/UserInviteNotification.php
index 87ea31c04..b453fc95d 100644
--- a/app/Notifications/UserInvite.php
+++ b/app/Access/Notifications/UserInviteNotification.php
@@ -1,11 +1,12 @@
<?php
-namespace BookStack\Notifications;
+namespace BookStack\Access\Notifications;
+use BookStack\App\MailNotification;
use BookStack\Users\Models\User;
use Illuminate\Notifications\Messages\MailMessage;
-class UserInvite extends MailNotification
+class UserInviteNotification extends MailNotification
{
public function __construct(
public string $token
diff --git a/app/Access/UserInviteService.php b/app/Access/UserInviteService.php
index 00e361e82..7d955f385 100644
--- a/app/Access/UserInviteService.php
+++ b/app/Access/UserInviteService.php
@@ -2,7 +2,7 @@
namespace BookStack\Access;
-use BookStack\Notifications\UserInvite;
+use BookStack\Access\Notifications\UserInviteNotification;
use BookStack\Users\Models\User;
class UserInviteService extends UserTokenService
@@ -18,6 +18,6 @@ class UserInviteService extends UserTokenService
{
$this->deleteByUser($user);
$token = $this->createTokenForUser($user);
- $user->notify(new UserInvite($token));
+ $user->notify(new UserInviteNotification($token));
}
}
diff --git a/app/Activity/Notifications/Messages/BaseActivityNotification.php b/app/Activity/Notifications/Messages/BaseActivityNotification.php
index a2045c8dc..414859091 100644
--- a/app/Activity/Notifications/Messages/BaseActivityNotification.php
+++ b/app/Activity/Notifications/Messages/BaseActivityNotification.php
@@ -4,7 +4,7 @@ namespace BookStack\Activity\Notifications\Messages;
use BookStack\Activity\Models\Loggable;
use BookStack\Activity\Notifications\MessageParts\LinkedMailMessageLine;
-use BookStack\Notifications\MailNotification;
+use BookStack\App\MailNotification;
use BookStack\Users\Models\User;
use Illuminate\Bus\Queueable;
diff --git a/app/Notifications/MailNotification.php b/app/App/MailNotification.php
similarity index 96%
rename from app/Notifications/MailNotification.php
rename to app/App/MailNotification.php
index 1f40219f9..8c57b5621 100644
--- a/app/Notifications/MailNotification.php
+++ b/app/App/MailNotification.php
@@ -1,6 +1,6 @@
<?php
-namespace BookStack\Notifications;
+namespace BookStack\App;
use BookStack\Users\Models\User;
use Illuminate\Bus\Queueable;
diff --git a/app/Settings/MaintenanceController.php b/app/Settings/MaintenanceController.php
index 9c48a4323..60e5fee28 100644
--- a/app/Settings/MaintenanceController.php
+++ b/app/Settings/MaintenanceController.php
@@ -5,7 +5,6 @@ namespace BookStack\Settings;
use BookStack\Activity\ActivityType;
use BookStack\Entities\Tools\TrashCan;
use BookStack\Http\Controller;
-use BookStack\Notifications\TestEmail;
use BookStack\References\ReferenceStore;
use BookStack\Uploads\ImageService;
use Illuminate\Http\Request;
@@ -69,7 +68,7 @@ class MaintenanceController extends Controller
$this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
try {
- user()->notifyNow(new TestEmail());
+ user()->notifyNow(new TestEmailNotification());
$this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
} catch (\Exception $exception) {
$errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
diff --git a/app/Notifications/TestEmail.php b/app/Settings/TestEmailNotification.php
similarity index 78%
rename from app/Notifications/TestEmail.php
rename to app/Settings/TestEmailNotification.php
index af9e5847f..3b13543e4 100644
--- a/app/Notifications/TestEmail.php
+++ b/app/Settings/TestEmailNotification.php
@@ -1,11 +1,12 @@
<?php
-namespace BookStack\Notifications;
+namespace BookStack\Settings;
+use BookStack\App\MailNotification;
use BookStack\Users\Models\User;
use Illuminate\Notifications\Messages\MailMessage;
-class TestEmail extends MailNotification
+class TestEmailNotification extends MailNotification
{
public function toMail(User $notifiable): MailMessage
{
diff --git a/app/Users/Models/User.php b/app/Users/Models/User.php
index e3d856a8d..92701ac13 100644
--- a/app/Users/Models/User.php
+++ b/app/Users/Models/User.php
@@ -3,6 +3,7 @@
namespace BookStack\Users\Models;
use BookStack\Access\Mfa\MfaValue;
+use BookStack\Access\Notifications\ResetPasswordNotification;
use BookStack\Access\SocialAccount;
use BookStack\Activity\Models\Favourite;
use BookStack\Activity\Models\Loggable;
@@ -11,7 +12,6 @@ use BookStack\Api\ApiToken;
use BookStack\App\Model;
use BookStack\App\Sluggable;
use BookStack\Entities\Tools\SlugGenerator;
-use BookStack\Notifications\ResetPassword;
use BookStack\Translation\LanguageManager;
use BookStack\Uploads\Image;
use Carbon\Carbon;
@@ -365,7 +365,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/
public function sendPasswordResetNotification($token)
{
- $this->notify(new ResetPassword($token));
+ $this->notify(new ResetPasswordNotification($token));
}
/**
diff --git a/tests/Api/UsersApiTest.php b/tests/Api/UsersApiTest.php
index e2a04b528..6ad727257 100644
--- a/tests/Api/UsersApiTest.php
+++ b/tests/Api/UsersApiTest.php
@@ -2,11 +2,11 @@
namespace Tests\Api;
+use BookStack\Access\Notifications\UserInviteNotification;
use BookStack\Activity\ActivityType;
use BookStack\Activity\Models\Activity as ActivityModel;
use BookStack\Entities\Models\Entity;
use BookStack\Facades\Activity;
-use BookStack\Notifications\UserInvite;
use BookStack\Users\Models\Role;
use BookStack\Users\Models\User;
use Illuminate\Support\Facades\Hash;
@@ -140,7 +140,7 @@ class UsersApiTest extends TestCase
$resp->assertStatus(200);
/** @var User $user */
$user = User::query()->where('email', '=', '[email protected]')->first();
- Notification::assertSentTo($user, UserInvite::class);
+ Notification::assertSentTo($user, UserInviteNotification::class);
}
public function test_create_name_and_email_validation()
diff --git a/tests/Auth/RegistrationTest.php b/tests/Auth/RegistrationTest.php
index bc190afd8..ff1a9d66b 100644
--- a/tests/Auth/RegistrationTest.php
+++ b/tests/Auth/RegistrationTest.php
@@ -2,7 +2,7 @@
namespace Tests\Auth;
-use BookStack\Notifications\ConfirmEmail;
+use BookStack\Access\Notifications\ConfirmEmailNotification;
use BookStack\Users\Models\Role;
use BookStack\Users\Models\User;
use Illuminate\Support\Facades\DB;
@@ -28,7 +28,7 @@ class RegistrationTest extends TestCase
// Ensure notification sent
/** @var User $dbUser */
$dbUser = User::query()->where('email', '=', $user->email)->first();
- Notification::assertSentTo($dbUser, ConfirmEmail::class);
+ Notification::assertSentTo($dbUser, ConfirmEmailNotification::class);
// Test access and resend confirmation email
$resp = $this->post('/login', ['email' => $user->email, 'password' => $user->password]);
@@ -42,7 +42,7 @@ class RegistrationTest extends TestCase
// Get confirmation and confirm notification matches
$emailConfirmation = DB::table('email_confirmations')->where('user_id', '=', $dbUser->id)->first();
- Notification::assertSentTo($dbUser, ConfirmEmail::class, function ($notification, $channels) use ($emailConfirmation) {
+ Notification::assertSentTo($dbUser, ConfirmEmailNotification::class, function ($notification, $channels) use ($emailConfirmation) {
return $notification->token === $emailConfirmation->token;
});
diff --git a/tests/Auth/ResetPasswordTest.php b/tests/Auth/ResetPasswordTest.php
index b97a2f2d3..e60ac5643 100644
--- a/tests/Auth/ResetPasswordTest.php
+++ b/tests/Auth/ResetPasswordTest.php
@@ -2,7 +2,7 @@
namespace Tests\Auth;
-use BookStack\Notifications\ResetPassword;
+use BookStack\Access\Notifications\ResetPasswordNotification;
use BookStack\Users\Models\User;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@@ -34,8 +34,8 @@ class ResetPasswordTest extends TestCase
/** @var User $user */
$user = User::query()->where('email', '=', '[email protected]')->first();
- Notification::assertSentTo($user, ResetPassword::class);
- $n = Notification::sent($user, ResetPassword::class);
+ Notification::assertSentTo($user, ResetPasswordNotification::class);
+ $n = Notification::sent($user, ResetPasswordNotification::class);
$this->get('/password/reset/' . $n->first()->token)
->assertOk()
@@ -95,7 +95,7 @@ class ResetPasswordTest extends TestCase
$resp = $this->followingRedirects()->post('/password/email', [
'email' => $editor->email,
]);
- Notification::assertTimesSent(1, ResetPassword::class);
+ Notification::assertTimesSent(1, ResetPasswordNotification::class);
$resp->assertSee('A password reset link will be sent to ' . $editor->email . ' if that email address is found in the system.');
}
}
diff --git a/tests/Auth/UserInviteTest.php b/tests/Auth/UserInviteTest.php
index 8d6143877..a9dee0007 100644
--- a/tests/Auth/UserInviteTest.php
+++ b/tests/Auth/UserInviteTest.php
@@ -2,8 +2,8 @@
namespace Tests\Auth;
+use BookStack\Access\Notifications\UserInviteNotification;
use BookStack\Access\UserInviteService;
-use BookStack\Notifications\UserInvite;
use BookStack\Users\Models\User;
use Carbon\Carbon;
use Illuminate\Notifications\Messages\MailMessage;
@@ -29,7 +29,7 @@ class UserInviteTest extends TestCase
$newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
- Notification::assertSentTo($newUser, UserInvite::class);
+ Notification::assertSentTo($newUser, UserInviteNotification::class);
$this->assertDatabaseHas('user_invites', [
'user_id' => $newUser->id,
]);
@@ -50,7 +50,7 @@ class UserInviteTest extends TestCase
$resp->assertRedirect('/settings/users');
$newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
- Notification::assertSentTo($newUser, UserInvite::class, function ($notification, $channels, $notifiable) {
+ Notification::assertSentTo($newUser, UserInviteNotification::class, function ($notification, $channels, $notifiable) {
/** @var MailMessage $mail */
$mail = $notification->toMail($notifiable);
diff --git a/tests/Settings/TestEmailTest.php b/tests/Settings/TestEmailTest.php
index 322f90107..e96024e7b 100644
--- a/tests/Settings/TestEmailTest.php
+++ b/tests/Settings/TestEmailTest.php
@@ -2,7 +2,7 @@
namespace Tests\Settings;
-use BookStack\Notifications\TestEmail;
+use BookStack\Settings\TestEmailNotification;
use Illuminate\Contracts\Notifications\Dispatcher;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
@@ -26,7 +26,7 @@ class TestEmailTest extends TestCase
$sendReq->assertRedirect('/settings/maintenance#image-cleanup');
$this->assertSessionHas('success', 'Email sent to ' . $admin->email);
- Notification::assertSentTo($admin, TestEmail::class);
+ Notification::assertSentTo($admin, TestEmailNotification::class);
}
public function test_send_test_email_failure_displays_error_notification()
@@ -57,6 +57,6 @@ class TestEmailTest extends TestCase
$this->permissions->grantUserRolePermissions($user, ['settings-manage']);
$sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
- Notification::assertSentTo($user, TestEmail::class);
+ Notification::assertSentTo($user, TestEmailNotification::class);
}
}