Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
c7a937a
Add SubmissionObserver object
ItIsJordan Dec 18, 2024
d7f66c9
SubmissionObserver functionality
ItIsJordan Dec 18, 2024
d261bbb
Add observer_key request var functionality to /records/int
ItIsJordan Dec 18, 2024
949c59d
Merge branch 'main' into observer-role
ItIsJordan Dec 18, 2024
7befee8
Merge branch 'main' into observer-role
ItIsJordan Jan 6, 2025
23ff1e7
Fix SubmissionObserver removal
ItIsJordan Jan 7, 2025
c6bb6c7
Add observer_key to records API context
ItIsJordan Jan 14, 2025
00bb25b
Add clipboard changes
ItIsJordan Jan 14, 2025
ebc0262
Add new observer key creation (on new version)
ItIsJordan Feb 18, 2025
66580b5
Update endpoint /submit (POST) in submission/views
ItIsJordan Feb 18, 2025
0bb32c6
Add observer key to post submission screen
ItIsJordan Feb 18, 2025
a45506d
Add status filtering to observer key creation in get_or_create_hepsub…
ItIsJordan Feb 18, 2025
41131a0
Add basic observer key test
ItIsJordan Feb 18, 2025
22ad691
Refactor SubmissionObserver
ItIsJordan Mar 3, 2025
4164dd0
Add endpoint to get observer key
ItIsJordan Mar 5, 2025
e6dd9e1
Add get_or_create_submission_observer
ItIsJordan Mar 5, 2025
efe2942
Update get_or_create_hepsubmission to use get_or_create_submission_ob…
ItIsJordan Mar 5, 2025
191e3f4
Update post submission observer key message
ItIsJordan Mar 5, 2025
18b7065
Remove unique constraint from observer_key
ItIsJordan Mar 5, 2025
c88a2a0
Update SubmissionObserver key method to 8char
ItIsJordan Mar 5, 2025
d1115e3
Fix test_observer_key
ItIsJordan Mar 5, 2025
87fc27a
Move and refactor get_or_create_submission_observer
ItIsJordan Mar 17, 2025
a2609f9
Update observer_url on post-submission screen
ItIsJordan Mar 17, 2025
53001a1
Implement observer key into post-submission email
ItIsJordan Mar 17, 2025
87e76f0
Update getting SubmissionObserver in create_new_version
ItIsJordan Mar 17, 2025
939ac41
Update observer_key endpoint
ItIsJordan Mar 17, 2025
8d1aa72
Dashboard widget observer key text
ItIsJordan Mar 17, 2025
9fd4c6e
Move verify_observer_key into permissions module
ItIsJordan Mar 17, 2025
ac08a57
Add test for verify_observer_key
ItIsJordan Mar 17, 2025
7d5dbcc
Add missing import from records_test.py
ItIsJordan Mar 17, 2025
163e8f4
Add copy button colour rule to record CSS
ItIsJordan Mar 26, 2025
ad32d79
Add observer_key functionality to file downloading by recid
ItIsJordan Mar 26, 2025
b508a54
Redo download URL dropdown generation
ItIsJordan Mar 26, 2025
4fe5c08
Merge branch 'main' into observer-role
ItIsJordan May 21, 2025
71273b6
Upgrade clipboardjs in webpack
ItIsJordan May 28, 2025
e95047b
Add copy button stylesheet
ItIsJordan Jun 3, 2025
8318cac
Update verify_observer_key for none/invalid input
ItIsJordan Jun 3, 2025
8c7a6cc
Remove old copy button css
ItIsJordan Jun 3, 2025
b6e530a
Add toastr.css link to copy button html files
ItIsJordan Jun 3, 2025
d15cfe8
Improve observer key function
ItIsJordan Jun 3, 2025
1500484
Add observer key access to data table download
ItIsJordan Jun 3, 2025
85ad2a8
Update observer key verification in render_record
ItIsJordan Jun 3, 2025
3b7027c
Update dashboard manager widget footer/modal css rules
ItIsJordan Jun 3, 2025
af76a1c
Refactor clipboard JS code
ItIsJordan Jun 3, 2025
a7adb80
Remove observer key display from publication_record.html
ItIsJordan Jun 3, 2025
ccfd128
Update create_new_version to regenerate observer key
ItIsJordan Jun 3, 2025
9f4f007
Add dashboard widget observer key copy button
ItIsJordan Jun 3, 2025
63b9af8
Add HTML/JS for observer key copy button submit display
ItIsJordan Jun 3, 2025
efeae9b
Add observer key output to record URLs
ItIsJordan Jun 3, 2025
7cf54ec
Add observer key error messaging to the 403 page
ItIsJordan Jun 3, 2025
1b8c266
Improve HEPDATA.switch_table observer key security
ItIsJordan Jun 3, 2025
dd24e3c
Update clipboard pin in webpack
ItIsJordan Jun 4, 2025
07a656c
Remove deprecated comment
ItIsJordan Jun 4, 2025
e090216
Add correct website URL to submission observer button
ItIsJordan Jun 16, 2025
fbc798d
Update SubmissionObserver constructor
ItIsJordan Jun 16, 2025
b3bbcd8
Add delete_submission_observer to submission/api.py
ItIsJordan Jun 16, 2025
ded5bf2
Updates submission.py to use new deletion function
ItIsJordan Jun 16, 2025
33ce922
Add SubmissionObserver model test
ItIsJordan Jun 16, 2025
dc48dd3
Add overall_status to record context
ItIsJordan Jun 16, 2025
08a27af
Add submission_status/observer_key to HEPData JS object
ItIsJordan Jun 16, 2025
e8d1ec7
Update submission e2e test to verify observer field
ItIsJordan Jun 16, 2025
777d763
Pass observer key to data table download
ItIsJordan Jun 16, 2025
c6e8650
Add observer key to resource download/landing page urls on record res…
ItIsJordan Jun 16, 2025
5603324
Add submission testing
ItIsJordan Jun 16, 2025
332a96d
Endpoint protection
ItIsJordan Jun 17, 2025
9d34dfa
fix test_get_or_create_submission_observer
ItIsJordan Jun 17, 2025
68a90fb
Fix broken test (regex)
ItIsJordan Jun 18, 2025
5632d24
Add copy button test to test_dashboard
ItIsJordan Jun 18, 2025
7c3ceb8
Update get_observer_url function to use get_or_create_submission_obse…
ItIsJordan Jun 18, 2025
6daabc5
Merge branch 'main' into observer-role
ItIsJordan Jul 16, 2025
3bae197
Add submission check to get_or_create_submission_observer
ItIsJordan Jul 16, 2025
0f892ff
Commit HEPSubmission before creating SubmissionObserver
ItIsJordan Jul 16, 2025
606872a
Add status param to create_blank_test_record in tests/conftest.py
ItIsJordan Jul 16, 2025
b62d54c
Add test_get_observer_url
ItIsJordan Jul 16, 2025
aa119b6
Update test_get_or_create_submission_observer to test against submiss…
ItIsJordan Jul 16, 2025
f2185e5
Merge branch 'main' into observer-role
ItIsJordan Aug 13, 2025
0dd7048
Merge branch 'main' into observer-role
ItIsJordan Aug 13, 2025
79a447e
Update tests/submission_test.py
ItIsJordan Aug 13, 2025
0899c56
Remove hardcoded observer key length
ItIsJordan Aug 13, 2025
44affa2
Merge branch 'observer-role' of https://github.com/HEPData/hepdata in…
ItIsJordan Aug 13, 2025
824ba18
Merge branch 'main' into observer-role
ItIsJordan Sep 15, 2025
b362c13
Merge branch 'main' into observer-role
ItIsJordan Sep 15, 2025
3ee5d48
Add create_record_with_participant to conftest
ItIsJordan Sep 15, 2025
72dd3f9
Update test_send_cookie_email
ItIsJordan Sep 15, 2025
d8117b5
Add test_notify_submission_created in email_test.py
ItIsJordan Sep 15, 2025
d2d351e
Create new HEPDATA.get_observer_key fnction
ItIsJordan Sep 17, 2025
7df6c34
Rename/expand get_observer_url
ItIsJordan Sep 17, 2025
a248401
Modify set_observer_key for async
ItIsJordan Sep 17, 2025
2e6ef63
Update tests for renamed get_observer_url function
ItIsJordan Sep 17, 2025
275cc9d
Update hepdata_resources for asynch request call
ItIsJordan Sep 17, 2025
bec32c7
Update test_get_observer_data for changes
ItIsJordan Sep 17, 2025
e0f19a9
Merge branch 'main' into observer-role
ItIsJordan Oct 1, 2025
42ef8b8
Use OBSERVER_KEY_LENGTH in verify_observer_key
ItIsJordan Oct 1, 2025
30fa8ae
Improve logic in get_or_create_submission_observer
ItIsJordan Oct 1, 2025
82643ae
Update hepdata/modules/submission/models.py
ItIsJordan Oct 1, 2025
12cde58
Merge branch 'observer-role' of https://github.com/HEPData/hepdata in…
ItIsJordan Oct 1, 2025
99cbf18
Fix indentation in copilot commit
ItIsJordan Oct 1, 2025
f62fe04
Revert "Improve logic in get_or_create_submission_observer"
ItIsJordan Oct 1, 2025
6e066e4
Merge branch 'main' into observer-role
ItIsJordan Oct 1, 2025
93587c2
Merge branch 'main' into observer-role
ItIsJordan Oct 14, 2025
a48b4ce
Remove extra SubmissionObserver deletion called in remove_submission
ItIsJordan Oct 14, 2025
d61c451
Allow create_blank_test_record to use alternate user
ItIsJordan Oct 14, 2025
688b963
Add logged out observer request test
ItIsJordan Oct 16, 2025
3ac6c2d
Widen submission screen observer container link
ItIsJordan Oct 16, 2025
d5fb912
Update css comment formatting in copybutton.scss
ItIsJordan Oct 16, 2025
185af4a
Fix bad syntax in create_blank_test_record in conftest.py
ItIsJordan Oct 16, 2025
78bf207
Dashboard manager submission observer css position improvements
ItIsJordan Oct 16, 2025
3332cc4
Merge branch 'main' into observer-role
ItIsJordan Oct 16, 2025
9914439
Fix text for submission observer input fields
ItIsJordan Oct 16, 2025
d809165
Merge branch 'main' into observer-role
ItIsJordan Oct 29, 2025
018b2cc
Update hepdata/modules/submission/api.py (copilot)
ItIsJordan Oct 29, 2025
40da23b
Modify copilot changes to delete_submission_observer
ItIsJordan Oct 29, 2025
d3d9bf6
Update hepdata/modules/permissions/api.py
ItIsJordan Oct 29, 2025
d96d402
Fix logging in verify_observer_key from copilot
ItIsJordan Oct 29, 2025
7ca9524
Fix Resource widget observer key button URL
ItIsJordan Nov 4, 2025
9d9f36a
Merge branch 'main' into observer-role
ItIsJordan Nov 4, 2025
74f4b44
Fix submission resource widget download button non-display bug
ItIsJordan Nov 5, 2025
51a795f
Merge branch 'main' into observer-role
ItIsJordan Nov 5, 2025
fde7455
Update hepdata/modules/submission/models.py
ItIsJordan Nov 6, 2025
50e49b1
Improve test_logged_out_observer in test_records.py
ItIsJordan Nov 10, 2025
1c8224f
Apply suggestions from code review
ItIsJordan Nov 10, 2025
8e225f7
Merge branch 'main' into observer-role
ItIsJordan Nov 11, 2025
6be0677
Remove double space in views.py/download_data_table_by_recid
ItIsJordan Nov 11, 2025
9b3338a
Set OBSERVER_KEY_LENGTH value in JS
ItIsJordan Nov 11, 2025
99a2e81
Remove extra space in email_test.py
ItIsJordan Nov 11, 2025
02c14f4
Remove extra slash in test_dashboard
ItIsJordan Nov 11, 2025
a38c819
Fix typo in test_submission_observer_create_delete
ItIsJordan Nov 11, 2025
9b8149e
Remove extra width value in copybutton.scss
ItIsJordan Nov 11, 2025
0f76f3c
Correctly refer to dashboard_button by ID in set_observer_key
ItIsJordan Nov 11, 2025
2c6df15
Remove useless slashes from observer_key request URLs
ItIsJordan Nov 11, 2025
02df96c
Improve observer key appending in switch_table
ItIsJordan Nov 11, 2025
f2f2e55
Improve observer key append logic in resource widget
ItIsJordan Nov 11, 2025
7f759c3
Modify render_record to pass observer_key to context when logged in
ItIsJordan Nov 12, 2025
ab1a479
Fix observer_key display when logged in for copy paste button
ItIsJordan Nov 12, 2025
884c4b0
Add more cases to test_logged_out_observer
ItIsJordan Nov 12, 2025
d53e135
Merge branch 'main' into observer-role
ItIsJordan Dec 2, 2025
870024d
Use get_latest_hepsubmission in get_or_create_submission_observer
ItIsJordan Dec 2, 2025
7aa2913
Fix copy button not working on dashboard widget
ItIsJordan Dec 3, 2025
a7cbc23
Merge branch 'main' into observer-role
ItIsJordan Dec 3, 2025
d763c11
Add coordinator check to get_observer_data check
ItIsJordan Dec 16, 2025
30cc7b3
Fix equality check in HEPDATA.get_observer_key_data
ItIsJordan Dec 16, 2025
1398684
Add coordinator check before setting observer key in render_record
ItIsJordan Dec 16, 2025
ef6eaee
Add a test for automatic observer creation
ItIsJordan Dec 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hepdata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def _(x):
CLIENT_TIMEOUT = 298 # Client-side timeout in s (should be slightly smaller than server timeout)
SIZE_LOAD_CHECK_THRESHOLD = 1 * (1024 * 1024) # Size (bytes) threshold for immediate loading of a table on the records page.
ADDITIONAL_SIZE_LOAD_CHECK_THRESHOLD = 1 * (1024 * 1024) # Size (bytes) threshold for disallowing render of additional res files
OBSERVER_KEY_LENGTH = 8 # The length that the UUID4 observer key is trimmed down to.

