Skip to content

Commit

Permalink
Redact urls for all types of notices
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Mar 14, 2024
1 parent e0ff495 commit 95bfd24
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
24 changes: 24 additions & 0 deletions app/models/notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def attorney

def auto_redact
InstanceRedactor.new.redact(self)
redact_urls
end

def mark_for_review
Expand Down Expand Up @@ -562,4 +563,27 @@ def set_default_jurisdiction

self.jurisdiction_list = [sender.country_code]
end

def redact_urls
custom_works_redactors = [
Redactors::SsnRedactor.new,
Redactors::EmailRedactor.new
]

instance_redactor = InstanceRedactor.new(
custom_works_redactors
)

works.each do |work|
instance_redactor.redact(work, %w[description])

work.infringing_urls.each do |url|
instance_redactor.redact(url, %w[url])
end

work.copyrighted_urls.each do |url|
instance_redactor.redact(url, %w[url])
end
end
end
end
1 change: 1 addition & 0 deletions app/models/other.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def to_partial_path
def auto_redact
InstanceRedactor.new.redact(self)
Redactors::GoogleSenderRedactor.new.redact(self)
redact_urls
end

def as_indexed_json(_options)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/dmca_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
notice = DMCA.new
redactor = InstanceRedactor.new
expect(redactor).to receive(:redact).with(notice)
expect(InstanceRedactor).to receive(:new).and_return(redactor)
expect(InstanceRedactor).to receive(:new).exactly(2).times.and_return(redactor)

notice.auto_redact
end
Expand Down
19 changes: 19 additions & 0 deletions spec/models/notice_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@
expect(n.body).not_to include '123-45-6789'
end

it 'redacts urls' do
recipient_names = ['Google', 'Google, Inc.', 'Google LLC', 'YouTube LLC']
notice = create(:dmca, :with_facet_data)

notice.works = [
Work.new(
infringing_urls: [
InfringingUrl.new(url: 'yo@example.com')
]
)
]

notice.auto_redact
notice.save

expect(notice.works.first.infringing_urls.first.url).to eq Lumen::REDACTION_MASK
expect(notice.works.first.infringing_urls.first.url_original).to eq 'yo@example.com'
end

it 'sets submitter if unset' do
user = create(:user, :with_entity)
n = NoticeBuilder.new(CourtOrder, default_notice_hash, user).build
Expand Down

0 comments on commit 95bfd24

Please sign in to comment.