From deb6d121087765f3d3ad9cc4fac62c6670692276 Mon Sep 17 00:00:00 2001 From: Yuki Date: Thu, 23 Jul 2015 23:08:42 +0530 Subject: [PATCH] Moderation Priority + IP --- app/controllers/moderation_controller.rb | 48 +++++++++++++++++++ app/views/moderation/_actions.html.haml | 4 ++ .../moderation/_moderation_nav.html.haml | 1 + .../moderation/_moderation_tabs.html.haml | 1 + app/views/moderation/_moderationbox.html.haml | 18 ++++--- app/views/moderation/_userbox.html.haml | 26 ++++++++++ app/views/moderation/priority.html.haml | 16 +++++++ config/routes.rb | 2 + 8 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 app/views/moderation/_actions.html.haml create mode 100644 app/views/moderation/_userbox.html.haml create mode 100644 app/views/moderation/priority.html.haml diff --git a/app/controllers/moderation_controller.rb b/app/controllers/moderation_controller.rb index 5e4ef475..38c28867 100644 --- a/app/controllers/moderation_controller.rb +++ b/app/controllers/moderation_controller.rb @@ -9,4 +9,52 @@ class ModerationController < ApplicationController Report.where(deleted: false).where('LOWER(type) = ?', "reports::#{@type}").reverse_order end end + + def priority + @user_id = params[:user_id] + if @user_id.nil? + @users = {} + Report.where(deleted: false).each do |report| + target = if report.target.is_a? User + report.target + else + next if report.target.user.nil? + report.target.user + end + + @users[target] ||= 0 + @users[target] += 1 + end + + @users = @users.sort_by do |k, v| + v + end.reverse.to_h + else + @user_id = @user_id.to_i + @type = 'all' + @reports = [] + Report.where(deleted: false).each do |report| + if report.target.is_a? User + @reports.push report if report.target.id == @user_id + else + next if report.target.user.nil? + @reports.push report if report.target.user.id == @user_id + end + end + + @target_user = User.find(@user_id) + render template: 'moderation/index' + end + end + + def ip + @user_id = params[:user_id] + @host = User.find(@user_id) + @users = [] + return if @host.nil? + @users = User.where('(current_sign_in_ip = ? OR last_sign_in_ip = ?) AND id != ?', @host.current_sign_in_ip, @host.last_sign_in_ip, @user_id) + @users.unshift @host + + render template: 'moderation/priority' + end end diff --git a/app/views/moderation/_actions.html.haml b/app/views/moderation/_actions.html.haml new file mode 100644 index 00000000..20c21cd9 --- /dev/null +++ b/app/views/moderation/_actions.html.haml @@ -0,0 +1,4 @@ +%a.btn.btn-default.btn-block{href: moderation_priority_path(user.id)} + View reports relating to user +%a.btn.btn-default.btn-block{href: moderation_ip_path(user.id)} + View users with same IP diff --git a/app/views/moderation/_moderation_nav.html.haml b/app/views/moderation/_moderation_nav.html.haml index 081abced..434c725a 100644 --- a/app/views/moderation/_moderation_nav.html.haml +++ b/app/views/moderation/_moderation_nav.html.haml @@ -14,3 +14,4 @@ = nav_entry t('views.general.comment').pluralize(2), moderation_path('comment') = nav_entry t('views.general.user').pluralize(2) , moderation_path('user') = nav_entry t('views.general.question').pluralize(2), moderation_path('question') + = nav_entry 'Priority', moderation_priority_path diff --git a/app/views/moderation/_moderation_tabs.html.haml b/app/views/moderation/_moderation_tabs.html.haml index f933578b..1ebce01a 100644 --- a/app/views/moderation/_moderation_tabs.html.haml +++ b/app/views/moderation/_moderation_tabs.html.haml @@ -6,3 +6,4 @@ = list_group_item t('views.general.comment').pluralize(2), moderation_path('comment') = list_group_item t('views.general.user').pluralize(2), moderation_path('user') = list_group_item t('views.general.question').pluralize(2), moderation_path('question') + = list_group_item 'Priority', moderation_priority_path diff --git a/app/views/moderation/_moderationbox.html.haml b/app/views/moderation/_moderationbox.html.haml index 60676dc8..c2829837 100644 --- a/app/views/moderation/_moderationbox.html.haml +++ b/app/views/moderation/_moderationbox.html.haml @@ -12,18 +12,24 @@ %p %b= t 'views.moderation.moderationbox.reason' %br - - (report.reason || "No reason provided.").lines.each do |reason| - - next unless reason.strip.length > 0 - = reason.strip - %br + - if report.reason.nil? or report.reason.strip.blank? + No reason provided + - else + - report.reason.lines.each do |reason| + - next if reason.strip.blank? + = reason.strip .row - .col-md-6.col-sm-4.col-xs-6.text-left + .col-md-8.col-sm-8.col-xs-8.text-left %a.btn.btn-primary{href: content_url(report)} = t('views.moderation.moderationbox.view', content: report.type.sub('Reports::', '')) - if report.target.respond_to? :user and not report.target.user.nil? %a.btn.btn-primary{href: show_user_profile_path(report.target.user.screen_name)} = t('views.moderation.moderationbox.view', content: t('views.general.user')) - .col-md-6.col-sm-8.col-xs-6.text-right + %a.btn.btn-primary{href: moderation_priority_path(report.target.user.id)} + Reports + %a.btn.btn-primary{href: moderation_ip_path(report.target.user.id)} + IP + .col-md-4.col-sm-4.col-xs-4.text-right %span.mod-count{id: "mod-count-#{report.id}"} = report.votes .btn-group diff --git a/app/views/moderation/_userbox.html.haml b/app/views/moderation/_userbox.html.haml new file mode 100644 index 00000000..27136f9a --- /dev/null +++ b/app/views/moderation/_userbox.html.haml @@ -0,0 +1,26 @@ +.panel.panel-default + .panel-body + .media + .pull-left + %img.img-rounded.profile--img{src: gravatar_url(user)} + .media-body + - if user.display_name.blank? + %h2 + %a{href: show_user_profile_path(user.screen_name)} + = user.screen_name + - else + %h2.profile--displayname + %a{href: show_user_profile_path(user.screen_name)} + = user.display_name + %h4.text-muted.profile--username= user.screen_name + .row + .col-md-12.col-sm-12.col-xs-12 + - unless count.nil? + %h4.entry-text#asked-count + = count + = 'Report'.pluralize(user.asked_count) + %br + %br + - else + %br + = render 'actions', user: user diff --git a/app/views/moderation/priority.html.haml b/app/views/moderation/priority.html.haml new file mode 100644 index 00000000..0291c89d --- /dev/null +++ b/app/views/moderation/priority.html.haml @@ -0,0 +1,16 @@ +- provide(:title, generate_title("Moderation")) += render 'moderation/moderation_nav' +.container.j2-page + .row + = render 'moderation/moderation_tabs' + .col-md-9.col-sm-9.col-xs-12 + %h2 + - if @host.nil? + Users sorted by reports + - else + Users with the same IP + #users + .row + - @users.each do |u, c| + .col-md-4.col-sm-12col-xs-12 + = render 'moderation/userbox', user: u, count: c diff --git a/config/routes.rb b/config/routes.rb index 6b00da95..eef8a30f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,8 @@ Rails.application.routes.draw do # Moderation panel constraints ->(req) { req.env['warden'].authenticate?(scope: :user) && (req.env['warden'].user.mod?) } do + match '/moderation/priority(/:user_id)', to: 'moderation#priority', via: :get, as: :moderation_priority + match '/moderation/ip/:user_id', to: 'moderation#ip', via: :get, as: :moderation_ip match '/moderation(/:type)', to: 'moderation#index', via: :get, as: :moderation, defaults: {type: 'all'} namespace :ajax do match '/mod/destroy_report', to: 'moderation#destroy_report', via: :post, as: :mod_destroy_report