fix: unpublish episode before deleting it + add validation step before deletion

fixes #112, closes #55
This commit is contained in:
Yassine Doghri 2021-10-01 10:59:44 +00:00
parent b9db936461
commit f75bd76458
9 changed files with 114 additions and 5 deletions

View File

@ -30,7 +30,7 @@ class Checkbox extends FormComponent
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');
return <<<HTML
<label class="leading-8">
<label class="leading-8 {$this->class}">
{$checkboxInput}
<span class="ml-2">{$this->slot}{$hint}</label>
</label>

View File

@ -272,6 +272,14 @@ $routes->group(
'permission:podcast_episodes-delete',
],
);
$routes->post(
'delete',
'EpisodeController::attemptDelete/$1/$2',
[
'filter' =>
'permission:podcast_episodes-delete',
],
);
$routes->get(
'transcript-delete',
'EpisodeController::transcriptDelete/$1/$2',

View File

@ -684,9 +684,63 @@ class EpisodeController extends BaseController
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
}
public function delete(): RedirectResponse
public function delete(): string
{
(new EpisodeModel())->delete($this->episode->id);
helper(['form']);
$data = [
'podcast' => $this->podcast,
'episode' => $this->episode,
];
replace_breadcrumb_params([
0 => $this->podcast->title,
1 => $this->episode->title,
]);
return view('episode/delete', $data);
}
public function attemptDelete(): RedirectResponse
{
$rules = [
'understand' => 'required',
];
if (! $this->validate($rules)) {
return redirect()
->back()
->withInput()
->with('errors', $this->validator->getErrors());
}
$db = db_connect();
$db->transStart();
$allPostsLinkedToEpisode = (new PostModel())
->where([
'episode_id' => $this->episode->id,
])
->findAll();
foreach ($allPostsLinkedToEpisode as $post) {
(new PostModel())->removePost($post);
}
// set episode published_at to null to unpublish before deletion
$this->episode->published_at = null;
$episodeModel = new EpisodeModel();
if (! $episodeModel->update($this->episode->id, $this->episode)) {
$db->transRollback();
return redirect()
->back()
->withInput()
->with('errors', $episodeModel->errors());
}
$episodeModel->delete($this->episode->id);
$db->transComplete();
return redirect()->route('episode-list', [$this->podcast->id]);
}

View File

@ -23,6 +23,7 @@ return [
'publish' => 'publish',
'publish-edit' => 'edit publication',
'unpublish' => 'unpublish',
'delete' => 'delete',
'fediverse' => 'fediverse',
'block-lists' => 'block lists',
'users' => 'users',

View File

@ -137,10 +137,16 @@ return [
],
'unpublish_form' => [
'disclaimer' =>
"Unpublishing the episode will delete all the notes associated with the episode and remove it from the podcast's RSS feed.",
"Unpublishing the episode will delete all the posts associated with it and remove it from the podcast's RSS feed.",
'understand' => 'I understand, I want to unpublish the episode',
'submit' => 'Unpublish',
],
'delete_form' => [
'disclaimer' =>
"Deleting the episode will delete all the posts associated with it and remove it from the podcast's RSS feed.",
'understand' => 'I understand, I want to delete the episode',
'submit' => 'Delete',
],
'soundbites' => 'Soundbites',
'soundbites_form' => [
'title' => 'Edit soundbites',

View File

@ -23,6 +23,7 @@ return [
'publish' => 'publier',
'publish-edit' => 'modifier la publication',
'unpublish' => 'dépublier',
'delete' => 'supprimer',
'fediverse' => 'fédiverse',
'block-lists' => 'listes de blocage',
'users' => 'utilisateurs',

View File

@ -141,6 +141,18 @@ return [
'message_warning_hint' => 'Ajouter un message augmente lengagement social, menant à une meilleure visibilité pour votre épisode.',
'message_warning_submit' => 'Publish quand même',
],
'unpublish_form' => [
'disclaimer' =>
'Dépublier lépisode supprimera toutes les publications qui lui sont associées et le retirera du flux RSS du podcast.',
'understand' => 'Je comprends, je veux dépublier lépisode',
'submit' => 'Dépublier',
],
'delete_form' => [
'disclaimer' =>
'Supprimer lépisode supprimera toutes les publications qui lui sont associées et le retirera du flux RSS du podcast.',
'understand' => 'Je comprends, Je veux supprimer lépisode',
'submit' => 'Supprimer',
],
'soundbites' => 'Extraits sonores',
'soundbites_form' => [
'title' => 'Modifier les extraits sonores',

View File

@ -0,0 +1,27 @@
<?= $this->extend('_layout') ?>
<?= $this->section('title') ?>
<?= lang('Episode.delete') ?>
<?= $this->endSection() ?>
<?= $this->section('pageTitle') ?>
<?= lang('Episode.delete') ?>
<?= $this->endSection() ?>
<?= $this->section('content') ?>
<form action="<?= route_to('episode-delete', $podcast->id, $episode->id) ?>" method="POST" class="flex flex-col max-w-xl mx-auto">
<?= csrf_field() ?>
<Alert variant="danger" glyph="alert" class="font-semibold"><?= lang('Episode.delete_form.disclaimer') ?></Alert>
<Forms.Checkbox class="mt-2" name="understand" required="true" isChecked="false"><?= lang('Episode.delete_form.understand') ?></Forms.Checkbox>
<div class="self-end mt-4">
<Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button>
<Button type="submit" variant="danger"><?= lang('Episode.delete_form.submit') ?></Button>
</div>
</form>
<?= $this->endSection() ?>

View File

@ -15,7 +15,7 @@
<Alert variant="danger" glyph="alert" class="font-semibold"><?= lang('Episode.unpublish_form.disclaimer') ?></Alert>
<Forms.Checkbox name="understand" required="true" isChecked="false"><?= lang('Episode.unpublish_form.understand') ?></Forms.Checkbox>
<Forms.Checkbox class="mt-2" name="understand" required="true" isChecked="false"><?= lang('Episode.unpublish_form.understand') ?></Forms.Checkbox>
<div class="self-end mt-4">
<Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button>