implemented moderator dashboard queue

This commit is contained in:
albert
2011-07-22 17:34:43 -04:00
parent 4828cef27d
commit d0e8084f0f
41 changed files with 710 additions and 330 deletions

View File

@@ -1,9 +1,10 @@
module Moderator
class DashboardsController < ApplicationController
before_filter :janitor_only
helper :post_flags, :post_appeals
def show
@dashboard = ModeratorDashboard.new(params[:min_date] || 2.days.ago.to_date, params[:max_level] || 20)
@dashboard = Moderator::Dashboard::Report.new(params[:min_date] || 2.days.ago.to_date, params[:max_level] || 20)
end
end
end

View File

@@ -0,0 +1,9 @@
module Moderator
class InvitationsController < ApplicationController
def new
end
def create
end
end
end

View File

@@ -0,0 +1,9 @@
module Moderator
class IpAddrsController < ApplicationController
def index
end
def search
end
end
end

View File

@@ -33,6 +33,23 @@ module ApplicationHelper
end
end
def mod_link_to_user(user, positive_or_negative)
html = ""
html << link_to(user.name, user_path(user))
if positive_or_negative == :positive
html << " [" + link_to("+", new_user_feedback_path(:user_record => {:category => "positive"})) + "]"
unless user.is_privileged?
html << " [" + link_to("invite", moderator_invitations_path(:invitation => {:name => user.name, :level => User::Levels::CONTRIBUTOR})) + "]"
end
else
html << " [" + link_to("&ndash;", new_user_feedback_path(:user_record => {:category => "negative", :user_id => user.id})) + "]"
end
html
end
protected
def nav_link_match(controller, url)
url =~ case controller

View File

