Fix: Delete local addresses when deleting maildispatcher
This commit is contained in:
parent
c2016af587
commit
48d9d9cc92
|
@ -17,7 +17,6 @@ class CreateAction
|
|||
session()->put('title', 'Mail-Verteiler erstellen');
|
||||
|
||||
return Inertia::render('maildispatcher/MaildispatcherForm', [
|
||||
'mode' => 'create',
|
||||
'meta' => MaildispatcherResource::meta(),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Maildispatcher\Actions;
|
||||
|
||||
use App\Maildispatcher\Models\Maildispatcher;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class DestroyAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Maildispatcher $maildispatcher): void
|
||||
{
|
||||
$maildispatcher->delete();
|
||||
}
|
||||
|
||||
public function asController(Maildispatcher $maildispatcher): RedirectResponse
|
||||
{
|
||||
$this->handle($maildispatcher);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Maildispatcher\Actions;
|
||||
|
||||
use App\Maildispatcher\Models\Maildispatcher;
|
||||
use App\Maildispatcher\Resources\MaildispatcherResource;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class EditAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function asController(Maildispatcher $maildispatcher): Response
|
||||
{
|
||||
session()->put('menu', 'maildispatcher');
|
||||
session()->put('title', 'Mail-Verteiler bearbeiten');
|
||||
|
||||
return Inertia::render('maildispatcher/MaildispatcherForm', [
|
||||
'data' => new MaildispatcherResource($maildispatcher),
|
||||
'meta' => MaildispatcherResource::meta(),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Maildispatcher\Actions;
|
||||
|
||||
use App\Maildispatcher\Models\Maildispatcher;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
||||
class UpdateAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
*/
|
||||
public function handle(Maildispatcher $maildispatcher, array $input): void
|
||||
{
|
||||
$maildispatcher->update([
|
||||
...$input,
|
||||
'filter' => (object) $input['filter'],
|
||||
]);
|
||||
ResyncAction::dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getValidationAttributes(): array
|
||||
{
|
||||
return [
|
||||
'gateway_id' => 'Verbindung',
|
||||
];
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'gateway_id' => 'required|exists:mailgateways,id',
|
||||
'name' => 'required|max:50',
|
||||
'filter' => 'present|array',
|
||||
];
|
||||
}
|
||||
|
||||
public function asController(Maildispatcher $maildispatcher, ActionRequest $request): JsonResponse
|
||||
{
|
||||
$this->handle($maildispatcher, $request->validated());
|
||||
|
||||
return response()->json('', 201);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,15 @@ class Maildispatcher extends Model
|
|||
'filter' => 'json',
|
||||
];
|
||||
|
||||
public static function booted(): void
|
||||
{
|
||||
static::deleting(function ($dispatcher) {
|
||||
foreach ($dispatcher->gateway->type->list($dispatcher->name, $dispatcher->gateway->domain) as $email) {
|
||||
$dispatcher->gateway->type->remove($dispatcher->name, $dispatcher->gateway->domain, $email->email);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function gateway(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Mailgateway::class);
|
||||
|
|
|
@ -25,6 +25,14 @@ class MaildispatcherResource extends JsonResource
|
|||
return [
|
||||
'name' => $this->name,
|
||||
'gateway' => new MailgatewayResource($this->whenLoaded('gateway')),
|
||||
'gateway_id' => $this->gateway_id,
|
||||
'filter' => $this->filter,
|
||||
'id' => $this->id,
|
||||
'links' => [
|
||||
'edit' => route('maildispatcher.edit', ['maildispatcher' => $this->getModel()]),
|
||||
'update' => route('maildispatcher.update', ['maildispatcher' => $this->getModel()]),
|
||||
'delete' => route('maildispatcher.destroy', ['maildispatcher' => $this->getModel()]),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class MailmanService
|
|||
{
|
||||
$response = $this->http()->delete("members/{$member->memberId}");
|
||||
|
||||
throw_unless($response->ok(), MailmanServiceException::class, 'Removing member failed');
|
||||
throw_unless($response->status(204), MailmanServiceException::class, 'Removing member failed');
|
||||
}
|
||||
|
||||
private function http(): PendingRequest
|
||||
|
|
|
@ -27,7 +27,7 @@ class FilterScope extends Filter
|
|||
public ?string $billKind = null,
|
||||
public array $activityIds = [],
|
||||
public array $subactivityIds = [],
|
||||
public string $search = '',
|
||||
public ?string $search = '',
|
||||
public array $groupIds = [],
|
||||
public array $additional = [],
|
||||
) {
|
||||
|
|
|
@ -84,14 +84,13 @@ export default {
|
|||
|
||||
data: function () {
|
||||
return {
|
||||
model: this.mode === 'create' ? {...this.meta.default_model} : {...this.data},
|
||||
model: this.data === undefined ? {...this.meta.default_model} : {...this.data},
|
||||
members: null,
|
||||
};
|
||||
},
|
||||
|
||||
props: {
|
||||
data: {},
|
||||
mode: {},
|
||||
meta: {},
|
||||
},
|
||||
|
||||
|
@ -107,7 +106,7 @@ export default {
|
|||
|
||||
async submit() {
|
||||
try {
|
||||
await this.axios.post('/maildispatcher', this.model);
|
||||
this.model.id ? await this.axios.patch(this.model.links.update, this.model) : await this.axios.post('/maildispatcher', this.model);
|
||||
this.$inertia.visit(this.meta.links.index);
|
||||
} catch (e) {
|
||||
this.errorsFromException(e);
|
||||
|
|
|
@ -3,11 +3,20 @@
|
|||
<template #toolbar>
|
||||
<page-toolbar-button :href="data.meta.links.create" color="primary" icon="plus">Verteiler erstellen</page-toolbar-button>
|
||||
</template>
|
||||
<ui-popup heading="Verteiler löschen?" v-if="deleting !== null" @close="deleting.reject()">
|
||||
<div>
|
||||
<p class="mt-4">Den Verteiler "{{ deleting.dispatcher.name }}" löschen?</p>
|
||||
<div class="grid grid-cols-2 gap-3 mt-6">
|
||||
<a href="#" @click.prevent="deleting.resolve()" class="text-center btn btn-danger">Löschen</a>
|
||||
<a href="#" @click.prevent="deleting.reject()" class="text-center btn btn-primary">Abbrechen</a>
|
||||
</div>
|
||||
</div>
|
||||
</ui-popup>
|
||||
<table cellspacing="0" cellpadding="0" border="0" class="custom-table custom-table-sm">
|
||||
<thead>
|
||||
<th>Name</th>
|
||||
<th>Interner Beitrag</th>
|
||||
<th>Nami-Beitrag</th>
|
||||
<th>Domain</th>
|
||||
<th>Verbindung</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
|
||||
|
@ -16,13 +25,14 @@
|
|||
<div v-text="dispatcher.name"></div>
|
||||
</td>
|
||||
<td>
|
||||
<div v-text="dispatcher.amount_human"></div>
|
||||
<div v-text="dispatcher.gateway.domain"></div>
|
||||
</td>
|
||||
<td>
|
||||
<div v-text="dispatcher.fee_name"></div>
|
||||
<div v-text="dispatcher.gateway.name"></div>
|
||||
</td>
|
||||
<td>
|
||||
<i-link :href="`/dispatcher/${dispatcher.id}/edit`" class="inline-flex btn btn-warning btn-sm"><svg-sprite src="pencil"></svg-sprite></i-link>
|
||||
<i-link :href="dispatcher.links.edit" class="mr-1 inline-flex btn btn-warning btn-sm"><svg-sprite src="pencil"></svg-sprite></i-link>
|
||||
<i-link @click.prevent="remove(dispatcher)" class="inline-flex btn btn-danger btn-sm"><svg-sprite src="trash"></svg-sprite></i-link>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -31,6 +41,25 @@
|
|||
|
||||
<script>
|
||||
export default {
|
||||
data: function () {
|
||||
return {
|
||||
deleting: null,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async remove(dispatcher) {
|
||||
new Promise((resolve, reject) => {
|
||||
this.deleting = {resolve, reject, dispatcher};
|
||||
})
|
||||
.then(() => {
|
||||
this.$inertia.delete(dispatcher.links.delete);
|
||||
this.deleting = null;
|
||||
})
|
||||
.catch(() => {
|
||||
this.deleting = null;
|
||||
});
|
||||
},
|
||||
},
|
||||
props: {
|
||||
data: {},
|
||||
},
|
||||
|
|
|
@ -21,8 +21,11 @@ use App\Initialize\Actions\NamiGetSearchLayerAction;
|
|||
use App\Initialize\Actions\NamiLoginCheckAction;
|
||||
use App\Initialize\Actions\NamiSearchAction;
|
||||
use App\Maildispatcher\Actions\CreateAction;
|
||||
use App\Maildispatcher\Actions\DestroyAction;
|
||||
use App\Maildispatcher\Actions\EditAction;
|
||||
use App\Maildispatcher\Actions\IndexAction;
|
||||
use App\Maildispatcher\Actions\StoreAction as MaildispatcherStoreAction;
|
||||
use App\Maildispatcher\Actions\UpdateAction as MaildispatcherUpdateAction;
|
||||
use App\Mailgateway\Actions\StoreAction;
|
||||
use App\Mailgateway\Actions\UpdateAction;
|
||||
use App\Member\Actions\ExportAction;
|
||||
|
@ -89,5 +92,8 @@ Route::group(['middleware' => 'auth:web'], function (): void {
|
|||
Route::patch('/api/mailgateway/{mailgateway}', UpdateAction::class)->name('mailgateway.update');
|
||||
Route::get('/maildispatcher', IndexAction::class)->name('maildispatcher.index');
|
||||
Route::get('/maildispatcher/create', CreateAction::class)->name('maildispatcher.create');
|
||||
Route::get('/maildispatcher/{maildispatcher}', EditAction::class)->name('maildispatcher.edit');
|
||||
Route::patch('/maildispatcher/{maildispatcher}', MaildispatcherUpdateAction::class)->name('maildispatcher.update');
|
||||
Route::post('/maildispatcher', MaildispatcherStoreAction::class)->name('maildispatcher.store');
|
||||
Route::delete('/maildispatcher/{maildispatcher}', DestroyAction::class)->name('maildispatcher.destroy');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue