Add Recent Reactions to the Admin Users' Page (#10680)
* Adds Recent Reations back to the Admin Users page...UGH rebasing :( - Render negative_reactions partial in admin/edit.html.erb - Add #set_related_reactions back to Admin::UsersController - Refacotors JS to target #reports-row in _reports.html.erb * Alphabetizes reports and reactions partials in edit.html.erb * Adds tests around Recent Reports and Recent Reactions sections to users_spec.rb
This commit is contained in:
parent
1a8fa3b182
commit
0a5babc10e
4 changed files with 47 additions and 2 deletions
|
|
@ -16,6 +16,7 @@ module Admin
|
|||
@user = User.find(params[:id])
|
||||
@notes = @user.notes.order(created_at: :desc).limit(10).load
|
||||
set_feedback_messages
|
||||
set_related_reactions
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
@ -136,6 +137,17 @@ module Admin
|
|||
.order(created_at: :desc).limit(15)
|
||||
end
|
||||
|
||||
def set_related_reactions
|
||||
user_article_ids = @user.articles.ids
|
||||
user_comment_ids = @user.comments.ids
|
||||
@related_vomit_reactions = Reaction.where(reactable_type: "Comment", reactable_id: user_comment_ids,
|
||||
category: "vomit")
|
||||
.or(Reaction.where(reactable_type: "Article", reactable_id: user_article_ids, category: "vomit"))
|
||||
.or(Reaction.where(reactable_type: "User", user_id: @user.id, category: "vomit"))
|
||||
.includes(:reactable)
|
||||
.order(created_at: :desc).limit(15)
|
||||
end
|
||||
|
||||
def user_params
|
||||
allowed_params = %i[
|
||||
new_note note_for_current_role user_status
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<div class="crayons-card p-6">
|
||||
<div>
|
||||
<h2 class="d-inline">Recent Reports</h2>
|
||||
<button type="button" data-toggle="collapse" data-target="#reactions-row" class="btn btn-secondary float-right">Toggle</button>
|
||||
<button type="button" data-toggle="collapse" data-target="#reports-row" class="btn btn-secondary float-right">Toggle</button>
|
||||
</div>
|
||||
<div class="pt-6 collapse" id="reactions-row">
|
||||
<div class="pt-6 collapse" id="reports-row">
|
||||
<% unless @related_reports.empty? %>
|
||||
<% @related_reports.each do |report| %>
|
||||
<a href="<%= admin_report_path(report.id) %>" class="list-group-item list-group-item-action action px-5 d-flex justify-content-between">
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
</div>
|
||||
|
||||
<%= render "notes" %>
|
||||
<%= render "negative_reactions" %>
|
||||
<%= render "reports" %>
|
||||
|
||||
<div class="crayons-card p-6">
|
||||
|
|
|
|||
|
|
@ -40,6 +40,38 @@ RSpec.describe "admin/users", type: :request do
|
|||
sign_out(admin)
|
||||
expect { get "/admin/users/#{user.id}/edit" }.to raise_error(Pundit::NotAuthorizedError)
|
||||
end
|
||||
|
||||
it "displays the 'Recent Reactions' section" do
|
||||
get "/admin/users/#{user.id}/edit"
|
||||
expect(response.body).to include("Recent Reactions")
|
||||
end
|
||||
|
||||
it "displays a message when there are no related vomit reactions for a user" do
|
||||
get "/admin/users/#{user.id}/edit"
|
||||
expect(response.body).to include("Nothing negative to see here! 👀")
|
||||
end
|
||||
|
||||
it "displays a list of recent related vomit reactions for a user if any exist" do
|
||||
vomit = build(:reaction, category: "vomit", user_id: user.id, reactable_type: "Article", status: "valid")
|
||||
get "/admin/users/#{user.id}/edit"
|
||||
expect(response.body).to include(vomit.reactable_type)
|
||||
end
|
||||
|
||||
it "displays the 'Recent Reports' section" do
|
||||
get "/admin/users/#{user.id}/edit"
|
||||
expect(response.body).to include("Recent Reports")
|
||||
end
|
||||
|
||||
it "displays a message when there are no related reports for a user" do
|
||||
get "/admin/users/#{user.id}/edit"
|
||||
expect(response.body).to include("Nothing to report here! 👀")
|
||||
end
|
||||
|
||||
it "displays a list of recent reports for a user if any exist" do
|
||||
report = build(:feedback_message, category: "spam", affected_id: user.id, feedback_type: "spam", status: "Open")
|
||||
get "/admin/users/#{user.id}/edit"
|
||||
expect(response.body).to include(report.feedback_type)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /admin/users/:id/banish" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue