Skip to content

Commit

Permalink
Avoid duplicates of special domains when showing full notice version
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Sep 5, 2022
1 parent d21e3e5 commit 83bea79
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 55 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). It uses [CalVer](https://calver.org/) as of May 2019.

## [22.09a](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.09a) - 2022-09-05
### Fixed
* Fixed duplicates of `special domains` when showing the full notice version.

## [22.09](https://github.com/berkmancenter/lumendatabase/releases/tag/2022.09) - 2022-09-05
### Added
* Introduced special domains.
Expand Down
11 changes: 2 additions & 9 deletions app/helpers/notices_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module NoticesHelper
# Determines whether 'click to request access' should be an option.
# Yes, the messy function signature implies there is a lot going on with the
# business logic.
def access_requestable?(notice, show_original, show_infringing)
def access_requestable?(notice, show_copyrighted, show_infringing)
[
show_original || show_infringing,
show_copyrighted || show_infringing,
# Additional access cannot be requested for confidential court orders
# as there is nothing further to display.
!confidential_order?(notice),
Expand Down Expand Up @@ -130,13 +130,6 @@ def placeholder_kind(user, role)
{ selected: user.entity.kind }
end

def work_url(url)
return url if SpecialDomain.where('? ~~* domain_name', url).where("why_special ? 'full_urls_only_for_researchers'").none? ||
(Current.user && (Current.user.role?(Role.researcher) || Current.user.role?(Role.super_admin)))

Work.fqdn_from_url(url)
end

private

def confidential_order?(notice)
Expand Down
1 change: 1 addition & 0 deletions app/models/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Url
include ValidatesUrls

attr_reader :url_original
attr_accessor :only_fqdn

def [](index)
self.instance_variable_get("@#{index}")
Expand Down
32 changes: 32 additions & 0 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def self.fqdn_from_url(url)
fqdn
end

def infringing_urls_public
filter_urls(infringing_urls)
end

def copyrighted_urls_public
filter_urls(copyrighted_urls)
end

# == Private Methods =========================================================
private

Expand Down Expand Up @@ -167,4 +175,28 @@ def valid_url(type, params)
def not_valid_url_return(type)
type.new(url: 'invalid')
end

def filter_urls(url_instances)
filtered_raw_urls = []
fqdns = []
user_allowed = (Current.user && (Current.user.role?(Role.researcher) || Current.user.role?(Role.super_admin)))

url_instances.each do |url_instance|
just_url = url_instance.url

filtered_raw_urls << url_instance and next if SpecialDomain.where('? ~~* domain_name', just_url).where("why_special ? 'full_urls_only_for_researchers'").none? ||
user_allowed

fqdn = Work.fqdn_from_url(just_url)

next if fqdns.include?(fqdn)

fqdns << fqdn
url_instance.url = fqdn
url_instance.only_fqdn = true
filtered_raw_urls << url_instance
end

filtered_raw_urls.uniq
end
end
4 changes: 2 additions & 2 deletions app/views/notices/_counterfeit_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

<%= render 'works_urls',
work: work,
original_title: 'Original URLs:',
copyrighted_title: 'Original URLs:',
infringing_title: 'Allegedly Infringing Counterfeit URLs:',
show_original: false,
show_copyrighted: false,
show_infringing: true
%>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notices/_counternotice_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<%= render 'works_urls',
work: work,
original_title: 'Original URLs:',
copyrighted_title: 'Original URLs:',
infringing_title: 'Allegedly Infringing URLs:',
show_original: true,
show_copyrighted: true,
show_infringing: true
%>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notices/_court_order_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= render 'works_urls',
work: work,
infringing_title: 'Targeted URLs:',
show_original: false,
show_copyrighted: false,
show_infringing: true
%>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notices/_data_protection_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= render 'works_urls',
work: work,
infringing_title: 'Location of Some of the Material Requested for Removal:',
show_original: false,
show_copyrighted: false,
show_infringing: true
%>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notices/_defamation_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= render 'works_urls',
work: work,
infringing_title: 'URLs of Allegedly Defamatory Material:',
show_original: false,
show_copyrighted: false,
show_infringing: true
%>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notices/_dmca_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<%= render 'works_urls',
work: work,
original_title: 'Original URLs:',
copyrighted_title: 'Original URLs:',
infringing_title: 'Allegedly Infringing URLs:',
show_original: true,
show_copyrighted: true,
show_infringing: true
%>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notices/_government_request_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

<%= render 'works_urls',
work: work,
original_title: 'URLs of original work:',
copyrighted_title: 'URLs of original work:',
infringing_title: 'URLs mentioned in request:',
show_original: true,
show_copyrighted: true,
show_infringing: true
%>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notices/_law_enforcement_request_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

<%= render 'works_urls',
work: work,
original_title: 'URLs of original work:',
copyrighted_title: 'URLs of original work:',
infringing_title: 'URLs mentioned in request:',
show_original: true,
show_copyrighted: true,
show_infringing: true
%>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notices/_other_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<%= render 'works_urls',
work: work,
original_title: 'URLs of original work:',
copyrighted_title: 'URLs of original work:',
infringing_title: 'Problematic URLs:',
show_original: true,
show_copyrighted: true,
show_infringing: true
%>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/notices/_private_information_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<%= render 'works_urls',
work: work,
original_title: 'URLs of original work:',
copyrighted_title: 'URLs of original work:',
infringing_title: 'URLs with private information:',
show_original: true,
show_copyrighted: true,
show_infringing: true
%>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/notices/_trademark_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= render 'works_urls',
work: work,
infringing_title: 'Allegedly Infringing URLs:',
show_original: false,
show_copyrighted: false,
show_infringing: true
%>
<% end %>
Expand Down
35 changes: 7 additions & 28 deletions app/views/notices/_works_urls.html.erb
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
<% if can_see_full_notice_version?(@notice) %>
<% if show_original %>
<div class="row">
<span class="label original-title"><%= original_title %></span>
<ol class="list original-urls">
<% if work.copyrighted_urls.each do |url| %>
<%= content_tag_for(:li, url) do %><%= work_url(url.url) %><% end %>
<% end.empty? %>
No copyrighted URLs were submitted.
<% end %>
</ol>
</div>
<% end %>
<% copyrighted_title = copyrighted_title || '' %>

<% if show_infringing %>
<div class="row">
<span class="label infringing-title"><%= infringing_title %></span>
<ol class="list infringing-urls">
<% if work.infringing_urls.each do |url| %>
<%= content_tag_for(:li, url) do %><%= work_url(url.url) %><% end %>
<% end.empty? %>
No infringing URLs were submitted.
<% end %>
</ol>
</div>
<% end %>
<% if can_see_full_notice_version?(@notice) %>
<%= render 'works_urls_type_list', type: 'copyrighted', show_copyrighted: show_copyrighted, copyrighted_title: copyrighted_title, work: work %>
<%= render 'works_urls_type_list', type: 'infringing', show_infringing: show_infringing, infringing_title: infringing_title, work: work %>
<% else %>
<% if show_original %>
<% if show_copyrighted %>
<div class="row">
<span class="label original-title"><%= original_title %></span>
<span class="label original-title"><%= copyrighted_title %></span>
<ol class="list original-urls">
<% if work.copyrighted_urls_counted_by_fqdn.each do |fqdn| %>
<li class="copyrighted_url"><%= fqdn[:fqdn] %> - <%= fqdn[:count] %> <%= 'URL'.pluralize(fqdn[:count]) %></li>
Expand Down Expand Up @@ -60,7 +39,7 @@
<% end %>
</div>
<% else %>
<% if access_requestable?(@notice, show_original, show_infringing) %>
<% if access_requestable?(@notice, show_copyrighted, show_infringing) %>
<div class="row">
<p><%= link_to 'Click here', request_access_notice_path(@notice) %> to request access and see full URLs.</p>
</div>
Expand Down
17 changes: 17 additions & 0 deletions app/views/notices/_works_urls_type_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% if binding.local_variable_get("show_#{type}") %>
<div class="row">
<span class="label <%= type %>-title"><%= binding.local_variable_get("#{type}_title") %></span>
<ol class="list <%= type %>-urls">
<% if work.send("#{type}_urls_public").each do |url_instance| %>
<li class="<%= type %>_url">
<%= url_instance.url %>
<% if url_instance.only_fqdn %>
<i class="tooltipster gg-lumen gg-info" title="You can only see the domain name of this url, the full version of the url is available only for logged-in users with specific permissions."></i>
<% end %>
</li>
<% end.empty? %>
No <%= type %> URLs were submitted.
<% end %>
</ol>
</div>
<% end %>

0 comments on commit 83bea79

Please sign in to comment.