Skip to content

Commit

Permalink
Revert "AO3-5627 Prevent deleting sole published chapter of a work (m…
Browse files Browse the repository at this point in the history
…ust delete work instead)" (#4533)

Revert "AO3-5627 Prevent deleting sole published chapter of a work (must delete work instead) (#4406)"

This reverts commit ec28398.
  • Loading branch information
sarken authored Jun 19, 2023
1 parent 5bbd451 commit 2738e68
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
25 changes: 12 additions & 13 deletions app/controllers/chapters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
11 changes: 1 addition & 10 deletions spec/controllers/chapters_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2738e68

Please sign in to comment.