Skip to content
Snippets Groups Projects
Commit f75bd764 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

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

fixes #112, closes #55
parent b9db9364
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,7 @@ class Checkbox extends FormComponent ...@@ -30,7 +30,7 @@ class Checkbox extends FormComponent
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1'); $hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');
return <<<HTML return <<<HTML
<label class="leading-8"> <label class="leading-8 {$this->class}">
{$checkboxInput} {$checkboxInput}
<span class="ml-2">{$this->slot}{$hint}</label> <span class="ml-2">{$this->slot}{$hint}</label>
</label> </label>
......
...@@ -272,6 +272,14 @@ $routes->group( ...@@ -272,6 +272,14 @@ $routes->group(
'permission:podcast_episodes-delete', 'permission:podcast_episodes-delete',
], ],
); );
$routes->post(
'delete',
'EpisodeController::attemptDelete/$1/$2',
[
'filter' =>
'permission:podcast_episodes-delete',
],
);
$routes->get( $routes->get(
'transcript-delete', 'transcript-delete',
'EpisodeController::transcriptDelete/$1/$2', 'EpisodeController::transcriptDelete/$1/$2',
......
...@@ -684,9 +684,63 @@ class EpisodeController extends BaseController ...@@ -684,9 +684,63 @@ class EpisodeController extends BaseController
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]); 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]); return redirect()->route('episode-list', [$this->podcast->id]);
} }
......
...@@ -23,6 +23,7 @@ return [ ...@@ -23,6 +23,7 @@ return [
'publish' => 'publish', 'publish' => 'publish',
'publish-edit' => 'edit publication', 'publish-edit' => 'edit publication',
'unpublish' => 'unpublish', 'unpublish' => 'unpublish',
'delete' => 'delete',
'fediverse' => 'fediverse', 'fediverse' => 'fediverse',
'block-lists' => 'block lists', 'block-lists' => 'block lists',
'users' => 'users', 'users' => 'users',
......
...@@ -137,10 +137,16 @@ return [ ...@@ -137,10 +137,16 @@ return [
], ],
'unpublish_form' => [ 'unpublish_form' => [
'disclaimer' => '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', 'understand' => 'I understand, I want to unpublish the episode',
'submit' => 'Unpublish', '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' => 'Soundbites',
'soundbites_form' => [ 'soundbites_form' => [
'title' => 'Edit soundbites', 'title' => 'Edit soundbites',
......
...@@ -23,6 +23,7 @@ return [ ...@@ -23,6 +23,7 @@ return [
'publish' => 'publier', 'publish' => 'publier',
'publish-edit' => 'modifier la publication', 'publish-edit' => 'modifier la publication',
'unpublish' => 'dépublier', 'unpublish' => 'dépublier',
'delete' => 'supprimer',
'fediverse' => 'fédiverse', 'fediverse' => 'fédiverse',
'block-lists' => 'listes de blocage', 'block-lists' => 'listes de blocage',
'users' => 'utilisateurs', 'users' => 'utilisateurs',
......
...@@ -141,6 +141,18 @@ return [ ...@@ -141,6 +141,18 @@ return [
'message_warning_hint' => 'Ajouter un message augmente l’engagement social, menant à une meilleure visibilité pour votre épisode.', 'message_warning_hint' => 'Ajouter un message augmente l’engagement social, menant à une meilleure visibilité pour votre épisode.',
'message_warning_submit' => 'Publish quand même', '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' => 'Extraits sonores',
'soundbites_form' => [ 'soundbites_form' => [
'title' => 'Modifier les extraits sonores', 'title' => 'Modifier les extraits sonores',
......
<?= $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() ?>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<Alert variant="danger" glyph="alert" class="font-semibold"><?= lang('Episode.unpublish_form.disclaimer') ?></Alert> <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"> <div class="self-end mt-4">
<Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button> <Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment