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:
parent
012e625c7c
commit
869f29d942
3 changed files with 24 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue