]> BookStack Code Mirror - bookstack/commitdiff
Notifications: Reorgranised classes into domain specific folders
authorDan Brown <redacted>
Mon, 11 Sep 2023 18:26:28 +0000 (19:26 +0100)
committerDan Brown <redacted>
Mon, 11 Sep 2023 18:27:36 +0000 (19:27 +0100)
Closes #4500

15 files changed:
app/Access/EmailConfirmationService.php
app/Access/Notifications/ConfirmEmailNotification.php [moved from app/Notifications/ConfirmEmail.php with 82% similarity]
app/Access/Notifications/ResetPasswordNotification.php [moved from app/Notifications/ResetPassword.php with 81% similarity]
app/Access/Notifications/UserInviteNotification.php [moved from app/Notifications/UserInvite.php with 85% similarity]
app/Access/UserInviteService.php
app/Activity/Notifications/Messages/BaseActivityNotification.php
app/App/MailNotification.php [moved from app/Notifications/MailNotification.php with 96% similarity]
app/Settings/MaintenanceController.php
app/Settings/TestEmailNotification.php [moved from app/Notifications/TestEmail.php with 78% similarity]
app/Users/Models/User.php
tests/Api/UsersApiTest.php
tests/Auth/RegistrationTest.php
tests/Auth/ResetPasswordTest.php
tests/Auth/UserInviteTest.php
tests/Settings/TestEmailTest.php

index 79220f996669d67a10d8979f0f50b8387d1125b9..de9ea69b882302236760a8202f62880eb77622f8 100644 (file)
@@ -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));
     }
 
     /**
similarity index 82%
rename from app/Notifications/ConfirmEmail.php
rename to app/Access/Notifications/ConfirmEmailNotification.php
index 6b395e137f075490b4073505c95c4be69ffad92f..c67e1cf62839f49680d4da1e7dc20f84b66d0b2e 100644 (file)
@@ -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
similarity index 81%
rename from app/Notifications/ResetPassword.php
rename to app/Access/Notifications/ResetPasswordNotification.php
index 2d7e9c361332f38329b83aa9adb788a500946653..0a0f4ceb783da7d71a1926fd8fedfa7066edc86c 100644 (file)
@@ -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
similarity index 85%
rename from app/Notifications/UserInvite.php
rename to app/Access/Notifications/UserInviteNotification.php
index 87ea31c04b2b1b19ad37ae282572c8c4d28c1ca8..b453fc95da29a120c746bb1e843c7a11b124221b 100644 (file)
@@ -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
index 00e361e827fe973398c77d99548eb32ad7900663..7d955f3851d763c199a0073f05c2d4a3e1366ef7 100644 (file)
@@ -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));
     }
 }
index a2045c8dcd4e7117fc32dcf4026538276ac63aec..414859091f12f86a3ef17212d65e02c146e02b59 100644 (file)
@@ -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;
 
similarity index 96%
rename from app/Notifications/MailNotification.php
rename to app/App/MailNotification.php
index 1f40219f9201790a3e914007c352130e7a9509b2..8c57b5621f1987e04cd4782c6018d9bb73ac8505 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace BookStack\Notifications;
+namespace BookStack\App;
 
 use BookStack\Users\Models\User;
 use Illuminate\Bus\Queueable;
index 9c48a432326c13bfcc46f1faf92158ebcb5de174..60e5fee283ffee34f9e968c2cd6cf15b9552e425 100644 (file)
@@ -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();
similarity index 78%
rename from app/Notifications/TestEmail.php
rename to app/Settings/TestEmailNotification.php
index af9e5847f1f04b3118e363262678de3eeed151dc..3b13543e4246cad02f10e5500066f07d6db9cc16 100644 (file)
@@ -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
     {
index e3d856a8d9964aa1c3ac3db5dbb0e385c1bed700..92701ac1312c89357c0cea0f07c9051f6ed0e493 100644 (file)
@@ -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));
     }
 
     /**
index e2a04b528ee43cac66dec437b28b8b5e046df569..6ad7272577bd3adfd8bb73056427c9fc8a7cafb7 100644 (file)
@@ -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()
index bc190afd81f6a6dbfb2b50af92ef5b599c1feecc..ff1a9d66b11b8ad942490189ffe9b61dfde9e992 100644 (file)
@@ -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;
         });
 
index b97a2f2d380fb3b1b72eb69dbaa76b6f3767d621..e60ac5643ac6e9a8d403c5839f011c797f8cb93c 100644 (file)
@@ -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.');
     }
 }
index 8d6143877d3529d9532df40586c61f6c5c0b7380..a9dee0007f5870e25a6cc65391d3f8eeb02347ac 100644 (file)
@@ -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);
 
index 322f90107ddb67d8e3a29c4d2075f5f71269423e..e96024e7b74fb1e4f13038336ee6864986001bf1 100644 (file)
@@ -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);
     }
 }