CFG_PUB_TYPE = 'publication'
CFG_DATA_TYPE = 'datatable'
Expand Down
24 changes: 18 additions & 6 deletions hepdata/modules/converter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from hepdata.config import CFG_CONVERTER_URL, CFG_SUPPORTED_FORMATS, CFG_CONVERTER_TIMEOUT

from hepdata_converter_ws_client import convert, Error
from hepdata.modules.permissions.api import user_allowed_to_perform_action
from hepdata.modules.permissions.api import user_allowed_to_perform_action, verify_observer_key
from hepdata.modules.converter import convert_zip_archive
from hepdata.modules.submission.api import get_latest_hepsubmission
from hepdata.modules.submission.models import HEPSubmission, DataResource, DataSubmission
Expand Down Expand Up @@ -133,6 +133,8 @@ def download_submission_with_recid(*args, **kwargs):
:return: download_submission
"""
recid = kwargs.pop('recid')
observer_key = request.args.get('observer_key')
key_verified = verify_observer_key(recid, observer_key)

version_count, version_count_all = get_version_count(recid)
if 'version' in kwargs:
Expand All @@ -142,7 +144,7 @@ def download_submission_with_recid(*args, **kwargs):
version = version_count if version_count else 1

# Check for a user trying to access a version of a publication record where they don't have permissions.
if version_count < version_count_all and version == version_count_all:
if version_count < version_count_all and version == version_count_all and not key_verified:
abort(403)

submission = HEPSubmission.query.filter_by(publication_recid=recid, version=version).first()
Expand Down Expand Up @@ -352,6 +354,8 @@ def download_data_table_by_recid(*args, **kwargs):
recid = kwargs.pop('recid')
table_name = kwargs.pop('table_name')
rivet = kwargs.pop('rivet', '')
observer_key = request.args.get('observer_key')
key_verified = verify_observer_key(recid, observer_key)

version_count, version_count_all = get_version_count(recid)
if 'version' in kwargs:
Expand All @@ -361,9 +365,12 @@ def download_data_table_by_recid(*args, **kwargs):
version = version_count if version_count else 1

# Check for a user trying to access a version of a publication record where they don't have permissions.
if version_count < version_count_all and version == version_count_all:
if version_count < version_count_all and version == version_count_all and not key_verified:
abort(403)

if not key_verified:
observer_key = None

datasubmission = None
original_table_name = table_name
try:
Expand All @@ -389,7 +396,7 @@ def download_data_table_by_recid(*args, **kwargs):

return download_datatable(datasubmission, kwargs.pop('file_format'),
submission_id='{0}'.format(recid), table_name=datasubmission.name,
rivet_analysis_name=rivet,
rivet_analysis_name=rivet, observer_key=observer_key,
yoda_keep_qualifiers=bool(request.args.get('qualifiers', False)))


Expand Down Expand Up @@ -419,8 +426,13 @@ def download_datatable(datasubmission, file_format, *args, **kwargs):
"""

