Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ npm-debug.log
vagrant-credentials.rb
ubuntu-bionic-18.04-cloudimg-console.log
.phpunit.result.cache
code/public/assets/

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@

namespace App\Athenia\Contracts\Services\Messaging;

use App\Models\Messaging\Message;

interface SendEmailServiceContract extends BaseMessageSendingServiceContract
{}
{
/**
* Used when there is no to set on the message
*
* @param Message $message
* @return void
*/
public function sendDirectMessage(Message $message);
}
19 changes: 13 additions & 6 deletions code/app/Athenia/Listeners/Messaging/MessageCreatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Athenia\Contracts\Repositories\Messaging\MessageRepositoryContract;
use App\Athenia\Contracts\Services\Messaging\BaseMessageSendingServiceContract;
use App\Athenia\Contracts\Services\Messaging\MessageSendingSelectionServiceContract;
use App\Athenia\Contracts\Services\Messaging\SendEmailServiceContract;
use App\Athenia\Events\Messaging\MessageCreatedEvent;
use App\Athenia\Events\Messaging\MessageSentEvent;
use App\Models\Messaging\Message;
Expand Down Expand Up @@ -56,16 +57,22 @@ public function handle(MessageCreatedEvent $event): void
->filter(fn (?BaseMessageSendingServiceContract $maybeService) => $maybeService);
foreach ($availableServices as $service) {

$to = $message->to;
if ($to instanceof CanReceiveMessageContract) {
$service->sendMessage($to, $message);
$to = $message->to_id ? $message->to : null;
if (!$to && $message->email && $service instanceof SendEmailServiceContract) {
$service->sendDirectMessage($message);
$sent = true;
}
if ($to instanceof HasMessageReceiversContract) {
foreach ($to->messageReceivers($message) as $messageReceiver) {
$service->sendMessage($messageReceiver, $message);
else {
if ($to instanceof CanReceiveMessageContract) {
$service->sendMessage($to, $message);
$sent = true;
}
if ($to instanceof HasMessageReceiversContract) {
foreach ($to->messageReceivers($message) as $messageReceiver) {
$service->sendMessage($messageReceiver, $message);
$sent = true;
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions code/app/Athenia/Mail/MessageMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class MessageMailer extends Mailable implements ShouldQueue

/**
* NotificationMailer constructor.
* @param CanReceiveEmailsContract $receiver
* @param Message $message
* @param CanReceiveEmailsContract|null $receiver
*/
public function __construct(private CanReceiveEmailsContract $receiver, private Message $message)
public function __construct(private Message $message, private ?CanReceiveEmailsContract $receiver = null)
{
$this->chain([new MessageSentEvent($message)]);
}
Expand All @@ -37,7 +37,7 @@ public function __construct(private CanReceiveEmailsContract $receiver, private
public function build()
{
$email = $this->message->email ?? $this->receiver->getEmailAddress();
$name = $this->receiver->getEmailToName();
$name = $this->receiver?->getEmailToName();
$data = $this->message->data;
if (isset ($data['message'])) {
$data['message_content'] = $data['message'];
Expand Down
13 changes: 12 additions & 1 deletion code/app/Athenia/Services/Messaging/SendEmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ public function __construct(private Mailer $mailer) {}
public function sendMessage(CanReceiveMessageContract $receiver, Message $message): bool
{
if ($receiver instanceof CanReceiveEmailsContract && $receiver->canReceiveMessage($message)) {
$this->mailer->send(new MessageMailer($receiver, $message));
$this->mailer->send(new MessageMailer($message, $receiver));

return true;
}

return false;
}

/**
* Used when there is no to set on the message
*
* @param Message $message
* @return void
*/
public function sendDirectMessage(Message $message)
{
$this->mailer->send(new MessageMailer($message));
}
}
10 changes: 2 additions & 8 deletions code/app/Policies/Wiki/ArticlePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ class ArticlePolicy extends BasePolicyAbstract
*/
public function all(User $user)
{
return $user->hasRole([
Role::ARTICLE_VIEWER,
Role::ARTICLE_EDITOR,
]);
return true;
}

/**
Expand All @@ -37,10 +34,7 @@ public function all(User $user)
*/
public function view(User $user, Article $model)
{
return $user->hasRole([
Role::ARTICLE_VIEWER,
Role::ARTICLE_EDITOR,
]);
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions code/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

'url' => env('APP_URL', 'http://localhost'),

'asset_url' => env('ASSET_URL', 'http://dev-assets.localhost'),
'asset_url' => env('ASSET_URL', 'http://localhost:8081'),

/*
|--------------------------------------------------------------------------
Expand All @@ -67,7 +67,7 @@
|
*/

'timezone' => 'UTC',
'timezone' => env('APP_TIMEZONE', 'UTC'),

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions code/config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@

'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],

Expand Down
2 changes: 0 additions & 2 deletions code/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
colors="true"
processIsolation="false"
beStrictAboutTestsThatDoNotTestAnything="false"
stopOnFailure="true"
stopOnError="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
Expand Down
10 changes: 0 additions & 10 deletions code/tests/Athenia/Feature/Http/Article/ArticleIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ public function testNotLoggedUserBlocked(): void
$response->assertStatus(403);
}

public function testIncorrectUserRoleBlocked(): void
{
foreach ($this->rolesWithoutAdmins([Role::ARTICLE_VIEWER, Role::ARTICLE_EDITOR]) as $role ) {
$this->actAs($role);
$response = $this->json('GET', $this->path);

$response->assertStatus(403);
}
}

public function testGetPaginationEmpty(): void
{
foreach ([Role::ARTICLE_EDITOR, Role::ARTICLE_VIEWER] as $role) {
Expand Down
11 changes: 0 additions & 11 deletions code/tests/Athenia/Feature/Http/Article/ArticleViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ public function testNotLoggedInUserBlocked(): void
$response->assertStatus(403);
}

public function testIncorrectUserRoleBlocked(): void
{
foreach ($this->rolesWithoutAdmins([Role::ARTICLE_EDITOR, Role::ARTICLE_VIEWER]) as $role) {
$this->actAs($role);

$response = $this->json('GET', $this->path);

$response->assertStatus(403);
}
}

public function testNotFound(): void
{
$this->actAsUser();
Expand Down
3 changes: 3 additions & 0 deletions code/tests/Athenia/Feature/Http/Authentication/LogoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function handle($request, $next) {
}
});

$log = app('log');
$log->shouldReceive('channel')->andReturn($log);

$user = User::factory()->create();
$token = JWTAuth::fromUser($user);
$response = $this->json('POST', '/v1/auth/logout', [], ['Authorization' => 'Bearer ' . $token]);
Expand Down
35 changes: 3 additions & 32 deletions code/tests/Athenia/Integration/Policies/Wiki/ArticlePolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Tests\Athenia\Integration\Policies\Wiki;

use App\Models\Role;
use App\Models\User\User;
use App\Models\Wiki\Article;
use App\Policies\Wiki\ArticlePolicy;
use Tests\DatabaseSetupTrait;
Expand All @@ -22,44 +23,14 @@ public function testAllSuccess(): void
{
$policy = new ArticlePolicy();

foreach ([Role::ARTICLE_EDITOR, Role::ARTICLE_VIEWER] as $role) {
$user = $this->getUserOfRole($role);

$this->assertTrue($policy->all($user));
}
}

public function testAllBlocks(): void
{
$policy = new ArticlePolicy();

foreach ($this->rolesWithoutAdmins([Role::ARTICLE_EDITOR, Role::ARTICLE_VIEWER]) as $role) {
$user = $this->getUserOfRole($role);

$this->assertFalse($policy->all($user));
}
$this->assertTrue($policy->all(new User()));
}

public function testViewSuccess(): void
{
$policy = new ArticlePolicy();

foreach ([Role::ARTICLE_EDITOR, Role::ARTICLE_VIEWER] as $role) {
$user = $this->getUserOfRole($role);

$this->assertTrue($policy->view($user, new Article()));
}
}

public function testViewBlocks(): void
{
$policy = new ArticlePolicy();

foreach ($this->rolesWithoutAdmins([Role::ARTICLE_EDITOR, Role::ARTICLE_VIEWER]) as $role) {
$user = $this->getUserOfRole($role);

$this->assertFalse($policy->view($user, new Article()));
}
$this->assertTrue($policy->view(new User(), new Article()));
}

public function testCreateSuccess(): void
Expand Down
2 changes: 1 addition & 1 deletion code/tests/Athenia/Unit/Mail/MessageMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testBuild(): void
],
]);

$messageMailer = new MessageMailer($user, $message);
$messageMailer = new MessageMailer($message, $user);

$builtMailer = $messageMailer->build();

Expand Down