Skip to content
Snippets Groups Projects
Commit dff49c7a authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Make sure the status bar can be used to correctly display the process

This makes significant changes to the way the visibility of phases are handled.

We confirm that users can "view" the phase. If not we then remove the phase
from the list of phases they are shown. We then make sure that we always
have a valid list of phases when we build the status bar
parent 5ef1710e
No related branches found
No related tags found
No related merge requests found
{% extends "base-apply.html" %}
{% load render_table from django_tables2 %}
{% load static wagtailcore_tags workflow_tags %}
{% load static wagtailcore_tags workflow_tags statusbar_tags %}
{% block title %}Submission Dashboard{% endblock %}
......@@ -27,7 +27,7 @@
<h5 class="heading heading--no-margin"><a class="link link--underlined" href="{% url 'funds:submissions:detail' submission.id %}">{{ submission.title }}</a></h5>
<h6 class="heading heading--no-margin heading--submission-meta"><span>Submitted:</span> {{ submission.submit_time.date }} by {{ submission.user.get_full_name }}</h6>
</div>
{% include "funds/includes/status_bar.html" with phases=submission.workflow current_phase=submission.phase class="status-bar--small" %}
{% status_bar submission.workflow submission.phase request.user css_class="status-bar--small" %}
</div>
{% if request.user|has_edit_perm:submission %}
<a class="button button--primary" href="{% url 'funds:submissions:edit' submission.id %}">
......
{% extends "base-apply.html" %}
{% load static workflow_tags wagtailcore_tags %}
{% load static workflow_tags wagtailcore_tags statusbar_tags %}
{% block title %}{{ object.title }}{% endblock %}
{% block body_class %}{% endblock %}
{% block content %}
......@@ -17,7 +17,7 @@
<span>{{ object.round }}</span>
<span>Lead: {{ object.lead }}</span>
</h5>
{% include "funds/includes/status_bar.html" with phases=object.workflow current_phase=object.phase same_stage=True%}
{% status_bar object.workflow object.phase request.user same_stage=True%}
<div class="tabs js-tabs">
<div class="tabs__container">
......@@ -143,4 +143,3 @@
<script src="{% static 'js/apply/tabs.js' %}"></script>
<script src="{% static 'js/apply/submission-text-cleanup.js' %}"></script>
{% endblock %}
<div class="status-bar {{ class }}">
{% for phase_name, phase in phases.items %}
{% if not same_stage or current_phase.stage == phase.stage %}
{% for phase in phases %}
{% ifchanged phase.step %}
<div class="status-bar__item
{% if phase.step == current_phase.step %}
......@@ -18,7 +17,6 @@
<svg class="status-bar__icon"><use xlink:href="#tick-alt"></use></svg>
</div>
{% endifchanged %}
{% endif %}
{% endfor %}
</div>
<div class="status-bar--mobile">
......
from collections import defaultdict
from django import template
register = template.Library()
def find_last_visible_phase(phases, user, current_phase):
last_phase = current_phase
while not last_phase.permissions.can_view(user):
last_phase = phases[last_phase.step - 1][0]
return last_phase
@register.inclusion_tag('funds/includes/status_bar.html')
def status_bar(workflow, current_phase, user, css_class='', same_stage=False):
all_phases = defaultdict(list)
for phase in list(workflow.values()):
all_phases[phase.step].append(phase)
# Grab the first phase for each step - visible only, the display phase
phases = [
phase for phase, *_ in all_phases.values()
if phase.permissions.can_view(user)
and (not same_stage or phase.stage == current_phase.stage)
]
if not current_phase.permissions.can_view(user):
current_phase = find_last_visible_phase(all_phases, user, current_phase)
# Current step not shown for user, move current phase to last good location
elif not all_phases[current_phase.step][0].permissions.can_view(user):
new_phase_list = []
for phase in reversed(phases):
if phase.step <= current_phase.step and current_phase not in new_phase_list:
next_phase = current_phase
else:
next_phase = phase
new_phase_list = [next_phase, *new_phase_list]
phases = new_phase_list
return {
'phases': phases,
'current_phase': current_phase,
'class': css_class,
}
......@@ -104,7 +104,7 @@ applicant_can = lambda user: user.is_applicant
reviewer_can = lambda user: user.is_reviewer
def make_permissions(edit=list(), review=list(), view=list()):
def make_permissions(edit=list(), review=list(), view=[staff_can, applicant_can, reviewer_can]):
return {
'edit': edit,
'review': review,
......@@ -116,6 +116,8 @@ no_permissions = make_permissions()
default_permissions = make_permissions(edit=[staff_can], review=[staff_can])
hidden_from_applicant_permissions = make_permissions(edit=[staff_can], review=[staff_can], view=[staff_can, reviewer_can])
reviewer_review_permissions = make_permissions(edit=[staff_can], review=[staff_can, reviewer_can])
applicant_edit_permissions = make_permissions(edit=[applicant_can], review=[staff_can])
......@@ -166,7 +168,7 @@ SingleStageDefinition = {
},
'display': 'Internal Review',
'stage': Request,
'permissions': default_permissions,
'permissions': hidden_from_applicant_permissions,
'step': 1,
},
'post_review_discussion': {
......@@ -177,7 +179,7 @@ SingleStageDefinition = {
},
'display': 'Under Discussion',
'stage': Request,
'permissions': default_permissions,
'permissions': hidden_from_applicant_permissions,
'step': 2,
},
'post_review_more_info': {
......@@ -352,7 +354,7 @@ DoubleStageDefinition = {
},
'display': 'Internal Review',
'stage': Concept,
'permissions': default_permissions,
'permissions': hidden_from_applicant_permissions,
'step': 1,
},
'concept_review_discussion': {
......@@ -363,7 +365,7 @@ DoubleStageDefinition = {
},
'display': 'Under Discussion',
'stage': Concept,
'permissions': default_permissions,
'permissions': hidden_from_applicant_permissions,
'step': 2,
},
'concept_review_more_info': {
......@@ -444,7 +446,7 @@ DoubleStageDefinition = {
},
'display': 'Internal Review',
'stage': Proposal,
'permissions': default_permissions,
'permissions': hidden_from_applicant_permissions,
'step': 6,
},
'post_proposal_review_discussion': {
......@@ -455,7 +457,7 @@ DoubleStageDefinition = {
},
'display': 'Under Discussion',
'stage': Proposal,
'permissions': default_permissions,
'permissions': hidden_from_applicant_permissions,
'step': 7,
},
'post_proposal_review_more_info': {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment