mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:38:17 +08:00
FIX: log for CleanUpTags job (#23964)
In previous [PR](https://github.com/discourse/discourse/pull/23864) we introduced setting to automatically delete unused tags. This action should be logged.
This commit is contained in:
parent
e91d8feab3
commit
8c355d9e99
|
@ -8,7 +8,14 @@ module Jobs
|
|||
|
||||
def execute(args)
|
||||
return unless SiteSetting.automatically_clean_unused_tags
|
||||
Tag.unused.where("tags.created_at < ?", GRACE_PERIOD_MINUTES.minutes.ago).destroy_all
|
||||
Tag.transaction do
|
||||
tags = Tag.unused.where("tags.created_at < ?", GRACE_PERIOD_MINUTES.minutes.ago)
|
||||
StaffActionLogger.new(Discourse.system_user).log_custom(
|
||||
"deleted_unused_tags",
|
||||
tags: tags.pluck(:name),
|
||||
)
|
||||
tags.destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,6 +43,16 @@ describe Jobs::CleanUpTags do
|
|||
created_at: 10.minutes.ago,
|
||||
)
|
||||
end
|
||||
fab!(:unused_tag_2) do
|
||||
Fabricate(
|
||||
:tag,
|
||||
name: "unused2",
|
||||
staff_topic_count: 0,
|
||||
public_topic_count: 0,
|
||||
pm_topic_count: 0,
|
||||
created_at: 10.minutes.ago,
|
||||
)
|
||||
end
|
||||
|
||||
fab!(:tag_in_group) do
|
||||
Fabricate(
|
||||
|
@ -57,8 +67,17 @@ describe Jobs::CleanUpTags do
|
|||
|
||||
it "deletes unused tags" do
|
||||
SiteSetting.automatically_clean_unused_tags = true
|
||||
expect { job.execute({}) }.to change { Tag.count }.by(-1)
|
||||
expect { job.execute({}) }.to change { Tag.count }.by(-2)
|
||||
expect { unused_tag.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { unused_tag_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "logs action" do
|
||||
SiteSetting.automatically_clean_unused_tags = true
|
||||
expect { job.execute({}) }.to change { UserHistory.count }.by(1)
|
||||
log = UserHistory.last
|
||||
expect(log.acting_user_id).to eq(-1)
|
||||
expect(log.details).to eq('tags: ["unused1", "unused2"]')
|
||||
end
|
||||
|
||||
it "does nothing when site setting is disabled by default" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user