From 83bea79b7de60a68c95dd458e36b18f356539d08 Mon Sep 17 00:00:00 2001 From: Peter Hankiewicz Date: Mon, 5 Sep 2022 19:19:30 +0200 Subject: [PATCH] Avoid duplicates of special domains when showing full notice version --- CHANGELOG.md | 4 +++ app/helpers/notices_helper.rb | 11 ++---- app/models/url.rb | 1 + app/models/work.rb | 32 +++++++++++++++++ app/views/notices/_counterfeit_works.html.erb | 4 +-- .../notices/_counternotice_works.html.erb | 4 +-- app/views/notices/_court_order_works.html.erb | 2 +- .../notices/_data_protection_works.html.erb | 2 +- app/views/notices/_defamation_works.html.erb | 2 +- app/views/notices/_dmca_works.html.erb | 4 +-- .../_government_request_works.html.erb | 4 +-- .../_law_enforcement_request_works.html.erb | 4 +-- app/views/notices/_other_works.html.erb | 4 +-- .../_private_information_works.html.erb | 4 +-- app/views/notices/_trademark_works.html.erb | 2 +- app/views/notices/_works_urls.html.erb | 35 ++++--------------- .../notices/_works_urls_type_list.html.erb | 17 +++++++++ 17 files changed, 81 insertions(+), 55 deletions(-) create mode 100644 app/views/notices/_works_urls_type_list.html.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index 28d51353d..632b3317b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/app/helpers/notices_helper.rb b/app/helpers/notices_helper.rb index 45fc362c7..76b26a322 100644 --- a/app/helpers/notices_helper.rb +++ b/app/helpers/notices_helper.rb @@ -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), @@ -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) diff --git a/app/models/url.rb b/app/models/url.rb index 9e60f9bd3..b4f9c9061 100644 --- a/app/models/url.rb +++ b/app/models/url.rb @@ -6,6 +6,7 @@ class Url include ValidatesUrls attr_reader :url_original + attr_accessor :only_fqdn def [](index) self.instance_variable_get("@#{index}") diff --git a/app/models/work.rb b/app/models/work.rb index 6e12f6a8e..f59087d38 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -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 @@ -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 diff --git a/app/views/notices/_counterfeit_works.html.erb b/app/views/notices/_counterfeit_works.html.erb index 002417d4d..d0dd2e046 100644 --- a/app/views/notices/_counterfeit_works.html.erb +++ b/app/views/notices/_counterfeit_works.html.erb @@ -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 %> diff --git a/app/views/notices/_counternotice_works.html.erb b/app/views/notices/_counternotice_works.html.erb index bdfbea693..fc27cf862 100644 --- a/app/views/notices/_counternotice_works.html.erb +++ b/app/views/notices/_counternotice_works.html.erb @@ -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 %> diff --git a/app/views/notices/_court_order_works.html.erb b/app/views/notices/_court_order_works.html.erb index 9ba205f04..ff8d70b75 100644 --- a/app/views/notices/_court_order_works.html.erb +++ b/app/views/notices/_court_order_works.html.erb @@ -12,7 +12,7 @@ <%= render 'works_urls', work: work, infringing_title: 'Targeted URLs:', - show_original: false, + show_copyrighted: false, show_infringing: true %> <% end %> diff --git a/app/views/notices/_data_protection_works.html.erb b/app/views/notices/_data_protection_works.html.erb index 6f67a771f..0391dda25 100644 --- a/app/views/notices/_data_protection_works.html.erb +++ b/app/views/notices/_data_protection_works.html.erb @@ -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 %> diff --git a/app/views/notices/_defamation_works.html.erb b/app/views/notices/_defamation_works.html.erb index adee94788..0b364ce85 100644 --- a/app/views/notices/_defamation_works.html.erb +++ b/app/views/notices/_defamation_works.html.erb @@ -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 %> diff --git a/app/views/notices/_dmca_works.html.erb b/app/views/notices/_dmca_works.html.erb index bdfbea693..fc27cf862 100644 --- a/app/views/notices/_dmca_works.html.erb +++ b/app/views/notices/_dmca_works.html.erb @@ -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 %> diff --git a/app/views/notices/_government_request_works.html.erb b/app/views/notices/_government_request_works.html.erb index 5b663bd39..1a8b9346b 100644 --- a/app/views/notices/_government_request_works.html.erb +++ b/app/views/notices/_government_request_works.html.erb @@ -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 %> diff --git a/app/views/notices/_law_enforcement_request_works.html.erb b/app/views/notices/_law_enforcement_request_works.html.erb index 6ac705ca3..8a35908b4 100644 --- a/app/views/notices/_law_enforcement_request_works.html.erb +++ b/app/views/notices/_law_enforcement_request_works.html.erb @@ -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 %> diff --git a/app/views/notices/_other_works.html.erb b/app/views/notices/_other_works.html.erb index a3b86e5e9..c5dbad780 100644 --- a/app/views/notices/_other_works.html.erb +++ b/app/views/notices/_other_works.html.erb @@ -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 %> diff --git a/app/views/notices/_private_information_works.html.erb b/app/views/notices/_private_information_works.html.erb index e2168ac66..4f9511e52 100644 --- a/app/views/notices/_private_information_works.html.erb +++ b/app/views/notices/_private_information_works.html.erb @@ -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 %> diff --git a/app/views/notices/_trademark_works.html.erb b/app/views/notices/_trademark_works.html.erb index 8cd8d116d..e53bcd711 100644 --- a/app/views/notices/_trademark_works.html.erb +++ b/app/views/notices/_trademark_works.html.erb @@ -13,7 +13,7 @@ <%= render 'works_urls', work: work, infringing_title: 'Allegedly Infringing URLs:', - show_original: false, + show_copyrighted: false, show_infringing: true %> <% end %> diff --git a/app/views/notices/_works_urls.html.erb b/app/views/notices/_works_urls.html.erb index ca8a7aa17..7cfaff32a 100644 --- a/app/views/notices/_works_urls.html.erb +++ b/app/views/notices/_works_urls.html.erb @@ -1,33 +1,12 @@ -<% if can_see_full_notice_version?(@notice) %> - <% if show_original %> -
- <%= original_title %> -
    - <% 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 %> -
