Screened Urls page shows results for each domain instead of each url

This commit is contained in:
Neil Lalonde 2013-11-04 16:24:32 -05:00
parent 0b79636b99
commit bd9b85f076
8 changed files with 33 additions and 9 deletions

View File

@ -7,12 +7,11 @@
<div class='table screened-urls'> <div class='table screened-urls'>
<div class="heading-container"> <div class="heading-container">
<div class="col heading first url">{{i18n admin.logs.screened_urls.url}}</div> <div class="col heading first domain">{{i18n admin.logs.screened_urls.domain}}</div>
<div class="col heading action">{{i18n admin.logs.action}}</div> <div class="col heading action">{{i18n admin.logs.action}}</div>
<div class="col heading match_count">{{i18n admin.logs.match_count}}</div> <div class="col heading match_count">{{i18n admin.logs.match_count}}</div>
<div class="col heading last_match_at">{{i18n admin.logs.last_match_at}}</div> <div class="col heading last_match_at">{{i18n admin.logs.last_match_at}}</div>
<div class="col heading created_at">{{i18n admin.logs.created_at}}</div> <div class="col heading created_at">{{i18n admin.logs.created_at}}</div>
<div class="col heading ip_address">{{i18n admin.logs.ip_address}}</div>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>

View File

@ -1,9 +1,8 @@
<div class="col first url"> <div class="col first domain">
<div class="overflow-ellipsis" {{bindAttr title="url"}}>{{url}}</div> <div class="overflow-ellipsis" {{bindAttr title="domain"}}>{{domain}}</div>
</div> </div>
<div class="col action">{{actionName}}</div> <div class="col action">{{actionName}}</div>
<div class="col match_count">{{match_count}}</div> <div class="col match_count">{{match_count}}</div>
<div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div> <div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div>
<div class="col created_at">{{unboundAgeWithTooltip created_at}}</div> <div class="col created_at">{{unboundAgeWithTooltip created_at}}</div>
<div class="col ip_address">{{ip_address}}</div>
<div class="clearfix"></div> <div class="clearfix"></div>

View File

@ -756,7 +756,7 @@ table.api-keys {
} }
.screened-emails, .screened-urls, .screened-ip-addresses { .screened-emails, .screened-urls, .screened-ip-addresses {
.email, .url { .email, .url, .domain {
width: 300px; width: 300px;
} }
.action, .match_count, .last_match_at, .created_at { .action, .match_count, .last_match_at, .created_at {

View File

@ -1,8 +1,8 @@
class Admin::ScreenedUrlsController < Admin::AdminController class Admin::ScreenedUrlsController < Admin::AdminController
def index def index
screened_urls = ScreenedUrl.limit(200).order('last_match_at desc').to_a screened_urls = ScreenedUrl.select("domain, sum(match_count) as match_count, max(last_match_at) as last_match_at, min(created_at) as created_at").group(:domain).to_a
render_serialized(screened_urls, ScreenedUrlSerializer) render_serialized(screened_urls, GroupedScreenedUrlSerializer)
end end
end end

View File

@ -18,7 +18,7 @@ class ScreenedUrl < ActiveRecord::Base
def normalize def normalize
self.url = ScreenedUrl.normalize_url(self.url) if self.url self.url = ScreenedUrl.normalize_url(self.url) if self.url
self.domain = self.domain.downcase if self.domain self.domain = self.domain.downcase.sub(/^www\./, '') if self.domain
end end
def self.watch(url, domain, opts={}) def self.watch(url, domain, opts={})

View File

@ -0,0 +1,11 @@
class GroupedScreenedUrlSerializer < ApplicationSerializer
attributes :domain,
:action,
:match_count,
:last_match_at,
:created_at
def action
'do_nothing'
end
end

View File

@ -1270,6 +1270,7 @@ en:
title: "Screened URLs" title: "Screened URLs"
description: "The URLs listed here were used in posts by users who have been identified as spammers." description: "The URLs listed here were used in posts by users who have been identified as spammers."
url: "URL" url: "URL"
domain: "Domain"
screened_ips: screened_ips:
title: "Screened IPs" title: "Screened IPs"
description: 'IP addresses that are being watched. Use "Allow" to whitelist IP addresses.' description: 'IP addresses that are being watched. Use "Allow" to whitelist IP addresses.'

View File

@ -58,6 +58,20 @@ describe ScreenedUrl do
record2.should be_valid record2.should be_valid
end end
it "strips www. from domains" do
record1 = described_class.new(valid_params.merge(domain: 'www.DuB30.com', url: 'www.DuB30.com/Gems/Gems-of-Power'))
record1.normalize
record1.domain.should == 'dub30.com'
record2 = described_class.new(valid_params.merge(domain: 'WWW.DuB30.cOM', url: 'WWW.DuB30.com/Gems/Gems-of-Power'))
record2.normalize
record2.domain.should == 'dub30.com'
record3 = described_class.new(valid_params.merge(domain: 'www.trolls.spammers.com', url: 'WWW.DuB30.com/Gems/Gems-of-Power'))
record3.normalize
record3.domain.should == 'trolls.spammers.com'
end
it "doesn't modify the url argument" do it "doesn't modify the url argument" do
expect { expect {
described_class.new(valid_params).normalize described_class.new(valid_params).normalize