if file_format == 'json':
return redirect('/record/data/{0}/{1}/{2}'.format(datasubmission.publication_recid,
datasubmission.id, datasubmission.version))
redirect_url = '/record/data/{0}/{1}/{2}'.format(datasubmission.publication_recid,
datasubmission.id, datasubmission.version)
observer_key = kwargs.get("observer_key")
if observer_key:
redirect_url += f"?observer_key={observer_key}"
return redirect(redirect_url)

elif file_format not in CFG_SUPPORTED_FORMATS:
return display_error(
title="The " + file_format + " output format is not supported",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,31 @@ $(document).ready(function() {
});
}

function set_observer_key(recid) {
/**
* Sets the observer key value on the manage submission dashboard widget.
*
* @param {number} recid - The recid to get observer_key for.
*/

// Call for observer key, with the flag to retrieve
let observer_promise = HEPDATA.get_observer_key_data(recid, 1);

observer_promise.then(function(observer_key) {
if(observer_key) {
// Unhide container, set value and text on the input
$('#data_link_container').removeAttr('hidden');
$('#direct_data_link').val(observer_key);
}
});
HEPDATA.setup_clipboard("#dashboard_button");
}

$(document).on('click', '.manage-submission-trigger', function (event) {
window.recid = $(this).attr('data-recid');
HEPDATA.load_all_review_messages("#conversation", $(this).attr('data-recid'));
process_reviews($(this).attr('data-recid'));
set_observer_key($(this).attr('data-recid'));
});