-
- <% end %> +<% copyrighted_title = copyrighted_title || '' %> - <% if show_infringing %> -
- <%= infringing_title %> -
    - <% 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 %> -
-
- <% 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 %>
- <%= original_title %> + <%= copyrighted_title %>
    <% if work.copyrighted_urls_counted_by_fqdn.each do |fqdn| %>
  1. <%= fqdn[:fqdn] %> - <%= fqdn[:count] %> <%= 'URL'.pluralize(fqdn[:count]) %>
  2. @@ -60,7 +39,7 @@ <% end %>
<% else %> - <% if access_requestable?(@notice, show_original, show_infringing) %> + <% if access_requestable?(@notice, show_copyrighted, show_infringing) %>

<%= link_to 'Click here', request_access_notice_path(@notice) %> to request access and see full URLs.

diff --git a/app/views/notices/_works_urls_type_list.html.erb b/app/views/notices/_works_urls_type_list.html.erb new file mode 100644 index 000000000..338ca43c5 --- /dev/null +++ b/app/views/notices/_works_urls_type_list.html.erb @@ -0,0 +1,17 @@ +<% if binding.local_variable_get("show_#{type}") %> +
+ <%= binding.local_variable_get("#{type}_title") %> +
    + <% if work.send("#{type}_urls_public").each do |url_instance| %> +
  1. + <%= url_instance.url %> + <% if url_instance.only_fqdn %> + + <% end %> +
  2. + <% end.empty? %> + No <%= type %> URLs were submitted. + <% end %> +
+
+<% end %>