Fixed removing notifications on admin unpublishing (#18047)
This commit is contained in:
parent
98514216e7
commit
6a229f00b7
2 changed files with 19 additions and 3 deletions
|
|
@ -213,13 +213,17 @@ class ArticlesController < ApplicationController
|
|||
|
||||
def admin_unpublish
|
||||
authorize @article
|
||||
attributes = {}
|
||||
if @article.has_frontmatter?
|
||||
@article.body_markdown.sub!(/\npublished:\s*true\s*\n/, "\npublished: false\n")
|
||||
body_markdown = @article.body_markdown.sub(/\npublished:\s*true\s*\n/, "\npublished: false\n")
|
||||
attributes[:body_markdown] = body_markdown
|
||||
else
|
||||
@article.published = false
|
||||
attributes[:published] = false
|
||||
end
|
||||
|
||||
if @article.save
|
||||
result = Articles::Updater.call(current_user, @article, attributes)
|
||||
|
||||
if result.success
|
||||
render json: { message: "success", path: @article.current_state_path }, status: :ok
|
||||
else
|
||||
render json: { message: @article.errors.full_messages }, status: :unprocessable_entity
|
||||
|
|
|
|||
|
|
@ -20,4 +20,16 @@ RSpec.describe "ArticlesAdminUnpublish", type: :request do
|
|||
article.reload
|
||||
expect(article.published).to be false
|
||||
end
|
||||
|
||||
it "removes the related notifications when unpublishing" do
|
||||
expect(article.published).to be true
|
||||
create(:notification, notifiable: article, action: "Published")
|
||||
expect do
|
||||
patch "/articles/#{article.id}/admin_unpublish", params: {
|
||||
id: article.id,
|
||||
username: user.username,
|
||||
slug: article.slug
|
||||
}
|
||||
end.to change(Notification, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue