Compare commits
3 Commits
59920bac1d
...
7bffa6c5ae
Author | SHA1 | Date |
---|---|---|
|
7bffa6c5ae | |
|
139c7623ab | |
|
1038f26171 |
|
@ -10,4 +10,9 @@ class MailEntry extends Data
|
||||||
{
|
{
|
||||||
$this->email = strtolower($email);
|
$this->email = strtolower($email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function is(self $mailEntry): bool
|
||||||
|
{
|
||||||
|
return $this->email === $mailEntry->email;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Mailgateway\Types;
|
namespace App\Mailgateway\Types;
|
||||||
|
|
||||||
use App\Maildispatcher\Data\MailEntry;
|
use App\Maildispatcher\Data\MailEntry;
|
||||||
|
use App\Mailman\Data\MailingList;
|
||||||
use App\Mailman\Exceptions\MailmanServiceException;
|
use App\Mailman\Exceptions\MailmanServiceException;
|
||||||
use App\Mailman\Support\MailmanService;
|
use App\Mailman\Support\MailmanService;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
@ -67,8 +68,7 @@ class MailmanType extends Type
|
||||||
|
|
||||||
public function search(string $name, string $domain, string $email): ?MailEntry
|
public function search(string $name, string $domain, string $email): ?MailEntry
|
||||||
{
|
{
|
||||||
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
|
$list = $this->getList($name, $domain);
|
||||||
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
|
|
||||||
$member = $this->service()->members($list)->first(fn ($member) => $member->email === $email);
|
$member = $this->service()->members($list)->first(fn ($member) => $member->email === $email);
|
||||||
|
|
||||||
return $member ? MailEntry::from(['email' => $member->email]) : null;
|
return $member ? MailEntry::from(['email' => $member->email]) : null;
|
||||||
|
@ -76,8 +76,7 @@ class MailmanType extends Type
|
||||||
|
|
||||||
public function add(string $name, string $domain, string $email): void
|
public function add(string $name, string $domain, string $email): void
|
||||||
{
|
{
|
||||||
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
|
$list = $this->getList($name, $domain);
|
||||||
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
|
|
||||||
$this->service()->addMember($list, $email);
|
$this->service()->addMember($list, $email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,21 +85,27 @@ class MailmanType extends Type
|
||||||
*/
|
*/
|
||||||
public function list(string $name, string $domain): Collection
|
public function list(string $name, string $domain): Collection
|
||||||
{
|
{
|
||||||
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
|
$list = $this->getList($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());
|
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
|
public function remove(string $name, string $domain, string $email): void
|
||||||
{
|
{
|
||||||
$list = $this->service()->getLists()->first(fn ($list) => $list->fqdnListname === "{$name}@{$domain}");
|
$list = $this->getList($name, $domain);
|
||||||
throw_if(!$list, MailmanServiceException::class, "List for {$name}@{$domain} not found");
|
|
||||||
$member = $this->service()->members($list)->first(fn ($member) => $member->email === $email);
|
$member = $this->service()->members($list)->first(fn ($member) => $member->email === $email);
|
||||||
throw_if(!$member, MailmanServiceException::class, 'Member for removing not found');
|
throw_if(!$member, MailmanServiceException::class, 'Member for removing not found');
|
||||||
$this->service()->removeMember($member);
|
$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
|
private function service(): MailmanService
|
||||||
{
|
{
|
||||||
return app(MailmanService::class)->setCredentials($this->url, $this->user, $this->password);
|
return app(MailmanService::class)->setCredentials($this->url, $this->user, $this->password);
|
||||||
|
|
|
@ -79,8 +79,9 @@ abstract class Type
|
||||||
*/
|
*/
|
||||||
public function sync(string $name, string $domain, Collection $results): void
|
public function sync(string $name, string $domain, Collection $results): void
|
||||||
{
|
{
|
||||||
|
$members = $this->list($name, $domain);
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
if ($this->search($name, $domain, $result->email)) {
|
if ($members->first(fn ($member) => $member->is($result))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ abstract class Type
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->list($name, $domain)
|
$this->list($name, $domain)
|
||||||
->filter(fn ($listEntry) => null === $results->first(fn ($r) => $r->email === $listEntry->email))
|
->filter(fn ($listEntry) => $results->doesntContain(fn ($r) => $r->is($listEntry)))
|
||||||
->each(fn ($listEntry) => $this->remove($name, $domain, $listEntry->email));
|
->each(fn ($listEntry) => $this->remove($name, $domain, $listEntry->email));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@ class FilterScope extends Filter
|
||||||
* @param array<int, int> $activityIds
|
* @param array<int, int> $activityIds
|
||||||
* @param array<int, int> $subactivityIds
|
* @param array<int, int> $subactivityIds
|
||||||
* @param array<int, int> $groupIds
|
* @param array<int, int> $groupIds
|
||||||
* @param array<int, int> $additional
|
* @param array<int, int> $include
|
||||||
|
* @param array<int, int> $exclude
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public bool $ausstand = false,
|
public bool $ausstand = false,
|
||||||
|
@ -29,7 +30,8 @@ class FilterScope extends Filter
|
||||||
public array $subactivityIds = [],
|
public array $subactivityIds = [],
|
||||||
public ?string $search = '',
|
public ?string $search = '',
|
||||||
public array $groupIds = [],
|
public array $groupIds = [],
|
||||||
public array $additional = [],
|
public array $include = [],
|
||||||
|
public array $exclude = [],
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,9 +75,13 @@ class FilterScope extends Filter
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (count($this->exclude)) {
|
||||||
|
$query->whereNotIn('id', $this->exclude);
|
||||||
|
}
|
||||||
})->orWhere(function ($query) {
|
})->orWhere(function ($query) {
|
||||||
if (count($this->additional)) {
|
if (count($this->include)) {
|
||||||
$query->whereIn('id', $this->additional);
|
$query->whereIn('id', $this->include);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,14 +34,23 @@
|
||||||
size="sm"
|
size="sm"
|
||||||
></f-multipleselect>
|
></f-multipleselect>
|
||||||
<f-multipleselect
|
<f-multipleselect
|
||||||
id="additional"
|
id="include"
|
||||||
name="additional"
|
name="include"
|
||||||
:options="members.meta.members"
|
:options="members.meta.members"
|
||||||
v-model="model.filter.additional"
|
v-model="model.filter.include"
|
||||||
@update:modelValue="reload(1)"
|
@update:modelValue="reload(1)"
|
||||||
label="Zusätzliche Mitglieder"
|
label="Zusätzliche Mitglieder"
|
||||||
size="sm"
|
size="sm"
|
||||||
></f-multipleselect>
|
></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
|
<f-multipleselect
|
||||||
id="groupIds"
|
id="groupIds"
|
||||||
name="groupIds"
|
name="groupIds"
|
||||||
|
|
Loading…
Reference in New Issue