@@ -0,0 +1,30 @@
module Moderator
module Dashboard
module Queries
class Artist
attr_reader :user, :count
def self.all(min_date, max_level)
sql = <<-EOS
SELECT artist_versions.updater_id AS user_id, count(*)
FROM artist_versions
JOIN users ON users.id = artist_versions.updater_id
WHERE
artist_versions.created_at > ?
AND users.level <= ?
GROUP BY artist_versions.updater_id
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
end
def initialize(hash)
@user = ::User.find(hash["updater_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -4,8 +4,27 @@ module Moderator
class Comment
attr_reader :comment, :count
def self.all(min_date, max_level)
sql = <<-EOS
SELECT comment_votes.comment_id, count(*)
FROM comment_votes
JOIN comments ON comments.id = comment_id
JOIN users ON users.id = comments.creator_id
WHERE
comment_votes.created_at > ?
AND comments.score < 0
AND users.level <= ?
GROUP BY comment_votes.comment_id
HAVING count(*) >= 3
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
end
def initialize(hash)
@comment = Comment.find(hash["comment_id"])
@comment = ::Comment.find(hash["comment_id"])
@count = hash["count"]
end
end

View File

@@ -0,0 +1,11 @@
module Moderator
module Dashboard
module Queries
class ModAction
def self.all
::ModAction.order("id desc").limit(10)
end
end
end
end
end

View File

@@ -0,0 +1,30 @@
module Moderator
module Dashboard
module Queries
class Note
attr_reader :user, :count
def self.all(min_date, max_level)
sql = <<-EOS
SELECT note_versions.updater_id, count(*)
FROM note_versions
JOIN users ON users.id = note_versions.updater_id
WHERE
note_versions.created_at > ?
AND users.level <= ?
GROUP BY note_versions.updater_id
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
end
def initialize(hash)
@user = ::User.find(hash["updater_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -1,14 +0,0 @@
module Moderator
module Dashboard
module Queries
class Post
attr_reader :post, :count
def initialize(hash)
@post = Post.find(hash["post_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -2,7 +2,7 @@ module Moderator
module Dashboard
module Queries
class PostAppeal
attr_reader :post, :reason
attr_reader :post, :count
def self.all(min_date)
sql = <<-EOS
@@ -11,7 +11,8 @@ module Moderator
JOIN posts ON posts.id = post_appeals.post_id
WHERE
post_appeals.created_at > ?
and posts.status <> ?
and posts.is_deleted = true
and posts.is_pending = false
GROUP BY post_appeals.post_id
ORDER BY count(*) DESC
LIMIT 10
@@ -21,8 +22,8 @@ module Moderator
end
def initialize(hash)
@post = Post.find(hash["post_id"])
@reason = hash["reason"]
@post = ::Post.find(hash["post_id"])
@count = hash["count"]
end
end
end

View File

@@ -12,7 +12,8 @@ module Moderator
WHERE
post_flags.created_at > ?
AND post_flags.reason <> ?
AND posts.status <> 'deleted'
AND posts.is_deleted = false
and posts.is_pending = false
GROUP BY post_flags.post_id
ORDER BY count(*) DESC
LIMIT 10

View File

@@ -0,0 +1,32 @@
module Moderator
module Dashboard
module Queries
class Tag
attr_reader :user, :count
def self.all(min_date, max_level)
sql = <<-EOS
SELECT post_versions.updater_id, count(*)
FROM post_versions
JOIN users ON users.id = post_versions.updater_id
WHERE
post_versions.created_at > ?
AND users.level <= ?
GROUP BY post_versions.updater_id
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.without_timeout do
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
end
end
def initialize(hash)
@user = ::User.find(hash["updater_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -2,10 +2,27 @@ module Moderator
module Dashboard
module Queries
class Upload
def self.all(min_date)
ActiveRecord::Base.without_timeout do
@upload_activity = ActiveRecord::Base.select_all_sql("select posts.uploader_string, count(*) from posts join users on posts.user_id = users.id where posts.created_at > ? and users.level <= ? group by posts.user_id order by count(*) desc limit 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
attr_reader :user, :count
def self.all(min_date, max_level)
sql = <<-EOS
select uploader_id, count(*)
from posts
join users on uploader_id = users.id
where
posts.created_at > ?
and level <= ?
group by posts.uploader_id
order by count(*) desc
limit 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
end
def initialize(hash)
@user = ::User.find(hash["uploader_id"])
@count = hash["count"]
end
end
end

View File

@@ -1,14 +0,0 @@
module Moderator
module Dashboard
module Queries
class User
attr_reader :user, :count
def initialize(hash)
@user = User.find(hash["user_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -0,0 +1,11 @@
module Moderator
module Dashboard
module Queries
class UserFeedback
def self.all
::UserFeedback.order("id desc").limit(10)
end
end
end
end
end

View File

@@ -0,0 +1,30 @@
module Moderator
module Dashboard
module Queries
class WikiPage
attr_reader :user, :count
def self.all(min_date, max_level)
sql = <<-EOS
SELECT wiki_page_versions.updater_id, count(*)
FROM wiki_page_versions
JOIN users ON users.id = wiki_page_versions.updater_id
WHERE
wiki_page_versions.created_at > ?
AND users.level <= ?
GROUP BY wiki_page_versions.updater_id
ORDER BY count(*) DESC
LIMIT 10
EOS
ActiveRecord::Base.select_all_sql(sql, min_date, max_level).map {|x| new(x)}
end
def initialize(hash)
@user = ::User.find(hash["updater_id"])
@count = hash["count"]
end
end
end
end
end

View File

@@ -1,6 +1,52 @@
module Moderator
module Dashboard
class Report
attr_reader :min_date, :max_level
def initialize(min_date, max_level)
@min_date = min_date
@max_level = max_level
end
def artists
Queries::Artist.all(min_date, max_level)
end
def comments
Queries::Comment.all(min_date, max_level)
end
def mod_actions
Queries::ModAction.all
end
def notes
Queries::Note.all(min_date, max_level)
end
def appeals
Queries::PostAppeal.all(min_date)
end
def flags
Queries::PostFlag.all(min_date)
end
def tags
Queries::Tag.all(min_date, max_level)
end
def posts
Queries::Upload.all(min_date, max_level)
end
def user_feedbacks
Queries::UserFeedback.all
end
def wiki_pages
Queries::WikiPage.all(min_date, max_level)
end
end
end
end

View File

@@ -1,54 +0,0 @@
class ModeratorDashboard
attr_reader :min_date, :max_level
def initialize(min_date, max_level)
@min_date = min_date
@max_level = max_level
end
def upload_activity
@upload_activity
end
def comment_activity(positive = false)
if positive
ActiveRecord::Base.select_all_sql("SELECT comment_votes.comment_id, count(*) FROM comment_votes JOIN comments ON comments.id = comment_votes.comment_id JOIN users ON users.id = comments.user_id WHERE comment_votes.created_at > ? AND comments.score > 0 AND users.level <= ? GROUP BY comment_votes.comment_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| CommentActivity.new(x)}
else
ActiveRecord::Base.select_all_sql("SELECT comment_votes.comment_id, count(*) FROM comment_votes JOIN comments ON comments.id = comment_votes.comment_id JOIN users ON users.id = comments.user_id WHERE comment_votes.created_at > ? AND comments.score < 0 AND users.level <= ? GROUP BY comment_votes.comment_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| CommentActivity.new(x)}
end
end
def post_activity(positive = false)
ActiveRecord::Base.without_timeout do
if positive
@post_activity = ActiveRecord::Base.select_all_sql("SELECT post_votes.post_id, count(*) FROM post_votes JOIN posts ON posts.id = post_votes.post_id JOIN users ON users.id = posts.user_id WHERE post_votes.created_at > ? AND posts.score > 0 AND users.level <= ? GROUP BY post_votes.post_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| PostActivity.new(x)}
else
@post_activity = ActiveRecord::Base.select_all_sql("SELECT post_votes.post_id, count(*) FROM post_votes JOIN posts ON posts.id = post_votes.post_id JOIN users ON users.id = posts.user_id WHERE post_votes.created_at > ? AND posts.score < 0 AND users.level <= ? AND posts.status <> 'deleted' GROUP BY post_votes.post_id HAVING count(*) >= 3 ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| PostActivity.new(x)}
end
end
@post_activity
end
def tag_activity
ActiveRecord::Base.without_timeout do
@tag_activity = ActiveRecord::Base.select_all_sql("SELECT post_tag_histories.user_id, count(*) FROM post_tag_histories JOIN users ON users.id = post_tag_histories.user_id WHERE post_tag_histories.created_at > ? AND users.level <= ? GROUP BY post_tag_histories.user_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
@tag_activity
end
def note_activity
ActiveRecord::Base.select_all_sql("SELECT note_versions.user_id, count(*) FROM note_versions JOIN users ON users.id = note_versions.user_id WHERE note_versions.created_at > ? AND users.level <= ? GROUP BY note_versions.user_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
def wiki_page_activity
ActiveRecord::Base.select_all_sql("SELECT wiki_page_versions.user_id, count(*) FROM wiki_page_versions JOIN users ON users.id = wiki_page_versions.user_id WHERE wiki_page_versions.created_at > ? AND users.level <= ? GROUP BY wiki_page_versions.user_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
def artist_activity
ActiveRecord::Base.select_all_sql("SELECT artist_versions.updater_id AS user_id, count(*) FROM artist_versions JOIN users ON users.id = artist_versions.updater_id WHERE artist_versions.created_at > ? AND users.level <= ? GROUP BY artist_versions.updater_id ORDER BY count(*) DESC LIMIT 10", min_date, max_level).map {|x| UserActivity.new(x)}
end
end

3
app/models/mod_action.rb Normal file
View File

@@ -0,0 +1,3 @@
class ModAction < ActiveRecord::Base
belongs_to :creator, :class_name => "User"
end

View File

@@ -42,8 +42,9 @@
<%= nav_link_to("Pools", pools_path) %>
<%= nav_link_to("Wiki", wiki_pages_path(:title => "help:home")) %>
<%= nav_link_to("Forum", forum_topics_path, :class => (CurrentUser.user.has_forum_been_updated? ? "forum-updated" : nil)) %>
<% if CurrentUser.is_moderator? %>
<% if CurrentUser.is_janitor? %>
<%= nav_link_to("Dashboard", moderator_dashboard_path) %>
<%= nav_link_to("Queue", moderator_post_dashboard_path) %>
<% end %>
<%= nav_link_to("&raquo;".html_safe, site_map_path) %>
</menu>

View File

@@ -0,0 +1,25 @@
<table>
<caption>Appeals</caption>
<thead>
<tr>
<th>Post</th>
<th>User</th>
<th>Flags</th>
<th>Appeals</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<% @dashboard.appeals.each do |appeal| %>
<tr>
<td><%= link_to image_tag(appeal.post.preview_file_url), post_path(appeal.post) %></td>
<td><%= mod_link_to_user appeal.post.uploader, :negative %></td>
<td><%= post_flag_reasons(appeal.post) %></td>
<td><%= post_appeal_reasons(appeal.post) %></td>
<td><%= appeal.post.score %></td>
</tr>
<% end %>
</tbody>
</table>
<p><%= link_to "View all appeals", post_appeals_path %></p>

View File

@@ -0,0 +1,17 @@
<table>
<caption>Artist Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.artists.each do |activity| %>
<tr>
<td><%= mod_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, artist_versions_path(:search => {:updater_id_eq => activity.user.id}) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,21 @@
<table>
<caption>Comment Activity</caption>
<thead>
<tr>
<th>Comment</th>
<th>User</th>
<th>Votes</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<% @dashboard.comments.each do |activity| %>
<tr>
<td><%= link_to activity.comment.body, post_path(activity.comment.post_id) %></td>
<td><%= mod_link_to_user(activity.comment.creator, :negative) %></td>
<td><%= activity.count %></td>
<td><%= activity.comment.score %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,19 @@
<table>
<caption>Mod Actions</caption>
<thead>
<tr>
<th>Moderator</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<% @dashboard.mod_actions.each do |mod_action| %>
<tr>
<td><%= link_to mod_action.creator.name, user_path(mod_action.creator) %></td>
<td><%= format_text(mod_action.description) %></td>
</tr>
<% end %>
</tbody>
</table>
<p><%= link_to "View all actions", mod_actions_path %></p>

View File

@@ -0,0 +1,17 @@
<table>
<caption>Note Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.notes.each do |activity| %>
<tr>
<td><%= mod_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, note_versions_path(:search => {:updater_id_eq => activity.user.id}) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,17 @@
<table>
<caption>Tag Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.tags.each do |activity| %>
<tr>
<td><%= mod_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, post_versions_path(:search => {:updater_id_eq => activity.user.id}) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,17 @@
<table>
<caption>Uploads</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.posts.each do |activity| %>
<tr>
<td><%= mod_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, posts_path(:tags => "user:#{activity.user.name}") %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,19 @@
<table>
<caption>User Feedback</caption>
<thead>
<tr>
<th>User</th>
<th>Message</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<% @dashboard.user_feedbacks.each do |record| %>
<tr class="user-record-score-<%= record.category %>">
<td><%= link_to(record.user.name, user_path(record.user)) %></td>
<td><%= format_text(record.body) %></td>
<td><%= time_ago_in_words(record.created_at) %> ago</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,17 @@
<table>
<caption>Wiki Page Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.wiki_pages.each do |activity| %>
<tr>
<td><%= mod_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, wiki_page_versions_path(:search => {:updater_id_eq => activity.user.id}) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1,7 @@
<div id="ip-addr-search">
<%= render "search_ip_addr" %>
</div>
<div id="activity-search">
<%= render "search_activity" %>
</div>

View File

@@ -0,0 +1,9 @@
<% form_tag(moderator_dashboard_path, :method => :get) do %>
<label for="min_date">Minimum Date</label>
<%= text_field_tag :min_date, @dashboard.min_date %><br>
<label for="max_level">Max Level</label>
<%= user_level_select_tag(:max_level) %><br>
<%= submit_tag "Search" %>
<% end %>

View File

@@ -0,0 +1,11 @@
<% form_tag(moderator_ip_addrs_path, :method => :get) do %>
<label for="user_ids">Search IPs</label>
<%= text_field_tag "search[ip_addr_eq]", params[:ip_addrs] %>
<%= submit_tag "Search" %>
<% end %>
<% form_tag(moderator_ip_addrs_path, :method => :get) do %>
<label for="user_ids">Search User IDs</label>
<%= text_field_tag "search[user_id_eq]", params[:user_ids] %>
<%= submit_tag "Search" %>
<% end %>

View File

@@ -1,222 +1,22 @@
<div id="moderator-dashboard">
<h1>Moderator Dashboard</h1>
<div id="ip-addr-search">
<% form_tag(moderator_ip_addrs_path, :method => :get) do %>
<label for="user_ids">Search IPs</label>
<%= text_field_tag "search[ip_addr_eq]", params[:ip_addrs] %>
<%= submit_tag "Search" %>
<% end %>
<% form_tag(moderator_ip_addrs_path, :method => :get) do %>
<label for="user_ids">Search User IDs</label>
<%= text_field_tag "search[user_id_eq]", params[:user_ids] %>
<%= submit_tag "Search" %>
<% end %>
</div>
<div id="activity-search">
<% form_tag(moderator_dashboard_path, :method => :get) do %>
<label for="min_date">Minimum Date</label>
<%= text_field_tag :min_date, @dashboard.min_date %><br>
<label for="max_level">Max Level</label>
<%= user_level_select_tag(:max_level) %><br>
<%= submit_tag "Search" %>
<% end %>
</div>
<div id="comment-activity">
<table width="100%" class="striped">
<caption>Uploads</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.upload_activity.each do |activity| %>
<tr>
<td><%= admin_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, {:controller => "post", :action => "index", :tags => "user:#{activity.user.name}"} %></td>
</tr>
<% end %>
</tbody>
</table>
<table width="100%" class="striped">
<caption>Note Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.note_activity.each do |activity| %>
<tr>
<td><%= admin_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, {:controller => "note", :action => "history", :user_id => activity.user.id} %></td>
</tr>
<% end %>
</tbody>
</table>
<table width="100%" class="striped">
<caption>Tag Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.tag_activity.each do |activity| %>
<tr>
<td><%= admin_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, {:controller => "post_tag_history", :action => "index", :user_id => activity.user.id} %></td>
</tr>
<% end %>
</tbody>
</table>
<table width="100%" class="striped">
<caption>Wiki Page Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.wiki_page_activity.each do |activity| %>
<tr>
<td><%= admin_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, {:controller => "wiki", :action => "recent_changes", :user_id => activity.user.id} %></td>
</tr>
<% end %>
</tbody>
</table>
<table width="100%" class="striped">
<caption>Artist Updates</caption>
<thead>
<tr>
<th>User</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<% @dashboard.artist_activity.each do |activity| %>
<tr>
<td><%= admin_link_to_user(activity.user, :positive) %></td>
<td><%= link_to activity.count, {:controller => "artist", :action => "recent_changes", :user_id => activity.user.id} %></td>
</tr>
<% end %>
</tbody>
</table>
<table width="100%" class="striped">
<caption>Comment Activity (Negative)</caption>
<thead>
<tr>
<th>Comment</th>
<th>User</th>
<th>Votes</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<% @dashboard.comment_activity.each do |activity| %>
<tr>
<td><%= link_to activity.comment.body, :controller => "post", :action => "show", :id => activity.comment.post_id %></td>
<td><%= admin_link_to_user(activity.comment.user, :negative) %></td>
<td><%= activity.count %></td>
<td><%= activity.comment.score %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div id="post-activity">
<table width="100%" class="striped">
<caption>Appealed Posts</caption>
<thead>
<tr>
<th>Post</th>
<th>User</th>
<th>Flags</th>
<th>Appeals</th>
<th>Score</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5"><%= link_to "View all posts", :controller => "post_appeal", :action => "index" %></td>
</tr>
</tfoot>
<tbody>
<% @dashboard.appealed_posts.each do |appeal| %>
<tr>
<td><%= link_to image_tag(appeal.post.preview_url), :controller => "post", :action => "show", :id => appeal.post.id %></td>
<td><%= admin_link_to_user appeal.post.user, :negative %></td>
<td><%= post_flag_summary(appeal.post) %></td>
<td><%= post_appeal_summary(appeal.post) %></td>
<td><%= appeal.post.score %></td>
</tr>
<% end %>
</tbody>
</table>
<div id="c-moderator-dashboards">
<div id="a-show">
<h1>Moderator Dashboard</h1>
<table width="100%" class="striped">
<caption>User Records</caption>
<thead>
<tr>
<th>User</th>
<th>Message</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<% UserRecord.recent(@dashboard.min_date).all(:order => "id desc").each do |record| %>
<tr class="user-record-score-<%= record.score %>">
<td><%= link_to(record.user.name, :controller => "user", :action => "show", :id => record.user_id) %></td>
<td><%= format_text(record.body) %></td>
<td><%= time_ago_in_words(record.created_at) %> ago</td>
</tr>
<% end %>
</tbody>
</table>
<table width="100%" class="striped">
<caption>Mod Actions</caption>
<thead>
<tr>
<th>Moderator</th>
<th>Description</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2"><%= link_to "View all actions", :controller => "mod_action", :action => "index" %></td>
</tr>
</tfoot>
<tbody>
<% ModAction.all(:order => "id desc", :limit => 10).each do |mod_action| %>
<tr>
<td><%= link_to mod_action.user.name, :controller => "user", :action => "show", :id => mod_action.user_id %></td>
<td><%= format_text(mod_action.description) %></td>
</tr>
<% end %>
</tbody>
</table>
<%= render "search" %>
<div id="col1">
<%= render "activity_upload" %>
<%= render "activity_note" %>
<%= render "activity_tag" %>
<%= render "activity_wiki_page" %>
<%= render "activity_artist" %>
<%= render "activity_comment" %>
</div>
<div id="col2">
<%= render "activity_appeal" %>
<%= render "activity_user_feedback" %>
<%= render "activity_mod_action" %>
</div>
</div>
</div>
</div>

View File

@@ -5,17 +5,17 @@ module Danbooru
module ClassMethods
def without_timeout
connection.execute("SET STATEMENT_TIMEOUT = 0")
connection.execute("SET STATEMENT_TIMEOUT = 0") unless Rails.env == "test"
yield
ensure
connection.execute("SET STATEMENT_TIMEOUT = 10000")
connection.execute("SET STATEMENT_TIMEOUT = 5000") unless Rails.env == "test"
end
def with_timeout(n)
connection.execute("SET STATEMENT_TIMEOUT = #{n}")
connection.execute("SET STATEMENT_TIMEOUT = #{n}") unless Rails.env == "test"
yield
ensure
connection.execute("SET STATEMENT_TIMEOUT = 10000")
connection.execute("SET STATEMENT_TIMEOUT = 5000") unless Rails.env == "test"
end
end

View File

@@ -20,6 +20,12 @@ Danbooru::Application.routes.draw do
end
end
end
resources :invitations, :only => [:new, :create, :index, :show]
resources :ip_addrs, :only => [:index, :search] do
collection do
get :search
end
end
end
resources :advertisements do
resources :hits, :controller => "advertisement_hits", :only => [:create]
@@ -57,6 +63,7 @@ Danbooru::Application.routes.draw do
end
resources :jobs
resources :ip_bans
resources :mod_actions
resources :notes do
collection do
get :search

View File

@@ -1818,6 +1818,38 @@ CREATE SEQUENCE janitor_trials_id_seq
ALTER SEQUENCE janitor_trials_id_seq OWNED BY janitor_trials.id;
--
-- Name: mod_actions; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE mod_actions (
id integer NOT NULL,
creator_id integer NOT NULL,
description text NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: mod_actions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE mod_actions_id_seq
START WITH 1
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
--
-- Name: mod_actions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE mod_actions_id_seq OWNED BY mod_actions.id;
--
-- Name: note_versions; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@@ -2678,6 +2710,13 @@ ALTER TABLE ip_bans ALTER COLUMN id SET DEFAULT nextval('ip_bans_id_seq'::regcla
ALTER TABLE janitor_trials ALTER COLUMN id SET DEFAULT nextval('janitor_trials_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE mod_actions ALTER COLUMN id SET DEFAULT nextval('mod_actions_id_seq'::regclass);
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -2938,6 +2977,14 @@ ALTER TABLE ONLY janitor_trials
ADD CONSTRAINT janitor_trials_pkey PRIMARY KEY (id);
--
-- Name: mod_actions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY mod_actions
ADD CONSTRAINT mod_actions_pkey PRIMARY KEY (id);
--
-- Name: note_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@@ -5171,4 +5218,6 @@ INSERT INTO schema_migrations (version) VALUES ('20110328215701');
INSERT INTO schema_migrations (version) VALUES ('20110607194023');
INSERT INTO schema_migrations (version) VALUES ('20110717010705');
INSERT INTO schema_migrations (version) VALUES ('20110717010705');
INSERT INTO schema_migrations (version) VALUES ('20110722211855');

View File

@@ -0,0 +1,9 @@
class CreateModActions < ActiveRecord::Migration
def change
create_table :mod_actions do |t|
t.column :creator_id, :integer, :null => false
t.column :description, :text, :null => false
t.timestamps
end
end
end

View File

@@ -0,0 +1,4 @@
Factory.define(:mod_action) do |f|
f.creator {|x| x.association(:user)}
f.description "1234"
end

View File

@@ -1,11 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@@ -0,0 +1,133 @@
require 'test_helper'
module Moderator
class DashboardsControllerTest < ActionController::TestCase
context "The moderator dashboards controller" do
setup do
@admin = Factory.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
end
context "show action" do
context "for mod actions" do
setup do
@mod_action = Factory.create(:mod_action)
end
should "render" do
assert_equal(1, ModAction.count)
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for user feedbacks" do
setup do
@feedback = Factory.create(:user_feedback)
end
should "render" do
assert_equal(1, UserFeedback.count)
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for wiki pages" do
setup do
@wiki_page = Factory.create(:wiki_page)
end
should "render" do
assert_equal(1, WikiPageVersion.count)
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for tags and uploads" do
setup do
@post = Factory.create(:post)
end
should "render" do
assert_equal(1, PostVersion.count)
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for notes"do
setup do
@post = Factory.create(:post)
@note = Factory.create(:note, :post_id => @post.id)
end
should "render" do
assert_equal(1, NoteVersion.count)
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for comments" do
setup do
@users = (0..5).map {Factory.create(:user)}
CurrentUser.scoped(@users[0], "1.2.3.4") do
@comment = Factory.create(:comment)
end
@users.each do |user|
CurrentUser.scoped(user, "1.2.3.4") do
@comment.vote!(-1)
end
end
end
should "render" do
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for artists" do
setup do
@artist = Factory.create(:artist)
end
should "render" do
get :show, {}, {:user_id => @admin.id}
assert_equal(1, ArtistVersion.count)
assert_response :success
end
end
context "for flags" do
setup do
@post = Factory.create(:post)
@post.flag!("blah")
end
should "render" do
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
context "for appeals" do
setup do
@post = Factory.create(:post, :is_deleted => true)
@post.appeal!("blah")
end
should "render" do
get :show, {}, {:user_id => @admin.id}
assert_response :success
end
end
end
end
end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class ModActionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end