Only query unpublish_all data on a relevant tab in the member manager (#19827)

* Only query unpublish_all data on a relevant tab in the member manager

* Added specs for AuditLog::UnpublishAllsQuery
This commit is contained in:
Anna Buianova 2023-07-25 17:36:45 +03:00 committed by GitHub
parent 012e625c7c
commit 869f29d942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View file

@ -418,7 +418,12 @@ module Admin
def set_unpublish_all_log
# in theory, there could be multiple "unpublish all" actions
# but let's query and display the last one for now, that should be enough for most cases
@unpublish_all_data = AuditLog::UnpublishAllsQuery.call(@user.id)
@unpublish_all_data = if @current_tab == "unpublish_logs"
AuditLog::UnpublishAllsQuery.call(@user.id)
else
# only find if the data exists for most tabs
AuditLog::UnpublishAllsQuery.new(@user.id).exists?
end
end
def calculate_countable_flags(reactions)

View file

@ -12,6 +12,12 @@ class AuditLog
@target_comments = []
end
def exists?
exists = AuditLog.where(slug: %w[api_user_unpublish unpublish_all_articles])
.where("data @> '{\"target_user_id\": ?}'", user_id).present?
Result.new(exists?: exists)
end
def call
audit_log = AuditLog.where(slug: %w[api_user_unpublish unpublish_all_articles])
.where("data @> '{\"target_user_id\": ?}'", user_id)

View file

@ -18,15 +18,25 @@ RSpec.describe AuditLog::UnpublishAllsQuery, type: :query do
expect(res.audit_log).to eq(audit_log)
end
it "exists?" do
it "exists? when data requested" do
res = described_class.call(user.id)
expect(res.exists?).to be true
end
it "exists? when exists requested" do
res = described_class.new(user.id).exists?
expect(res.exists?).to be true
end
end
it "doesn't exist when there is no related audit_log" do
it "doesn't exist when there is no related audit_log and asked for data" do
res = described_class.call(user.id)
expect(res.exists?).to be false
end
it "doesn't exist when there is no related audit_log and asked for exists?" do
res = described_class.new(user.id).exists?
expect(res.exists?).to be false
end
end
end