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

Hyp 300 #628

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions app/projects/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.http import QueryDict
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.shortcuts import render
from dal import autocomplete

from contact.views import email_send
Expand Down Expand Up @@ -774,7 +775,7 @@ def submit_user_permission_request(request):

# Check if there are administrators to notify.
if project.project_supervisors is None or project.project_supervisors == "":
return HttpResponse(200)
return render(request, 'projects/signup/request-access.html', {"panel": {"additional_context": {"requested_access": True}}})

# Convert the comma separated string of emails into a list.
supervisor_emails = project.project_supervisors.split(",")
Expand All @@ -798,7 +799,7 @@ def submit_user_permission_request(request):
except Exception as e:
logger.exception(e)

return HttpResponse(200)
return render(request, 'projects/signup/request-access.html', {"panel": {"additional_context": {"requested_access": True}}})



Expand Down
3 changes: 3 additions & 0 deletions app/projects/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# For signup steps that will always be displayed no matter what actions are taken.
SIGNUP_STEP_PERMANENT_STATUS = 'permanent'

# For signup steps that have already been completed but are pending admin action.
SIGNUP_STEP_PENDING_STATUS = 'pending'

class DataProjectPanel():
"""
The base class that holds information needed to when displaying a panel
Expand Down
38 changes: 30 additions & 8 deletions app/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from profile.forms import RegistrationForm
from hypatio.auth0authenticate import public_user_auth_and_jwt
from hypatio.auth0authenticate import user_auth_and_jwt
from projects.models import AGREEMENT_FORM_TYPE_EXTERNAL_LINK, TEAM_ACTIVE, TEAM_READY
from projects.models import AGREEMENT_FORM_TYPE_EXTERNAL_LINK, TEAM_ACTIVE, TEAM_READY, TEAM_PENDING
from projects.models import AGREEMENT_FORM_TYPE_STATIC
from projects.models import AGREEMENT_FORM_TYPE_MODEL
from projects.models import AGREEMENT_FORM_TYPE_FILE
Expand All @@ -32,6 +32,7 @@
from projects.panels import SIGNUP_STEP_CURRENT_STATUS
from projects.panels import SIGNUP_STEP_FUTURE_STATUS
from projects.panels import SIGNUP_STEP_PERMANENT_STATUS
from projects.panels import SIGNUP_STEP_PENDING_STATUS
from projects.panels import DataProjectInformationalPanel
from projects.panels import DataProjectSignupPanel
from projects.panels import DataProjectActionablePanel
Expand Down Expand Up @@ -220,6 +221,7 @@ def get_context_data(self, **kwargs):
context['SIGNUP_STEP_CURRENT_STATUS'] = SIGNUP_STEP_CURRENT_STATUS
context['SIGNUP_STEP_FUTURE_STATUS'] = SIGNUP_STEP_FUTURE_STATUS
context['SIGNUP_STEP_PERMANENT_STATUS'] = SIGNUP_STEP_PERMANENT_STATUS
context['SIGNUP_STEP_PENDING_STATUS'] = SIGNUP_STEP_PENDING_STATUS

# If this project is informational only, just show them the description without requiring an account.
if self.project.informational_only:
Expand Down Expand Up @@ -386,7 +388,7 @@ def get_manager_context(self, context):

return context

def get_step_status(self, step_name, step_complete, is_permanent=False):
def get_step_status(self, step_name, step_complete, is_permanent=False, is_pending=False):
"""
Returns the status this step should have. If the given step is incomplete and we do not
already have a current_step, then this step is the current step and update
Expand All @@ -399,6 +401,9 @@ def get_step_status(self, step_name, step_complete, is_permanent=False):
if is_permanent:
return SIGNUP_STEP_PERMANENT_STATUS

if is_pending:
return SIGNUP_STEP_PENDING_STATUS

logger.debug(f"{self.project.project_key}/{step_name}: Completed step")
return SIGNUP_STEP_COMPLETED_STATUS

Expand Down Expand Up @@ -603,19 +608,23 @@ def setup_panel_request_access(self, context):
if not self.project.requires_authorization or self.project.has_teams:
return

# This step is never completed, it is usually the last step.
step_status = self.get_step_status('request_access', False)

# If the user does not have a participant record, they have not yet requested access.
requested_access = self.participant is not None

# Check for a prior current step which is possible even when this step is complete
# due to rejection of signed agreement forms
prior_current_step = next((s for s in context["setup_panels"] if s.status == SIGNUP_STEP_CURRENT_STATUS ), None)

# This step is never completed, it is usually the last step.
step_status = self.get_step_status('request_access', requested_access and not prior_current_step, is_pending=True)

panel = DataProjectSignupPanel(
title='Request Access',
bootstrap_color='default',
template='projects/signup/request-access.html',
status=step_status,
additional_context={
'requested_access': requested_access
'requested_access': requested_access,
}
)

Expand All @@ -642,8 +651,21 @@ def setup_panel_team(self, context):
team_approved=False
)

# This step is never completed.
step_status = self.get_step_status('setup_team', False)
# This step is completed/pending if the participant has been associated
# with a team, or for a team leader, request for access has been made.
if team and self.participant.user == team.team_leader:

# Step is completed if awaiting access
completed = team.status == TEAM_READY
elif team and self.participant.user != team.team_leader:

# Step is completed if awaiting access
completed = True
else:
completed = False

# Determine step status
step_status = self.get_step_status('setup_team', completed, is_pending=True)

panel = DataProjectSignupPanel(
title='Join or Create a Team',
Expand Down
8 changes: 7 additions & 1 deletion app/static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
float: right;
color: gray;
}
.pending-step-header span:after {
font-family:'Glyphicons Halflings';
content:"\e023";
float: right;
color: #1F1C18;
}
.accordion-step-header span:after {
font-family:'Glyphicons Halflings';
content:"\e234";
Expand All @@ -41,4 +47,4 @@
/* Colors the asterisks detail on the form red */
.required-field-tip {
color: rgb(153, 8, 8);
}
}
25 changes: 21 additions & 4 deletions app/templates/projects/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ <h2 class="panel-title">
current-step-header
{% elif panel.status == SIGNUP_STEP_PERMANENT_STATUS %}
current-step-header
{% elif panel.status == SIGNUP_STEP_PENDING_STATUS %}
pending-step-header
{% else %}
blocked-step-header
{% endif %}">
<span>{{ panel.title }}</span>
</div>
</h2>
</div>
{% if panel.status == SIGNUP_STEP_CURRENT_STATUS or panel.status == SIGNUP_STEP_PERMANENT_STATUS %}
{% if panel.status == SIGNUP_STEP_CURRENT_STATUS or panel.status == SIGNUP_STEP_PERMANENT_STATUS or panel.status == SIGNUP_STEP_PENDING_STATUS %}
<div class="panel-body">
{% include panel.template %}
</div>
Expand Down Expand Up @@ -235,8 +237,15 @@ <h4 class="modal-title" id="signed-agreement-form-completed-modal-title">Tasks</
contentType: false
}).done(function(){

// Notify
notify('success', "Agreement form submitted!", 'thumbs-up');
submit_button.replaceWith("<h3><span class='label label-success'>Form saved.</span></h3>");

// Reset button and update to indicate success
$(submit_button).button("reset");
setTimeout(function() {
// Do this in a timeout since Bootstrap's 'button' function breaks jQuery methods in same iteration
$(submit_button).html("Form Saved &nbsp;<i class='fa fa-check'></i>").prop("disabled", "disabled").toggleClass("btn-primary btn-success");
}, 0);

// Refresh the page so the user does not see this button again
setTimeout(function(){
Expand Down Expand Up @@ -299,8 +308,16 @@ <h4 class="modal-title" id="signed-agreement-form-completed-modal-title">Tasks</
$.post($(this).attr('action'), formFields + "&" + $('input[name=agreement_text]').serialize(), function(res){
// $("#loading").hide();
}).done(function() {
notify('success', "Agreement form submitted!", 'thumbs-up');
submit_button.replaceWith("<h3><span class='label label-success'>Form saved.</span></h3>");

// Notify
notify('success', "Agreement form submitted!", 'thumbs-up');

// Reset button and update to indicate success
$(submit_button).button("reset");
setTimeout(function() {
// Do this in a timeout since Bootstrap's 'button' function breaks jQuery methods in same iteration
$(submit_button).html("Form Saved &nbsp;<i class='fa fa-check'></i>").prop("disabled", "disabled").toggleClass("btn-primary btn-success");
}, 0);

// Refresh the page so the user does not see this button again
setTimeout(function(){
Expand Down
47 changes: 25 additions & 22 deletions app/templates/projects/signup/request-access.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
{% if panel.additional_context.requested_access %}
Your request is being reviewed. Please use the 'Contact Us' link for any further questions.
{% else %}
<form name="access_request_form" action="{% url 'projects:submit_user_permission_request' %}" method="post">
<form name="access_request_form" method="post" enctype="multipart/form-data"
ic-post-to="{% url 'projects:submit_user_permission_request' %}"
ic-on-success="onAccessRequestSuccess()"
ic-on-error="onAccessRequestError()">
<fieldset>
<div class="row">
<div class="col-md-12">
Expand All @@ -16,9 +19,9 @@
<div class="row">
<div class="col-md-12">
<div class="form-group">
<button type="submit" class="btn btn-primary">Request Access</button>
<img name="loading" id="loading" src="{% static 'gears.svg' %}" style="display:none;">
<div id="status" style="color: green; font-size: 1.5em;"></div>
<button id="request-access-submit-button" type="submit" class="btn btn-primary">Request Access
<span id="request-access-indicator" style="display: none; margin-left: 5px;" class="ic-indicator fa fa-spinner fa-spin"></span>
</button>
</div>
</div>
</div>
Expand All @@ -28,22 +31,22 @@
{% endif %}

<script type="application/javascript">
$('form[name=access_request_form]').submit(function(e){
e.preventDefault();

$("#loading").show();

$.post($(this).attr('action'), $(this).serialize(), function(res){
$("#loading").hide();
}).done(function() {
$("#status").text("Access request submitted! Refreshing page...");

// Refresh the page so the user does not see the Request Access button again
setTimeout(function(){
location.reload();
},2000);
}).fail(function() {
$("#status").text("Access request failed.");
});
});

function onAccessRequestSuccess() {

// Update button
$('#request-access-submit-button').html('Request submitted!&nbsp;&nbsp;<i class=\'fa fa-check\'></i>').prop('disabled', true).toggleClass('btn-primary btn-success')

// Notify
notify('success', 'Access request submitted', 'thumbs-up');

// Update panel class
$(".container").find(".current-step-header").toggleClass("current-step-header pending-step-header");
}

function onAccessRequestError() {

// Notify
notify('danger', 'Access request failed, please contact support or try again', 'exclamation-sign');
}
</script>