Skip to content

Commit

Permalink
Allow submitting author status to be transferred to a co-author. Ref #…
Browse files Browse the repository at this point in the history
…2128.

We occasionally ask for submtting author status of a project to be transferred. This change adds a 'transfer project' button to the author page of the project submission system.
  • Loading branch information
tompollard committed Nov 13, 2023
1 parent cece757 commit 749a6c1
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load i18n %}{% autoescape off %}{% filter wordwrap:70 %}
Dear {{ name }},

You have been made submitting author of the project entitled "{{ project.title }}" on {{ SITE_NAME }}.

You can view and edit the project on your project homepage: {{ url_prefix }}{% url "project_home" %}.

{{ signature }}

{{ footer }}
{% endfilter %}{% endautoescape %}
19 changes: 19 additions & 0 deletions physionet-django/notification/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,22 @@ def notify_event_participant_application(request, user, registered_user, event):
body = loader.render_to_string('events/email/event_registration.html', context)
# Not resend the email if there was an integrity error
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)


def notify_submitting_author(request, project):
"""
Notify a user that they have been made submitting author for a project.
"""
author = project.authors.get(is_submitting=True)
subject = f"{settings.SITE_NAME}: You are now a submitting author"
context = {
'name': author.get_full_name(),
'project': project,
'url_prefix': get_url_prefix(request),
'SITE_NAME': settings.SITE_NAME,
'signature': settings.EMAIL_SIGNATURE,
'footer': email_footer()
}
body = loader.render_to_string('notification/email/notify_submitting_author.html', context)
# Not resend the email if there was an integrity error
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [author.user.email], fail_silently=False)
25 changes: 25 additions & 0 deletions physionet-django/project/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@ def update_corresponder(self):
new_c.save()


class TransferAuthorForm(forms.Form):
"""
Transfer submitting author.
"""
transfer_author = forms.ModelChoiceField(queryset=None, required=True,
widget=forms.Select(attrs={'onchange': 'set_transfer_author()',
'id': 'transfer_author_id'}),
empty_label="Select an author")

def __init__(self, project, *args, **kwargs):
super().__init__(*args, **kwargs)
self.project = project
# Exclude the current submitting author from the queryset
authors = project.authors.exclude(is_submitting=True).order_by('display_order')
self.fields['transfer_author'].queryset = authors

def transfer(self):
new_author = self.cleaned_data['transfer_author']

# Assign the new submitting author
self.project.authors.update(is_submitting=False)
new_author.is_submitting = True
new_author.save()


class ActiveProjectFilesForm(forms.Form):
"""
Inherited form for manipulating project files/directories. Upload
Expand Down
22 changes: 22 additions & 0 deletions physionet-django/project/static/project/js/transfer-author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$(document).ready(function() {
// Function to update the displayed author name when a new author is selected
function set_transfer_author() {
var selectedAuthorName = $("#transfer_author_id option:selected").text();
$('#project_author').text(selectedAuthorName);
}

// Attach the change event to the author select dropdown to update the name on change
$("#transfer_author_id").change(set_transfer_author);

// Prevent the default form submission and show the confirmation modal
$('#authorTransferForm').on('submit', function(e) {
e.preventDefault();
$('#transfer_author_modal').modal('show');
});

// When the confirmation button is clicked, submit the form
$('#confirmAuthorTransfer').on('click', function() {
$('#authorTransferForm').off('submit').submit();
});
});

46 changes: 46 additions & 0 deletions physionet-django/project/templates/project/project_authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,61 @@ <h3>Your Affiliations</h3>
<button class="btn btn-primary btn-rsp" name="edit_affiliations" type="submit">Set Affiliations</button>
</form>
<hr>
<br>

{# Transfer project to a new submitting author #}
{% if is_submitting %}
<h3>Submitting Author</h3>
<p>Only the submitting author of a project is able to edit content.
You may transfer the role of submitting author to a co-author.
Choose one of the co-authors below to make them the submitting author for this project.
Transferring authorship will remove your ability to edit content!</p>

<form id="authorTransferForm" action="{% url 'project_authors' project.slug %}" method="post" class="no-pd">
{% csrf_token %}
{% include "inline_form_snippet.html" with form=transfer_author_form %}
<button class="btn btn-primary btn-rsp" name="transfer_author" type="submit">Transfer</button>
</form>
<hr>
{% endif %}

<!-- Modal for confirming author transfer -->
<div class="modal fade" id="transfer_author_modal" tabindex="-1" role="dialog" aria-labelledby="transferAuthorshipModalTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="transferAuthorshipModalTitle">Transfer Authorship</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p id="confirmationText">Please confirm that you would like to assign '<span id="project_author"></span>' as the new submitting author.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="confirmAuthorTransfer">Transfer</button>
</div>
</div>
</div>
</div>
<!-- End Modal -->

{% endblock %}

{% block local_js_bottom %}
<script src="{% static 'custom/js/enable-popover.js' %}"></script>
<script>
disableAddButtons();
</script>

{# Disable submission if not currently editable #}
{% if not project.author_editable %}
<script src="{% static 'custom/js/disable-input.js' %}"></script>
{% endif %}

{% if is_submitting %}
<script src="{% static 'project/js/transfer-author.js' %}"></script>
{% endif %}

{% endblock %}
15 changes: 14 additions & 1 deletion physionet-django/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,10 @@ def project_authors(request, project_slug, **kwargs):
inviter=user)
corresponding_author_form = forms.CorrespondingAuthorForm(
project=project)
transfer_author_form = forms.TransferAuthorForm(
project=project)
else:
invite_author_form, corresponding_author_form = None, None
invite_author_form, corresponding_author_form, transfer_author_form = None, None, None

if author.is_corresponding:
corresponding_email_form = AssociatedEmailChoiceForm(
Expand Down Expand Up @@ -591,6 +593,16 @@ def project_authors(request, project_slug, **kwargs):
messages.success(request, 'Your corresponding email has been updated.')
else:
messages.error(request, 'Submission unsuccessful. See form for errors.')
elif 'transfer_author' in request.POST and is_submitting:
transfer_author_form = forms.TransferAuthorForm(
project=project, data=request.POST)
if transfer_author_form.is_valid():
transfer_author_form.transfer()
notification.notify_submitting_author(request, project)
messages.success(request, 'The submitting author has been updated.')
return redirect('project_authors', project_slug=project.slug)
else:
messages.error(request, 'Submission unsuccessful. See form for errors.')

authors = project.get_author_info()
invitations = project.authorinvitations.filter(is_active=True)
Expand All @@ -601,6 +613,7 @@ def project_authors(request, project_slug, **kwargs):
'invite_author_form':invite_author_form,
'corresponding_author_form':corresponding_author_form,
'corresponding_email_form':corresponding_email_form,
'transfer_author_form': transfer_author_form,
'add_item_url':edit_affiliations_url, 'remove_item_url':edit_affiliations_url,
'is_submitting':is_submitting})

Expand Down

0 comments on commit 749a6c1

Please sign in to comment.