Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1617 do_revision bugfix - now validates for manageable files #4366

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/core/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ def serve_pdf_galley_to_browser(request, file, article):
raise Http404


def delete_file(article_object, file_object):
def unassociate_file(article_object, file_object):
""" Deletes a file. Note: the actual file is not deleted, this just removes the association of the file with an
article.
article. The history remains.

:param article_object: the article associated with the file
:param file_object: the file object to delete
Expand Down
11 changes: 6 additions & 5 deletions src/review/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def get_draft_email_message(request, article):
return render_template.get_message_content(request, email_context, 'draft_message')


def group_files(article, reviews):
def group_files(article, reviews, manageable=False):
files = list()

for file in article.manuscript_files.all():
Expand All @@ -422,10 +422,11 @@ def group_files(article, reviews):
for file in article.data_figure_files.all():
files.append(file)

for review in reviews:
if review.for_author_consumption and review.display_review_file:
files.append(review.review_file)

if not manageable:
for review in reviews:
if review.for_author_consumption and review.display_review_file:
files.append(review.review_file)

return files


Expand Down
2 changes: 1 addition & 1 deletion src/review/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def test_shared_review_download_view(self):
)

# finally, delete the file from disk
files.delete_file(article_with_completed_reviews, file)
files.unassociate_file(article_with_completed_reviews, file)


def setup_request_object(self):
Expand Down
30 changes: 19 additions & 11 deletions src/review/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,8 @@ def do_revisions(request, article_id, revision_id):
).exclude(decision='withdrawn')

form = forms.DoRevisions(instance=revision_request)
revision_files = logic.group_files(revision_request.article, reviews)
manageable_files = logic.group_files(revision_request.article, reviews, manageable=True)
downloadable_files = logic.group_files(revision_request.article, reviews)

if request.POST:
post_redirect = reverse(
Expand All @@ -2047,15 +2048,22 @@ def do_revisions(request, article_id, revision_id):
if 'delete' in request.POST:
file_id = request.POST.get('delete')
file = get_object_or_404(core_models.File, pk=file_id)
files.delete_file(revision_request.article, file)
logic.log_revision_event(
'File {0} ({1}) deleted.'.format(
file.id,
file.original_filename
),
request.user,
revision_request,
)
if file in manageable_files:
files.unassociate_file(revision_request.article, file)
logic.log_revision_event(
'File {0} ({1}) deleted.'.format(
file.id,
file.original_filename
),
request.user,
revision_request,
)
else:
messages.add_message(
request,
messages.WARNING,
_('Given file ID not found in article files.')
)
return redirect(post_redirect)

elif 'save' in request.POST:
Expand Down Expand Up @@ -2101,7 +2109,7 @@ def do_revisions(request, article_id, revision_id):
if request.GET.get('file_id', None):
file_id = request.GET.get('file_id')
file = get_object_or_404(core_models.File, pk=file_id)
if file in revision_files:
if file in downloadable_files:
logic.log_revision_event(
'Downloaded file {0} ({1}).'.format(
file.label,
Expand Down