Fix: Do not store maildispatcher members with same email address multiple times
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
philipp lang 2023-10-11 23:13:59 +02:00
parent ff245397d5
commit a26f064698
2 changed files with 22 additions and 1 deletions

View File

@ -27,6 +27,9 @@ class ResyncAction
{
return Member::search(data_get($dispatcher->filter, 'search', ''))->query(
fn ($q) => $q->select('*')->withFilter(FilterScope::fromPost($dispatcher->filter))
)->get()->filter(fn ($member) => $member->email || $member->email_parents)->map(fn ($member) => MailEntry::from(['email' => $member->email ?: $member->email_parents]));
)->get()
->filter(fn ($member) => $member->email || $member->email_parents)
->map(fn ($member) => MailEntry::from(['email' => $member->email ?: $member->email_parents]))
->unique(fn ($member) => $member->email);
}
}

View File

@ -2,6 +2,7 @@
namespace Tests\Feature\Maildispatcher;
use \Mockery as M;
use App\Activity;
use App\Maildispatcher\Models\Localmaildispatcher;
use App\Maildispatcher\Models\Maildispatcher;
@ -50,6 +51,23 @@ class StoreTest extends TestCase
]);
}
public function testItDoesntStoreTwoMembersWithSameEmailAddress(): void
{
$type = M::mock(LocalType::class)->makePartial();
$type->shouldReceive('add')->once();
app()->instance(LocalType::class, $type);
$gateway = Mailgateway::factory()->type(LocalType::class, [])->domain('example.com')->create();
Member::factory()->defaults()->create(['email' => 'jane@example.com']);
Member::factory()->defaults()->create(['email' => 'jane@example.com']);
$this->postJson('/maildispatcher', [
'name' => 'test',
'gateway_id' => $gateway->id,
'filter' => [],
]);
}
public function testMaildispatcherReceivesLowerVersionOfEmail(): void
{
$gateway = Mailgateway::factory()->type(LocalType::class, [])->create();