From edec58af81c9024287ce45a5d3da9e0dbefe791e Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Tue, 19 May 2026 13:06:13 -0300 Subject: [PATCH] refactor(post): remove now-dead PostAction::AlreadyPublished MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UpdatePost::execute used to return AlreadyPublished for the Published short-circuit. This PR widened the short-circuit to four terminal statuses and consolidated them under PostAction::Finalized — so the old enum case stopped being emitted, and every caller already had a defensive in_array([AlreadyPublished, Finalized], ...). Audit before removal: nothing emits AlreadyPublished anymore (only UpdatePost::execute returns Actions, and it returns Finalized for the whole terminal set), no test references the case, and no string 'already_published' exists elsewhere in app/resources/tests/lang. - Drop the enum case - Simplify the three in_array checks to a direct === Finalized - Delete the dead App/PostController branch that flashed the old cannot_edit_published message (its successor branch with cannot_edit_finalized stays). The old i18n key is left in lang/ for now — orphan but harmless, can ressuscitate if a similar flash is added back. --- app/Enums/Post/Action.php | 1 - app/Http/Controllers/Api/PostController.php | 2 +- app/Http/Controllers/App/PostController.php | 7 ------- app/Mcp/Tools/Post/PublishPostTool.php | 2 +- app/Mcp/Tools/Post/UpdatePostTool.php | 2 +- 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/Enums/Post/Action.php b/app/Enums/Post/Action.php index b781b03f..521c99d3 100644 --- a/app/Enums/Post/Action.php +++ b/app/Enums/Post/Action.php @@ -6,7 +6,6 @@ enum Action: string { - case AlreadyPublished = 'already_published'; case Finalized = 'finalized'; case Publishing = 'publishing'; case Scheduled = 'scheduled'; diff --git a/app/Http/Controllers/Api/PostController.php b/app/Http/Controllers/Api/PostController.php index 23296b92..c662d53d 100644 --- a/app/Http/Controllers/Api/PostController.php +++ b/app/Http/Controllers/Api/PostController.php @@ -67,7 +67,7 @@ public function update(UpdatePostRequest $request, Post $post): PostResource|Jso $result = UpdatePost::execute($request->user()->currentWorkspace, $post, $request->validated()); - if (in_array(data_get($result, 'action'), [PostAction::AlreadyPublished, PostAction::Finalized], true)) { + if (data_get($result, 'action') === PostAction::Finalized) { return response()->json( ['message' => 'Cannot edit a published post.'], Response::HTTP_UNPROCESSABLE_ENTITY diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.php index 051b3865..e02dbe95 100644 --- a/app/Http/Controllers/App/PostController.php +++ b/app/Http/Controllers/App/PostController.php @@ -282,13 +282,6 @@ public function update(UpdatePostRequest $request, Post $post): RedirectResponse $action = data_get($result, 'action'); - if ($action === PostAction::AlreadyPublished) { - session()->flash('flash.banner', __('posts.flash.cannot_edit_published')); - session()->flash('flash.bannerStyle', 'danger'); - - return back(); - } - if ($action === PostAction::Finalized) { session()->flash('flash.banner', __('posts.flash.cannot_edit_finalized')); session()->flash('flash.bannerStyle', 'danger'); diff --git a/app/Mcp/Tools/Post/PublishPostTool.php b/app/Mcp/Tools/Post/PublishPostTool.php index d69904d9..993fb434 100644 --- a/app/Mcp/Tools/Post/PublishPostTool.php +++ b/app/Mcp/Tools/Post/PublishPostTool.php @@ -47,7 +47,7 @@ public function handle(Request $request): Response|ResponseFactory 'scheduled_at' => $scheduledAt, ]); - if (in_array(data_get($result, 'action'), [PostAction::AlreadyPublished, PostAction::Finalized], true)) { + if (data_get($result, 'action') === PostAction::Finalized) { return Response::error('Post is already published or in a terminal state.'); } diff --git a/app/Mcp/Tools/Post/UpdatePostTool.php b/app/Mcp/Tools/Post/UpdatePostTool.php index b36f1613..6062a722 100644 --- a/app/Mcp/Tools/Post/UpdatePostTool.php +++ b/app/Mcp/Tools/Post/UpdatePostTool.php @@ -54,7 +54,7 @@ public function handle(Request $request): Response|ResponseFactory $result = UpdatePost::execute($workspace, $post, $payload); - if (in_array(data_get($result, 'action'), [PostAction::AlreadyPublished, PostAction::Finalized], true)) { + if (data_get($result, 'action') === PostAction::Finalized) { return Response::error('Cannot edit a published post.'); }