mod actions: add options to filter /mod_actions by subject.
This commit is contained in:
@@ -21,6 +21,14 @@ class IpBansController < ApplicationController
|
||||
respond_with(@ip_bans)
|
||||
end
|
||||
|
||||
def show
|
||||
@ip_ban = authorize IpBan.find(params[:id])
|
||||
|
||||
respond_with(@ip_ban) do |format|
|
||||
format.html { redirect_to ip_bans_path(search: { id: @ip_ban.id }) }
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@ip_ban = authorize IpBan.find(params[:id])
|
||||
@ip_ban.update(permitted_attributes(@ip_ban))
|
||||
|
||||
@@ -5,7 +5,11 @@ class ModActionsController < ApplicationController
|
||||
|
||||
def index
|
||||
@mod_actions = ModAction.visible(CurrentUser.user).paginated_search(params)
|
||||
@mod_actions = @mod_actions.includes(:creator) if request.format.html?
|
||||
|
||||
if request.format.html?
|
||||
@mod_actions = @mod_actions.includes(:creator, :subject)
|
||||
@dtext_data = DText.preprocess(@mod_actions.map(&:description))
|
||||
end
|
||||
|
||||
respond_with(@mod_actions)
|
||||
end
|
||||
|
||||
@@ -67,12 +67,10 @@ class ModAction < ApplicationRecord
|
||||
ip_ban_delete: 162,
|
||||
ip_ban_undelete: 163,
|
||||
mass_update: 1000, # XXX unused
|
||||
bulk_revert: 1001, # XXX unused
|
||||
other: 2000,
|
||||
}
|
||||
|
||||
def self.model_types
|
||||
%w[Artist Comment CommentVote ForumPost ForumTopic IpBan ModerationReport Pool Post PostVote Tag TagAlias TagImplication User UserFeedback]
|
||||
%w[Artist Comment CommentVote ForumPost ForumTopic IpBan ModerationReport Pool Post PostVote Tag TagAlias TagImplication User]
|
||||
end
|
||||
|
||||
def self.visible(user)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<%= search_form_for(mod_actions_path) do |f| %>
|
||||
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %>
|
||||
<%= f.input :description_matches, label: "Description", input_html: { value: params[:search][:description_matches] } %>
|
||||
<%= f.input :category, label: "Category", collection: ModAction.categories.map {|k,v| [k.capitalize.tr("_"," "), v]}, include_blank: true,selected: params[:search][:category] %>
|
||||
<% if params[:search][:subject_id].present? && params[:search][:subject_type] %>
|
||||
<%= f.input :subject_id, label: "#{params[:search][:subject_type].titleize} ID", input_html: { value: params[:search][:subject_id] } %>
|
||||
<% end %>
|
||||
<%= f.input :subject_type, label: "Subject", collection: ModAction.model_types.map { |k, v| [k.titleize, k] }, include_blank: true, selected: params[:search][:subject_type] %>
|
||||
<%= f.input :category, label: "Category", collection: ModAction.categories.map { |k, v| [k.capitalize.tr("_", " "), k] }, include_blank: true, selected: params[:search][:category] %>
|
||||
<%= f.input :order, collection: [%w[Newest created_at], %w[Oldest created_at_asc]], include_blank: true, selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
<%= render "search" %>
|
||||
|
||||
<%= table_for @mod_actions, class: "striped autofit" do |t| %>
|
||||
<% t.column "Message", td: {class: "col-expand"} do |mod_action| %>
|
||||
<% t.column "Description", td: { class: "col-expand" } do |mod_action| %>
|
||||
<div class="prose">
|
||||
<%= link_to_user mod_action.creator %> <%= format_text(mod_action.description.chomp(".").strip, inline: true) %>.
|
||||
<%= link_to_user mod_action.creator %> <%= format_text(mod_action.description.chomp(".").strip, inline: true, data: @dtext_data) %>.
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% t.column "Category" do |mod_action| %>
|
||||
<%= link_to mod_action.category.humanize, mod_actions_path(search: { category: mod_action.category_id }) %>
|
||||
<%= link_to mod_action.category.humanize, mod_actions_path(search: { category: mod_action.category }) %>
|
||||
<% end %>
|
||||
|
||||
<% t.column "Created" do |mod_action| %>
|
||||
@@ -20,6 +20,20 @@
|
||||
<%= link_to "»", mod_actions_path(search: { creator_name: mod_action.creator.name }) %>
|
||||
<div><%= time_ago_in_words_tagged(mod_action.created_at) %></div>
|
||||
<% end %>
|
||||
|
||||
<% t.column column: :control do |mod_action| %>
|
||||
<% if mod_action.subject_id.present? %>
|
||||
<%= render PopupMenuComponent.new do |menu| %>
|
||||
<% menu.item do %>
|
||||
<%= link_to "Details", mod_action.subject %>
|
||||
<% end %>
|
||||
|
||||
<% menu.item do %>
|
||||
<%= link_to "#{mod_action.subject_type.titleize.humanize} history", mod_actions_path(search: { subject_type: mod_action.subject_type, subject_id: mod_action.subject_id }) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(@mod_actions) %>
|
||||
|
||||
@@ -137,7 +137,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
resources :forum_topic_visits, only: [:index]
|
||||
resources :ip_bans, only: [:index, :new, :create, :update]
|
||||
resources :ip_bans, only: [:index, :show, :new, :create, :update]
|
||||
resources :ip_addresses, only: [:show], id: /.+?(?=\.json|\.xml|\.html)|.+/
|
||||
resources :ip_geolocations, only: [:index]
|
||||
resource :iqdb_queries, :only => [:show, :create] do
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
FactoryBot.define do
|
||||
factory(:mod_action) do
|
||||
creator :factory => :user
|
||||
description {"1234"}
|
||||
category {"other"}
|
||||
creator factory: :user
|
||||
subject factory: :post
|
||||
description { "undeleted post ##{subject_id}" }
|
||||
category { "post_undelete" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,6 +60,26 @@ class IpBansControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
should "redirect for html" do
|
||||
get_auth ip_ban_path(@ip_ban), @admin
|
||||
|
||||
assert_redirected_to ip_bans_path(search: { id: @ip_ban.id })
|
||||
end
|
||||
|
||||
should "render for json" do
|
||||
get_auth ip_ban_path(@ip_ban), @admin, as: :json
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "render 403 for an unauthorized user" do
|
||||
get ip_ban_path(@ip_ban)
|
||||
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
should "mark an ip ban as deleted" do
|
||||
put_auth ip_ban_path(@ip_ban), @admin, params: { ip_ban: { is_deleted: true }, format: "js" }
|
||||
|
||||
Reference in New Issue
Block a user