forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display information about "unpublish all" actions in the member manag…
…er (forem#18576) * Query audit_log + target records for display in the member manager * Display information about logged unpublished articles and comments * Display information if the post was republished * Added specs for unpublish_log tab on user's page in the member manager * Fixed specs * Change the wording for displaying info about unpublish all actions
- Loading branch information
1 parent
f839aca
commit 9bb5b81
Showing
8 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ module UserDetails | |
Emails | ||
Reports | ||
Flags | ||
UnpublishLogs | ||
].freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class AuditLog | ||
class UnpublishAllsQuery | ||
Result = Struct.new(:exists?, :audit_log, :target_articles, :target_comments, keyword_init: true) | ||
|
||
def initialize(user_id) | ||
@user_id = user_id | ||
@target_articles = [] | ||
@target_comments = [] | ||
end | ||
|
||
def self.call(...) | ||
new(...).call | ||
end | ||
|
||
def call | ||
audit_log = AuditLog.where(slug: %w[api_user_unpublish unpublish_all_articles]) | ||
.where("data @> '{\"target_user_id\": ?}'", user_id) | ||
.includes(:user) | ||
.order("created_at DESC") | ||
.first | ||
if audit_log | ||
target_articles = Article.where(id: audit_log.data["target_article_ids"], user_id: user_id) | ||
target_comments = Comment.where(id: audit_log.data["target_comment_ids"], user_id: user_id) | ||
end | ||
Result.new( | ||
exists?: audit_log.present?, | ||
audit_log: audit_log, | ||
target_articles: target_articles, | ||
target_comments: target_comments, | ||
) | ||
end | ||
|
||
attr_reader :user_id | ||
attr_accessor :target_comments, :target_articles | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% if @unpublish_all_data.exists? %> | ||
<h2 class="fs-xl fw-normal mb-5">Unpublished by <%= link_to @unpublish_all_data.audit_log.user.username, @unpublish_all_data.audit_log.user.path %> on <%= @unpublish_all_data.audit_log.created_at.strftime("%Y-%m-%d, %H:%M") %></h3> | ||
<div class="crayons-card p-6 mb-5"> | ||
<h4 class="mb-2">Posts:</h4> | ||
<% @unpublish_all_data.target_articles.each do |article| %> | ||
<div class="mb-1"> | ||
<%= link_to article.title, article.current_state_path %> | ||
<a href="<%= article.path %>/edit" target="_blank" rel="noopener" class="c-link">Edit</a> | ||
<% if article.published %> | ||
<span class="color-base-60">(was republished)</span> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<div class="crayons-card p-6"> | ||
<h4 class="mb-2">Comments:</h4> | ||
<% @unpublish_all_data.target_comments.each do |comment| %> | ||
<div class="crayons-card p-3 mb-3"> | ||
<div class="color-base-80"> | ||
<%= truncate(strip_tags(comment.processed_html), length: 250).html_safe %> | ||
</div> | ||
<%= link_to "commentable", comment.commentable.current_state_path %> | ||
<p class="fs-s"> | ||
Created at: <%= comment.created_at.strftime("%Y-%m-%d, %H:%M") %> | ||
</p> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe AuditLog::UnpublishAllsQuery, type: :query do | ||
let(:user) { create(:user) } | ||
let!(:article) { create(:article, user: user) } | ||
|
||
describe "::call" do | ||
context "when audit_log exists" do | ||
let!(:audit_log) do | ||
create(:audit_log, slug: "unpublish_all_articles", | ||
data: { target_user_id: user.id, target_article_ids: [article.id] }) | ||
end | ||
|
||
it "has articles and audit_log in the result" do | ||
res = described_class.call(user.id) | ||
expect(res.target_articles).to eq([article]) | ||
expect(res.target_comments).to eq([]) | ||
expect(res.audit_log).to eq(audit_log) | ||
end | ||
|
||
it "exists?" do | ||
res = described_class.call(user.id) | ||
expect(res.exists?).to be true | ||
end | ||
end | ||
|
||
it "doesn't exist when there is no related audit_log" do | ||
res = described_class.call(user.id) | ||
expect(res.exists?).to be false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters