Skip to content

Commit

Permalink
fix(page handling): Only show restriction warning on doc1 pages
Browse files Browse the repository at this point in the history
Previously, we saw that our regexes could be a little over-zealous,
matching on pages that have nothing to do with downloading documents.
This change makes it so they only match on doc1 (or similar) pages.

Fixes: freelawproject/recap#265
  • Loading branch information
mlissner committed Aug 6, 2019
1 parent 7654a64 commit 112853c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 13 additions & 5 deletions spec/ContentDelegateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('The ContentDelegate class', function() {

describe('ContentDelegate constructor', function() {
const expected_url = 'https://ecf.canb.uscourts.gov/cgi-bin/DktRpt.pl?531591';
const restricted_url = 'https://ecf.canb.uscourts.gov/doc1/04503837920';
const expected_path = '/cgi-bin/DktRpt.pl?531591';
const expected_court = 'canb';
const expected_pacer_case_id = '531591';
Expand All @@ -88,6 +89,7 @@ describe('The ContentDelegate class', function() {
it('should flag restriction for Warning!', function () {
const form = document.createElement('form');
const input = document.createElement('input');
input.value = 'View Document';
form.appendChild(input);
document.body.appendChild(form);

Expand All @@ -97,10 +99,10 @@ describe('The ContentDelegate class', function() {
table.appendChild(table_tr);
table_tr.appendChild(table_td);
document.body.appendChild(table);
table_td.textContent = "Warning!";
table_td.textContent = "Warning! Image";

expect(document.body.innerText).not.toContain('will not be uploaded');
const cd = new ContentDelegate(expected_url, expected_path, expected_court,
const cd = new ContentDelegate(restricted_url, expected_path, expected_court,
expected_pacer_case_id, expected_pacer_doc_id, expected_links);
expect(cd.restricted).toBe(true);
expect(document.body.innerText).toContain('will not be uploaded');
Expand All @@ -111,17 +113,22 @@ describe('The ContentDelegate class', function() {
it('should flag restriction for bold restriction', function () {
const form = document.createElement('form');
const input = document.createElement('input');
input.value = 'View Document';
form.appendChild(input);
document.body.appendChild(form);

const table_td = document.createElement('td');
document.body.appendChild(table_td);
table_td.textContent = "Image";

const paragraph = document.createElement('p');
const bold = document.createElement('b');
paragraph.appendChild(bold);
document.body.appendChild(paragraph);
bold.textContent = "SEALED";

expect(document.body.innerText).not.toContain('will not be uploaded');
const cd = new ContentDelegate(expected_url, expected_path, expected_court,
const cd = new ContentDelegate(restricted_url, expected_path, expected_court,
expected_pacer_case_id, expected_pacer_doc_id, expected_links);
expect(cd.restricted).toBe(true);
expect(document.body.innerText).toContain('will not be uploaded');
Expand Down Expand Up @@ -997,13 +1004,14 @@ describe('The ContentDelegate class', function() {
'https://ecf.canb.uscourts.gov/doc1/034031424909',
'https://ecf.canb.uscourts.gov/doc1/034031438754',
];
const expected_url = 'https://ecf.canb.uscourts.gov/cgi-bin/DktRpt.pl?531591';

describe('when there are no valid urls', function() {
let links;
let cd;
beforeEach(function() {
links = linksFromUrls(fake_urls);
cd = new ContentDelegate(null, null, null, null, null, links);
cd = new ContentDelegate(expected_url, null, null, null, null, links);
cd.attachRecapLinkToEligibleDocs();
});

Expand All @@ -1018,7 +1026,7 @@ describe('The ContentDelegate class', function() {
beforeEach(function() {
links = linksFromUrls(urls);
$('body').append(links);
cd = new ContentDelegate(null, null, null, null, null, links);
cd = new ContentDelegate(expected_url, null, null, null, null, links);
cd.pacer_doc_ids = [ 1234 ];
});

Expand Down
6 changes: 6 additions & 0 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ ContentDelegate.prototype.checkRestrictions = function() {
// "document is restricted", "SEALED", or "do not allow it to be seen".
// Case-insensitively.

// The regexes below are pretty broad by design.
// Only trigger this code on doc1 pages.
if (!PACER.isSingleDocumentPage(this.url, document)) {
return false;
}

let restrictedDoc = false;

for (let td of
Expand Down

0 comments on commit 112853c

Please sign in to comment.