From d0d920c6297b9223d4ad14fbcfc2ae2a67cc5acf Mon Sep 17 00:00:00 2001 From: sarken Date: Mon, 19 Jun 2023 02:50:03 -0400 Subject: [PATCH] Revert "AO3-5627 Prevent deleting sole published chapter of a work (must delete work instead) (#4406)" This reverts commit ec283984cce9c90827c5dcd197feaf09ce431855. --- app/controllers/chapters_controller.rb | 25 ++++++++++---------- app/models/chapter.rb | 4 ---- config/locales/controllers/en.yml | 2 -- spec/controllers/chapters_controller_spec.rb | 11 +-------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/app/controllers/chapters_controller.rb b/app/controllers/chapters_controller.rb index 66d70cc8ab..8d11d2ae8a 100644 --- a/app/controllers/chapters_controller.rb +++ b/app/controllers/chapters_controller.rb @@ -213,22 +213,21 @@ def confirm_delete # DELETE /work/:work_id/chapters/1 # DELETE /work/:work_id/chapters/1.xml def destroy - if @chapter.is_only_chapter? || @chapter.only_non_draft_chapter? - flash[:error] = t(".only_chapter") + if @chapter.is_only_chapter? + flash[:error] = ts("You can't delete the only chapter in your story. If you want to delete the story, choose 'Delete work'.") redirect_to(edit_work_path(@work)) - return - end - - was_draft = !@chapter.posted? - if @chapter.destroy - @work.minor_version = @work.minor_version + 1 - @work.set_revised_at - @work.save - flash[:notice] = ts("The chapter #{was_draft ? 'draft ' : ''}was successfully deleted.") else - flash[:error] = ts("Something went wrong. Please try again.") + was_draft = !@chapter.posted? + if @chapter.destroy + @work.minor_version = @work.minor_version + 1 + @work.set_revised_at + @work.save + flash[:notice] = ts("The chapter #{was_draft ? 'draft ' : ''}was successfully deleted.") + else + flash[:error] = ts("Something went wrong. Please try again.") + end + redirect_to controller: 'works', action: 'show', id: @work end - redirect_to controller: "works", action: "show", id: @work end private diff --git a/app/models/chapter.rb b/app/models/chapter.rb index d113e6e5ec..ec73288925 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -149,10 +149,6 @@ def is_only_chapter? self.work.chapters.count == 1 end - def only_non_draft_chapter? - self.posted? && self.work.chapters.posted.count == 1 - end - # Virtual attribute for work wip_length # Chapter needed its own version for sense-checking purposes def wip_length diff --git a/config/locales/controllers/en.yml b/config/locales/controllers/en.yml index ff90b0ec19..3fe422de62 100644 --- a/config/locales/controllers/en.yml +++ b/config/locales/controllers/en.yml @@ -13,8 +13,6 @@ en: destroy: unblocked: You have unblocked the user %{name}. chapters: - destroy: - only_chapter: You can't delete the only chapter in your work. If you want to delete the work, choose "Delete Work". show: anonymous: Anonymous chapter_position: " - Chapter %{position}" diff --git a/spec/controllers/chapters_controller_spec.rb b/spec/controllers/chapters_controller_spec.rb index 01ba9a1e98..97a4a95a86 100644 --- a/spec/controllers/chapters_controller_spec.rb +++ b/spec/controllers/chapters_controller_spec.rb @@ -961,7 +961,7 @@ context "when work has one chapter" do it "redirects to edit work" do delete :destroy, params: { work_id: work.id, id: work.chapters.first.id } - it_redirects_to_with_error(edit_work_path(work), "You can't delete the only chapter in your work. If you want to delete the work, choose \"Delete Work\".") + it_redirects_to_with_error(edit_work_path(work), "You can't delete the only chapter in your story. If you want to delete the story, choose 'Delete work'.") end end @@ -1067,15 +1067,6 @@ .and avoid_changing { work.number_of_posted_chapters } end end - - context "when work has more than one chapter and all but one are drafts" do - let!(:chapter2) { create(:chapter, work: work, posted: false, position: 2, authors: [user.pseuds.first]) } - - it "cannot delete the posted chapter" do - delete :destroy, params: { work_id: work.id, id: work.chapters.first.id } - it_redirects_to_with_error(edit_work_path(work), "You can't delete the only chapter in your work. If you want to delete the work, choose \"Delete Work\".") - end - end end context "when other user is logged in" do