mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-30 07:32:39 +01:00
Notifications: Reorgranised classes into domain specific folders
Closes #4500
This commit is contained in:
parent
18f396c21b
commit
8e3f8de627
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace BookStack\Access;
|
namespace BookStack\Access;
|
||||||
|
|
||||||
|
use BookStack\Access\Notifications\ConfirmEmailNotification;
|
||||||
use BookStack\Exceptions\ConfirmationEmailException;
|
use BookStack\Exceptions\ConfirmationEmailException;
|
||||||
use BookStack\Notifications\ConfirmEmail;
|
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
|
|
||||||
class EmailConfirmationService extends UserTokenService
|
class EmailConfirmationService extends UserTokenService
|
||||||
@ -26,7 +26,7 @@ class EmailConfirmationService extends UserTokenService
|
|||||||
$this->deleteByUser($user);
|
$this->deleteByUser($user);
|
||||||
$token = $this->createTokenForUser($user);
|
$token = $this->createTokenForUser($user);
|
||||||
|
|
||||||
$user->notify(new ConfirmEmail($token));
|
$user->notify(new ConfirmEmailNotification($token));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BookStack\Notifications;
|
namespace BookStack\Access\Notifications;
|
||||||
|
|
||||||
|
use BookStack\App\MailNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
|
||||||
class ConfirmEmail extends MailNotification
|
class ConfirmEmailNotification extends MailNotification
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $token
|
public string $token
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BookStack\Notifications;
|
namespace BookStack\Access\Notifications;
|
||||||
|
|
||||||
|
use BookStack\App\MailNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
|
||||||
class ResetPassword extends MailNotification
|
class ResetPasswordNotification extends MailNotification
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $token
|
public string $token
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BookStack\Notifications;
|
namespace BookStack\Access\Notifications;
|
||||||
|
|
||||||
|
use BookStack\App\MailNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
|
||||||
class UserInvite extends MailNotification
|
class UserInviteNotification extends MailNotification
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $token
|
public string $token
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace BookStack\Access;
|
namespace BookStack\Access;
|
||||||
|
|
||||||
use BookStack\Notifications\UserInvite;
|
use BookStack\Access\Notifications\UserInviteNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
|
|
||||||
class UserInviteService extends UserTokenService
|
class UserInviteService extends UserTokenService
|
||||||
@ -18,6 +18,6 @@ class UserInviteService extends UserTokenService
|
|||||||
{
|
{
|
||||||
$this->deleteByUser($user);
|
$this->deleteByUser($user);
|
||||||
$token = $this->createTokenForUser($user);
|
$token = $this->createTokenForUser($user);
|
||||||
$user->notify(new UserInvite($token));
|
$user->notify(new UserInviteNotification($token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace BookStack\Activity\Notifications\Messages;
|
|||||||
|
|
||||||
use BookStack\Activity\Models\Loggable;
|
use BookStack\Activity\Models\Loggable;
|
||||||
use BookStack\Activity\Notifications\MessageParts\LinkedMailMessageLine;
|
use BookStack\Activity\Notifications\MessageParts\LinkedMailMessageLine;
|
||||||
use BookStack\Notifications\MailNotification;
|
use BookStack\App\MailNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BookStack\Notifications;
|
namespace BookStack\App;
|
||||||
|
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
@ -5,7 +5,6 @@ namespace BookStack\Settings;
|
|||||||
use BookStack\Activity\ActivityType;
|
use BookStack\Activity\ActivityType;
|
||||||
use BookStack\Entities\Tools\TrashCan;
|
use BookStack\Entities\Tools\TrashCan;
|
||||||
use BookStack\Http\Controller;
|
use BookStack\Http\Controller;
|
||||||
use BookStack\Notifications\TestEmail;
|
|
||||||
use BookStack\References\ReferenceStore;
|
use BookStack\References\ReferenceStore;
|
||||||
use BookStack\Uploads\ImageService;
|
use BookStack\Uploads\ImageService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -69,7 +68,7 @@ class MaintenanceController extends Controller
|
|||||||
$this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
|
$this->logActivity(ActivityType::MAINTENANCE_ACTION_RUN, 'send-test-email');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
user()->notifyNow(new TestEmail());
|
user()->notifyNow(new TestEmailNotification());
|
||||||
$this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
|
$this->showSuccessNotification(trans('settings.maint_send_test_email_success', ['address' => user()->email]));
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
|
$errorMessage = trans('errors.maintenance_test_email_failure') . "\n" . $exception->getMessage();
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace BookStack\Notifications;
|
namespace BookStack\Settings;
|
||||||
|
|
||||||
|
use BookStack\App\MailNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
|
||||||
class TestEmail extends MailNotification
|
class TestEmailNotification extends MailNotification
|
||||||
{
|
{
|
||||||
public function toMail(User $notifiable): MailMessage
|
public function toMail(User $notifiable): MailMessage
|
||||||
{
|
{
|
@ -3,6 +3,7 @@
|
|||||||
namespace BookStack\Users\Models;
|
namespace BookStack\Users\Models;
|
||||||
|
|
||||||
use BookStack\Access\Mfa\MfaValue;
|
use BookStack\Access\Mfa\MfaValue;
|
||||||
|
use BookStack\Access\Notifications\ResetPasswordNotification;
|
||||||
use BookStack\Access\SocialAccount;
|
use BookStack\Access\SocialAccount;
|
||||||
use BookStack\Activity\Models\Favourite;
|
use BookStack\Activity\Models\Favourite;
|
||||||
use BookStack\Activity\Models\Loggable;
|
use BookStack\Activity\Models\Loggable;
|
||||||
@ -11,7 +12,6 @@ use BookStack\Api\ApiToken;
|
|||||||
use BookStack\App\Model;
|
use BookStack\App\Model;
|
||||||
use BookStack\App\Sluggable;
|
use BookStack\App\Sluggable;
|
||||||
use BookStack\Entities\Tools\SlugGenerator;
|
use BookStack\Entities\Tools\SlugGenerator;
|
||||||
use BookStack\Notifications\ResetPassword;
|
|
||||||
use BookStack\Translation\LanguageManager;
|
use BookStack\Translation\LanguageManager;
|
||||||
use BookStack\Uploads\Image;
|
use BookStack\Uploads\Image;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@ -365,7 +365,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
|||||||
*/
|
*/
|
||||||
public function sendPasswordResetNotification($token)
|
public function sendPasswordResetNotification($token)
|
||||||
{
|
{
|
||||||
$this->notify(new ResetPassword($token));
|
$this->notify(new ResetPasswordNotification($token));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Api;
|
namespace Tests\Api;
|
||||||
|
|
||||||
|
use BookStack\Access\Notifications\UserInviteNotification;
|
||||||
use BookStack\Activity\ActivityType;
|
use BookStack\Activity\ActivityType;
|
||||||
use BookStack\Activity\Models\Activity as ActivityModel;
|
use BookStack\Activity\Models\Activity as ActivityModel;
|
||||||
use BookStack\Entities\Models\Entity;
|
use BookStack\Entities\Models\Entity;
|
||||||
use BookStack\Facades\Activity;
|
use BookStack\Facades\Activity;
|
||||||
use BookStack\Notifications\UserInvite;
|
|
||||||
use BookStack\Users\Models\Role;
|
use BookStack\Users\Models\Role;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
@ -140,7 +140,7 @@ class UsersApiTest extends TestCase
|
|||||||
$resp->assertStatus(200);
|
$resp->assertStatus(200);
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = User::query()->where('email', '=', 'bboris@example.com')->first();
|
$user = User::query()->where('email', '=', 'bboris@example.com')->first();
|
||||||
Notification::assertSentTo($user, UserInvite::class);
|
Notification::assertSentTo($user, UserInviteNotification::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_create_name_and_email_validation()
|
public function test_create_name_and_email_validation()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\Auth;
|
namespace Tests\Auth;
|
||||||
|
|
||||||
use BookStack\Notifications\ConfirmEmail;
|
use BookStack\Access\Notifications\ConfirmEmailNotification;
|
||||||
use BookStack\Users\Models\Role;
|
use BookStack\Users\Models\Role;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -28,7 +28,7 @@ class RegistrationTest extends TestCase
|
|||||||
// Ensure notification sent
|
// Ensure notification sent
|
||||||
/** @var User $dbUser */
|
/** @var User $dbUser */
|
||||||
$dbUser = User::query()->where('email', '=', $user->email)->first();
|
$dbUser = User::query()->where('email', '=', $user->email)->first();
|
||||||
Notification::assertSentTo($dbUser, ConfirmEmail::class);
|
Notification::assertSentTo($dbUser, ConfirmEmailNotification::class);
|
||||||
|
|
||||||
// Test access and resend confirmation email
|
// Test access and resend confirmation email
|
||||||
$resp = $this->post('/login', ['email' => $user->email, 'password' => $user->password]);
|
$resp = $this->post('/login', ['email' => $user->email, 'password' => $user->password]);
|
||||||
@ -42,7 +42,7 @@ class RegistrationTest extends TestCase
|
|||||||
|
|
||||||
// Get confirmation and confirm notification matches
|
// Get confirmation and confirm notification matches
|
||||||
$emailConfirmation = DB::table('email_confirmations')->where('user_id', '=', $dbUser->id)->first();
|
$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;
|
return $notification->token === $emailConfirmation->token;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\Auth;
|
namespace Tests\Auth;
|
||||||
|
|
||||||
use BookStack\Notifications\ResetPassword;
|
use BookStack\Access\Notifications\ResetPasswordNotification;
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@ -34,8 +34,8 @@ class ResetPasswordTest extends TestCase
|
|||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = User::query()->where('email', '=', 'admin@admin.com')->first();
|
$user = User::query()->where('email', '=', 'admin@admin.com')->first();
|
||||||
|
|
||||||
Notification::assertSentTo($user, ResetPassword::class);
|
Notification::assertSentTo($user, ResetPasswordNotification::class);
|
||||||
$n = Notification::sent($user, ResetPassword::class);
|
$n = Notification::sent($user, ResetPasswordNotification::class);
|
||||||
|
|
||||||
$this->get('/password/reset/' . $n->first()->token)
|
$this->get('/password/reset/' . $n->first()->token)
|
||||||
->assertOk()
|
->assertOk()
|
||||||
@ -95,7 +95,7 @@ class ResetPasswordTest extends TestCase
|
|||||||
$resp = $this->followingRedirects()->post('/password/email', [
|
$resp = $this->followingRedirects()->post('/password/email', [
|
||||||
'email' => $editor->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.');
|
$resp->assertSee('A password reset link will be sent to ' . $editor->email . ' if that email address is found in the system.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace Tests\Auth;
|
namespace Tests\Auth;
|
||||||
|
|
||||||
|
use BookStack\Access\Notifications\UserInviteNotification;
|
||||||
use BookStack\Access\UserInviteService;
|
use BookStack\Access\UserInviteService;
|
||||||
use BookStack\Notifications\UserInvite;
|
|
||||||
use BookStack\Users\Models\User;
|
use BookStack\Users\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
@ -29,7 +29,7 @@ class UserInviteTest extends TestCase
|
|||||||
|
|
||||||
$newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
|
$newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
|
||||||
|
|
||||||
Notification::assertSentTo($newUser, UserInvite::class);
|
Notification::assertSentTo($newUser, UserInviteNotification::class);
|
||||||
$this->assertDatabaseHas('user_invites', [
|
$this->assertDatabaseHas('user_invites', [
|
||||||
'user_id' => $newUser->id,
|
'user_id' => $newUser->id,
|
||||||
]);
|
]);
|
||||||
@ -50,7 +50,7 @@ class UserInviteTest extends TestCase
|
|||||||
$resp->assertRedirect('/settings/users');
|
$resp->assertRedirect('/settings/users');
|
||||||
|
|
||||||
$newUser = User::query()->where('email', '=', $email)->orderBy('id', 'desc')->first();
|
$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 */
|
/** @var MailMessage $mail */
|
||||||
$mail = $notification->toMail($notifiable);
|
$mail = $notification->toMail($notifiable);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\Settings;
|
namespace Tests\Settings;
|
||||||
|
|
||||||
use BookStack\Notifications\TestEmail;
|
use BookStack\Settings\TestEmailNotification;
|
||||||
use Illuminate\Contracts\Notifications\Dispatcher;
|
use Illuminate\Contracts\Notifications\Dispatcher;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@ -26,7 +26,7 @@ class TestEmailTest extends TestCase
|
|||||||
$sendReq->assertRedirect('/settings/maintenance#image-cleanup');
|
$sendReq->assertRedirect('/settings/maintenance#image-cleanup');
|
||||||
$this->assertSessionHas('success', 'Email sent to ' . $admin->email);
|
$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()
|
public function test_send_test_email_failure_displays_error_notification()
|
||||||
@ -57,6 +57,6 @@ class TestEmailTest extends TestCase
|
|||||||
|
|
||||||
$this->permissions->grantUserRolePermissions($user, ['settings-manage']);
|
$this->permissions->grantUserRolePermissions($user, ['settings-manage']);
|
||||||
$sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
|
$sendReq = $this->actingAs($user)->post('/settings/maintenance/send-test-email');
|
||||||
Notification::assertSentTo($user, TestEmail::class);
|
Notification::assertSentTo($user, TestEmailNotification::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user