$(document).on('click', '.conversation-trigger', function (event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

{%- block additional_assets %}
{{ webpack['hepdata-info.css'] }}
{{ webpack['toastr.css'] }}
{%- endblock additional_assets %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ <h4 class="modal-title" id="codeDialogLabel">Manage Submission</h4>

</div>
<div class="clearfix"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default pull-right" data-dismiss="modal" aria-label="Close">Close
<div id="manager-footer" class="modal-footer">
<div id="data_link_message">
You can use this URL to allow any user observer access without special permissions:
</div>
<div id="data_link_container" hidden>
<input id="direct_data_link" class="data_link" value="" readonly>
<button id="dashboard_button" class="btn btn-small copy-btn-style" data-clipboard-target="#direct_data_link">
<i class="fa fa-copy" alt="Copy to clipboard"></i>
</button>
</div>
<button id="manager-close" type="button" class="btn btn-default pull-right" data-dismiss="modal" aria-label="Close">
Close
</button>

</div>
</div>
</div>
Expand Down
12 changes: 10 additions & 2 deletions hepdata/modules/email/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

from hepdata.modules.permissions.models import CoordinatorRequest
from hepdata.modules.submission.api import get_latest_hepsubmission, \
get_primary_submission_participants_for_record, get_submission_participants_for_record
get_primary_submission_participants_for_record, get_submission_participants_for_record, \
get_or_create_submission_observer
from hepdata.modules.submission.models import HEPSubmission, DataSubmission, DataReview
from hepdata.utils.users import get_user_from_id
from invenio_accounts.models import User
Expand Down Expand Up @@ -460,6 +461,12 @@ def notify_submission_created(record, coordinator_id, uploader, reviewer):

collaboration = _get_collaboration(coordinator_id)

# Get any SubmissionObserver object entry for this ID
submission_observer = get_or_create_submission_observer(record['recid'])

# Generate the observer access URL with key in
observer_url = f"{site_url}/record/{record['recid']}?observer_key={submission_observer.observer_key}"

message_body = render_template('hepdata_theme/email/created.html',
name=name,
actor=coordinator.email,
Expand All @@ -469,7 +476,8 @@ def notify_submission_created(record, coordinator_id, uploader, reviewer):
article=record['recid'],
title=record['title'],
site_url=site_url,
link=site_url + "/record/{0}".format(record['recid']))
link=site_url + "/record/{0}".format(record['recid']),
observer_url=observer_url)

create_send_email_task(coordinator.email,
'[HEPData] Submission {0} has been created'.format(record['recid']),
Expand Down
45 changes: 43 additions & 2 deletions hepdata/modules/permissions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

import logging

from functools import partial
from operator import is_not

from flask_login import current_user
from sqlalchemy import or_

from hepdata.config import OBSERVER_KEY_LENGTH
from hepdata.modules.permissions.models import SubmissionParticipant, CoordinatorRequest
from hepdata.modules.records.utils.common import get_record_contents
from hepdata.modules.submission.models import HEPSubmission
from hepdata.modules.submission.models import HEPSubmission, SubmissionObserver
from hepdata.utils.users import get_user_from_id, user_is_admin

logging.basicConfig()
log = logging.getLogger(__name__)


def get_records_participated_in_by_user(user):
_current_user_id = user.id
Expand Down Expand Up @@ -194,3 +198,40 @@ def write_submissions_to_files():

csvfile.close()
csvfile1.close()


def verify_observer_key(submission_id, observer_key):
"""
Verifies the access key used to access a submission without
login requirement.
:param int submission_id: The requested HEPSubmission for access
:param str observer_key: The access key used to access the submission
:returns: Bool representing match status against database
"""

# Validate inputs
if submission_id is None or observer_key is None:
return False

try:
submission_id = int(submission_id)
except (ValueError, TypeError):
log.warning(f"Invalid submission_id format: {submission_id}")
return False

if len(observer_key) != OBSERVER_KEY_LENGTH:
log.warning(f"Invalid observer_key length for submission {submission_id}")
return False
try:
submission_observer = SubmissionObserver.query.filter_by(
publication_recid=submission_id,
observer_key=observer_key
).first()

result = submission_observer is not None

return result

except Exception as e:
log.error(f"Database error in verify_observer_key: {e}")
return False
57 changes: 39 additions & 18 deletions hepdata/modules/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from hepdata.modules.converter import convert_oldhepdata_to_yaml
from hepdata.modules.email.api import send_cookie_email
from hepdata.modules.email.utils import create_send_email_task
from hepdata.modules.permissions.api import user_allowed_to_perform_action
from hepdata.modules.permissions.api import user_allowed_to_perform_action, verify_observer_key
from hepdata.modules.permissions.models import SubmissionParticipant
from hepdata.modules.records.subscribers.api import is_current_user_subscribed_to_record
from hepdata.modules.records.utils.common import decode_string, find_file_in_directory, allowed_file, \
Expand All @@ -51,7 +51,8 @@
from hepdata.modules.records.utils.json_ld import get_json_ld
from hepdata.modules.records.utils.submission import process_submission_directory, \
create_data_review, cleanup_submission, clean_error_message_for_display
from hepdata.modules.submission.api import get_latest_hepsubmission, get_submission_participants_for_record
from hepdata.modules.submission.api import get_latest_hepsubmission, get_submission_participants_for_record, \
get_or_create_submission_observer
from hepdata.modules.records.utils.users import get_coordinators_in_system, has_role
from hepdata.modules.records.utils.workflow import update_action_for_submission_participant
from hepdata.modules.records.utils.yaml_utils import split_files
Expand All @@ -62,7 +63,8 @@
HEPSubmission,
RecordVersionCommitMessage,
RelatedRecid,
RelatedTable
RelatedTable,
SubmissionObserver
)
from hepdata.utils.file_extractor import extract
from hepdata.utils.miscellaneous import sanitize_html, get_resource_data
Expand Down Expand Up @@ -370,7 +372,7 @@ def extract_journal_info(record):
record['journal_info'] = "Conference Paper"


def render_record(recid, record, version, output_format, light_mode=False):
def render_record(recid, record, version, output_format, light_mode=False, observer_key=None):

# Count number of all versions and number of finished versions of a publication record.
version_count_all = HEPSubmission.query.filter(HEPSubmission.publication_recid == recid,
Expand All @@ -385,20 +387,24 @@ def render_record(recid, record, version, output_format, light_mode=False):
if version == -1:
version = version_count if version_count else 1

# Check for a user trying to access a version of a publication record where they don't have permissions.
if version_count < version_count_all and version == version_count_all:
# Prompt the user to login if they are not authenticated then redirect, otherwise return a 403 error.
if not current_user.is_authenticated:
redirect_url_after_login = '%2Frecord%2F{0}%3Fversion%3D{1}%26format%3D{2}'.format(recid, version, output_format)
if 'table' in request.args:
redirect_url_after_login += '%26table%3D{0}'.format(request.args['table'])
if output_format.startswith('yoda') and 'rivet' in request.args:
redirect_url_after_login += '%26rivet%3D{0}'.format(request.args['rivet'])
if output_format.startswith('yoda') and 'qualifiers' in request.args:
redirect_url_after_login += '%26qualifiers%3D{0}'.format(request.args['qualifiers'])
return redirect('/login/?next={0}'.format(redirect_url_after_login))
else:
abort(403)
key_verified = verify_observer_key(recid, observer_key)

# We skip the version check if the access key matches
if not key_verified:
# Check for a user trying to access a version of a publication record where they don't have permissions.
if version_count < version_count_all and version == version_count_all:
# Prompt the user to login if they are not authenticated then redirect, otherwise return a 403 error.
if not current_user.is_authenticated:
redirect_url_after_login = '%2Frecord%2F{0}%3Fversion%3D{1}%26format%3D{2}'.format(recid, version, output_format)
if 'table' in request.args:
redirect_url_after_login += '%26table%3D{0}'.format(request.args['table'])
if output_format.startswith('yoda') and 'rivet' in request.args:
redirect_url_after_login += '%26rivet%3D{0}'.format(request.args['rivet'])
if output_format.startswith('yoda') and 'qualifiers' in request.args:
redirect_url_after_login += '%26qualifiers%3D{0}'.format(request.args['qualifiers'])
return redirect('/login/?next={0}'.format(redirect_url_after_login))
else:
abort(403)

hepdata_submission = get_latest_hepsubmission(publication_recid=recid, version=version)

Expand All @@ -413,6 +419,16 @@ def render_record(recid, record, version, output_format, light_mode=False):
ctx['record_type'] = 'publication'
ctx['related_recids'] = get_record_data_list(hepdata_submission, "related")
ctx['related_to_this_recids'] = get_record_data_list(hepdata_submission, "related_to_this")
ctx['overall_status'] = hepdata_submission.overall_status


if key_verified and observer_key:
ctx['observer_key'] = observer_key
elif hepdata_submission.overall_status == 'todo':
observer = get_or_create_submission_observer(hepdata_submission.publication_recid)

if observer and has_coordinator_permissions(recid, current_user):
ctx['observer_key'] = observer.observer_key

increment(recid)

Expand Down Expand Up @@ -541,7 +557,12 @@ def create_new_version(recid, user, notify_uploader=True, uploader_message=None)
inspire_id=hepsubmission.inspire_id,
coordinator=hepsubmission.coordinator,
version=hepsubmission.version + 1)

# Gets a generated or new SubmissionObserver object
observer_key = get_or_create_submission_observer(_rev_hepsubmission.publication_recid, regenerate=True)

db.session.add(_rev_hepsubmission)
db.session.add(observer_key)
db.session.commit()

if notify_uploader:
Expand Down
Loading