Skip to content

Commit 315c0d9

Browse files
authored
Merge pull request #2358 from broadinstitute/jb-redacted-study-page
Adding redacted study page (SCP-6101)
2 parents 3ac643f + ffbb63d commit 315c0d9

File tree

8 files changed

+74
-6
lines changed

8 files changed

+74
-6
lines changed

app/controllers/application_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ class ApplicationController < ActionController::Base
22
include RealIpLogger
33

44
# Error modal contact message
5+
SCP_ZENDESK = 'scp-support@broadinstitute.zendesk.com'.freeze
56
SCP_SUPPORT_EMAIL = "If this error persists, please contact support at:<br /><br />" \
6-
"<a href='mailto:scp-support@broadinstitute.zendesk.com' data-analytics-name='scp-support-email' " \
7-
"class='no-wrap'>scp-support@broadinstitute.zendesk.com</a>"
7+
"<a href='mailto:#{SCP_ZENDESK}' data-analytics-name='scp-support-email' " \
8+
"class='no-wrap'>#{SCP_ZENDESK}</a>"
89

910
###
1011
#

app/controllers/site_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SiteController < ApplicationController
1919
:reviewer_access, :validate_reviewer_access]
2020
before_action :set_cluster_group, only: [:study, :show_user_annotations_form]
2121
before_action :set_selected_annotation, only: [:show_user_annotations_form]
22-
before_action :check_view_permissions, except: [:index, :legacy_study, :get_viewable_studies, :privacy_policy,
22+
before_action :check_view_permissions, except: [:index, :legacy_study, :redacted_study, :get_viewable_studies, :privacy_policy,
2323
:terms_of_service, :log_action, :get_taxon, :get_taxon_assemblies,
2424
:covid19, :record_download_acceptance, :reviewer_access,
2525
:validate_reviewer_access]
@@ -152,6 +152,13 @@ def study
152152
@explore_tab_default = @study.can_visualize?
153153
end
154154

155+
# show a landing page for a redacted study
156+
def redacted_study
157+
unless @study.redacted?
158+
redirect_to view_study_path(accession: @study.accession, study_name: @study.url_safe_name) and return
159+
end
160+
end
161+
155162
def record_download_acceptance
156163
@download_acceptance = DownloadAcceptance.new(download_acceptance_params)
157164
if @download_acceptance.save
@@ -383,6 +390,8 @@ def check_view_permissions
383390
end
384391
elsif !user_signed_in?
385392
authenticate_user!
393+
elsif @study.redacted? && !@study.can_view?(current_user)
394+
redirect_to merge_default_redirect_params(redacted_study_path(@study.accession), scpbr: params[:scpbr]) and return
386395
elsif user_signed_in? && !@study.can_view?(current_user)
387396
alert = "You do not have permission to perform that action. #{SCP_SUPPORT_EMAIL}"
388397
redirect_to merge_default_redirect_params(site_path, scpbr: params[:scpbr]), alert: alert and return

app/javascript/lib/layout-utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export function mitigateStudyOverviewTitleTruncation() {
135135
* Set global header end width, and mitigate long study titles on narrow screens
136136
*/
137137
export function adjustGlobalHeader() {
138-
if (window.SCP.analyticsPageName !== 'site-study') {return}
138+
const allowedPages = ['site-study', 'site-redacted-study']
139+
if (!allowedPages.includes(window.SCP.analyticsPageName)) {return}
139140

140141
// Set min-width of container for menus on help, create study, and sign in / username
141142
const globalHeaderEnd = document.getElementById('scp-navbar-dropdown-collapse')

app/models/study.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,13 +1706,17 @@ def species_list
17061706

17071707
# contact emails for questions about study data. will only use corresponding authors (if present) or help email
17081708
def data_custodians
1709-
authors.corresponding.pluck(:email).presence || ['scp-support@broadinstitute.zendesk.com']
1709+
authors.corresponding.pluck(:email).presence || [ApplicationController::SCP_ZENDESK]
17101710
end
17111711

17121712
def duos_study_url
17131713
"#{DuosRegistrationService.duos_ui_url}/studies/#{duos_study_id}"
17141714
end
17151715

1716+
def redaction_contact_emails
1717+
[user.email, user.organizational_email, authors.corresponding.pluck(:email)].flatten.compact.uniq
1718+
end
1719+
17161720
###
17171721
#
17181722
# DELETE METHODS
@@ -1944,6 +1948,11 @@ def was_just_initialized?(cutoff: nil)
19441948
field_changed_from?(track, :initialized, false) && track.created_at >= (cutoff || 1.second.ago)
19451949
end
19461950

1951+
def redacted?
1952+
last_public_change = last_change_for(:public)
1953+
!public && field_changed_from?(last_public_change, :public, true)
1954+
end
1955+
19471956
# basic Mixpanel props for study state tracking
19481957
def mixpanel_state_props
19491958
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<h3 id="redaction-notice"><%= @study.accession %> has been redacted by the owner.</h3>
2+
<p>
3+
If you are seeing this notice and are attempting to access this study, please contact the study owner(s) for more
4+
information.
5+
</p>
6+
<p>
7+
Click to view contact: <% @study.redaction_contact_emails.each do |email| %>
8+
<%= link_to '#',
9+
class: 'corresponding-study-owner',
10+
data: {
11+
email: Base64.encode64(email), placement: 'top',
12+
},
13+
title: "Send email to contact" do %>
14+
<% end %>
15+
&nbsp;
16+
<% end %>
17+
</p>
18+
19+
<script type="text/javascript" nonce="<%= content_security_policy_script_nonce %>">
20+
$('.corresponding-study-owner').each( function(index) {
21+
window.SCP.renderComponent(this, 'AuthorEmailPopup', { dataEl: this })
22+
})
23+
</script>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234

235235
# data viewing actions
236236
get 'study/:identifier', to: 'site#legacy_study', as: :legacy_study
237+
get 'redacted/:accession', to: 'site#redacted_study', as: :redacted_study
237238
get 'study/:accession/:study_name', to: 'site#study', as: :view_study
238239
get 'study/:accession/:study_name/edit_study_description', to: 'site#edit_study_description', as: :edit_study_description
239240
match 'study/:accession/:study_name/update_settings', to: 'site#update_study_settings', via: [:post, :patch], as: :update_study_settings

test/controllers/site_controller_test.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def teardown
111111
get view_study_path(accession: @study.accession, study_name: @study.url_safe_name)
112112
assert_response 302
113113
follow_redirect!
114-
assert_equal site_path, path
114+
assert_equal redacted_study_path(@study.accession), path
115115
end
116116

117117
test 'should control access to files in private studies' do
@@ -273,4 +273,21 @@ def teardown
273273
assert_select '#home-page-link', 1
274274
HomePageLink.delete_all
275275
end
276+
277+
test 'should load study redaction page' do
278+
# should redirect to study if not redacted
279+
get redacted_study_path(accession: @study.accession)
280+
follow_redirect!
281+
assert_equal view_study_path(accession: @study.accession, study_name: @study.url_safe_name),
282+
path,
283+
'Did not redirect to home page for non-redacted study'
284+
Study.stub :find_by, @study do
285+
@study.stub :redacted?, true do
286+
get redacted_study_path(accession: @study.accession)
287+
assert_response :success
288+
assert_equal redacted_study_path(accession: @study.accession), path
289+
assert_select '#redaction-notice', 1, 'Redacted study message not found on page'
290+
end
291+
end
292+
end
276293
end

test/models/study_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class StudyTest < ActiveSupport::TestCase
3939

4040
teardown do
4141
@user.update(organizational_email: @user.email)
42+
@study.update(public: true) unless @study.public
4243
end
4344

4445
after(:all) do
@@ -286,6 +287,12 @@ class StudyTest < ActiveSupport::TestCase
286287
assert_equal [new_name, new_cluster.name], study.default_cluster_order
287288
end
288289

290+
test 'should indicate study is redacted' do
291+
assert_not @study.redacted?
292+
@study.update(public: false)
293+
assert @study.redacted?
294+
end
295+
289296
test 'should enforce organizational email requirement' do
290297
@study.public = false
291298
assert @study.valid?

0 commit comments

Comments
 (0)