Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [email protected]?
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 = [email protected]?
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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