Skip to content

Commit

Permalink
Screened Urls page shows results for each domain instead of each url
Browse files Browse the repository at this point in the history
  • Loading branch information
nlalonde committed Nov 4, 2013
1 parent 0b79636 commit bd9b85f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

<div class='table screened-urls'>
<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 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 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>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<div class="col first url">
<div class="overflow-ellipsis" {{bindAttr title="url"}}>{{url}}</div>
<div class="col first domain">
<div class="overflow-ellipsis" {{bindAttr title="domain"}}>{{domain}}</div>
</div>
<div class="col action">{{actionName}}</div>
<div class="col match_count">{{match_count}}</div>
<div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div>
<div class="col created_at">{{unboundAgeWithTooltip created_at}}</div>
<div class="col ip_address">{{ip_address}}</div>
<div class="clearfix"></div>
2 changes: 1 addition & 1 deletion app/assets/stylesheets/common/admin/admin_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ table.api-keys {
}

.screened-emails, .screened-urls, .screened-ip-addresses {
.email, .url {
.email, .url, .domain {
width: 300px;
}
.action, .match_count, .last_match_at, .created_at {
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/screened_urls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Admin::ScreenedUrlsController < Admin::AdminController

def index
screened_urls = ScreenedUrl.limit(200).order('last_match_at desc').to_a
render_serialized(screened_urls, ScreenedUrlSerializer)
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, GroupedScreenedUrlSerializer)
end

end
2 changes: 1 addition & 1 deletion app/models/screened_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ScreenedUrl < ActiveRecord::Base

def normalize
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

def self.watch(url, domain, opts={})
Expand Down
11 changes: 11 additions & 0 deletions app/serializers/grouped_screened_url_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class GroupedScreenedUrlSerializer < ApplicationSerializer
attributes :domain,
:action,
:match_count,
:last_match_at,
:created_at

def action
'do_nothing'
end
end
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ en:
title: "Screened URLs"
description: "The URLs listed here were used in posts by users who have been identified as spammers."
url: "URL"
domain: "Domain"
screened_ips:
title: "Screened IPs"
description: 'IP addresses that are being watched. Use "Allow" to whitelist IP addresses.'
Expand Down
14 changes: 14 additions & 0 deletions spec/models/screened_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@
record2.should be_valid
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
expect {
described_class.new(valid_params).normalize
Expand Down

0 comments on commit bd9b85f

Please sign in to comment.