Compare commits

..

No commits in common. "7bffa6c5ae46ca13666fb5bbb0b8e6aea17511f7" and "59920bac1d3a4f417734eed1139074de2ed408b0" have entirely different histories.

5 changed files with 17 additions and 43 deletions

View File

@ -10,9 +10,4 @@ class MailEntry extends Data
{
$this->email = strtolower($email);
}
public function is(self $mailEntry): bool
{
return $this->email === $mailEntry->email;
}
}

View File

@ -3,7 +3,6 @@
namespace App\Mailgateway\Types;
use App\Maildispatcher\Data\MailEntry;
use App\Mailman\Data\MailingList;
use App\Mailman\Exceptions\MailmanServiceException;
use App\Mailman\Support\MailmanService;
use Illuminate\Support\Collection;
@ -68,7 +67,8 @@ class MailmanType extends Type
public function search(string $name, string $domain, string $email): ?MailEntry
{
$list = $this->getList($name, $domain);
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
$member = $this->service()->members($list)->first(fn ($member) => $member->email === $email);
return $member ? MailEntry::from(['email' => $member->email]) : null;
@ -76,7 +76,8 @@ class MailmanType extends Type
public function add(string $name, string $domain, string $email): void
{
$list = $this->getList($name, $domain);
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
$this->service()->addMember($list, $email);
}
@ -85,27 +86,21 @@ class MailmanType extends Type
*/
public function list(string $name, string $domain): Collection
{
$list = $this->getList($name, $domain);
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
return collect($this->service()->members($list)->map(fn ($member) => MailEntry::from(['email' => $member->email]))->all());
}
public function remove(string $name, string $domain, string $email): void
{
$list = $this->getList($name, $domain);
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
$member = $this->service()->members($list)->first(fn ($member) => $member->email === $email);
throw_if(!$member, MailmanServiceException::class, 'Member for removing not found');
$this->service()->removeMember($member);
}
private function getList(string $name, string $domain): MailingList
{
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
return $list;
}
private function service(): MailmanService
{
return app(MailmanService::class)->setCredentials($this->url, $this->user, $this->password);

View File

@ -79,9 +79,8 @@ abstract class Type
*/
public function sync(string $name, string $domain, Collection $results): void
{
$members = $this->list($name, $domain);
foreach ($results as $result) {
if ($members->first(fn ($member) => $member->is($result))) {
if ($this->search($name, $domain, $result->email)) {
continue;
}
@ -89,7 +88,7 @@ abstract class Type
}
$this->list($name, $domain)
->filter(fn ($listEntry) => $results->doesntContain(fn ($r) => $r->is($listEntry)))
->filter(fn ($listEntry) => null === $results->first(fn ($r) => $r->email === $listEntry->email))
->each(fn ($listEntry) => $this->remove($name, $domain, $listEntry->email));
}

View File

@ -20,8 +20,7 @@ class FilterScope extends Filter
* @param array<int, int> $activityIds
* @param array<int, int> $subactivityIds
* @param array<int, int> $groupIds
* @param array<int, int> $include
* @param array<int, int> $exclude
* @param array<int, int> $additional
*/
public function __construct(
public bool $ausstand = false,
@ -30,8 +29,7 @@ class FilterScope extends Filter
public array $subactivityIds = [],
public ?string $search = '',
public array $groupIds = [],
public array $include = [],
public array $exclude = [],
public array $additional = [],
) {
}
@ -75,13 +73,9 @@ class FilterScope extends Filter
}
});
}
if (count($this->exclude)) {
$query->whereNotIn('id', $this->exclude);
}
})->orWhere(function ($query) {
if (count($this->include)) {
$query->whereIn('id', $this->include);
if (count($this->additional)) {
$query->whereIn('id', $this->additional);
}
});
});

View File

@ -34,23 +34,14 @@
size="sm"
></f-multipleselect>
<f-multipleselect
id="include"
name="include"
id="additional"
name="additional"
:options="members.meta.members"
v-model="model.filter.include"
v-model="model.filter.additional"
@update:modelValue="reload(1)"
label="Zusätzliche Mitglieder"
size="sm"
></f-multipleselect>
<f-multipleselect
id="exclude"
name="exclude"
:options="members.meta.members"
v-model="model.filter.exclude"
@update:modelValue="reload(1)"
label="Mitglieder ausschließen"
size="sm"
></f-multipleselect>
<f-multipleselect
id="groupIds"
name="groupIds"