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

FS-4001: Add Assigned to you section to assessment overview #690

Draft
wants to merge 5 commits into
base: main
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
6 changes: 3 additions & 3 deletions app/blueprints/assessments/forms/assignment_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class AssessmentAssignmentForm(FlaskForm):
def validate(self, extra_validators=None):
if super().validate(extra_validators):
if request.referrer != request.url:
# From a redirect, not a form post
return False
# if request.referrer != request.url:
# # From a redirect, not a form post
# return False

if not (
selected_assessments := request.form.getlist("selected_assessments")
Expand Down
83 changes: 77 additions & 6 deletions app/blueprints/assessments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ def assessor_type(fund_short_name: str, round_short_name: str):
if not (selected_assessments := request.form.getlist("selected_assessments")):
abort(500, "Required selected_assessments field to be populated")

from_form = request.form.get("from_form")

selected_assessor_role = (
request.form.getlist("assessor_role")[0]
if request.form.getlist("assessor_role")
Expand Down Expand Up @@ -567,6 +569,7 @@ def assessor_type(fund_short_name: str, round_short_name: str):
round_details=round_details,
stats=unfiltered_stats,
form=form,
from_form=from_form,
)


Expand All @@ -589,6 +592,8 @@ def assessor_type_list(fund_short_name: str, round_short_name: str):
if not (selected_assessments := request.form.getlist("selected_assessments")):
abort(500, "Required selected_assessments field to be populated")

from_form = request.form.get("from_form")

if not (assessor_role := request.form.getlist("assessor_role")):
abort(500, "Required assessor_role field to be populated")

Expand Down Expand Up @@ -707,6 +712,7 @@ def assessor_type_list(fund_short_name: str, round_short_name: str):
selected_users=selected_users,
assigned_users=assigned_users,
form=form,
from_form=from_form,
)


Expand Down Expand Up @@ -930,6 +936,8 @@ def assignment_overview(fund_short_name: str, round_short_name: str):

request.form = ImmutableMultiDict(new_request_form)

from_form = request.form.get("from_form")

assigned_user_set = set(request.form.getlist("assigned_users"))
selected_user_set = set(request.form.getlist("selected_users"))

Expand Down Expand Up @@ -1106,13 +1114,21 @@ def assignment_overview(fund_short_name: str, round_short_name: str):
f"Could not create assignment for user {user_id} and application {application_id}"
)

return redirect(
url_for(
"assessment_bp.fund_dashboard",
fund_short_name=fund_short_name,
round_short_name=round_short_name,
if from_form == "True":
return redirect(
url_for(
"assessment_bp.application",
application_id=application_id,
)
)
else:
return redirect(
url_for(
"assessment_bp.fund_dashboard",
fund_short_name=fund_short_name,
round_short_name=round_short_name,
)
)
)

thread_executor.executor.shutdown()

Expand Down Expand Up @@ -1168,6 +1184,7 @@ def assignment_overview(fund_short_name: str, round_short_name: str):
assessments=post_processed_overviews,
form=form,
assessment_statuses=assessment_statuses,
from_form=from_form,
)


Expand Down Expand Up @@ -1629,6 +1646,54 @@ def application(application_id):
)
)

thread_executor = ContextAwareExecutor(
max_workers=4,
thread_name_prefix="application-request",
flask_app=current_app,
)

# Get all the users for the fund
future_users_for_fund = thread_executor.submit(
get_users_for_fund,
state.fund_short_name,
None, # round_short_name,
True,
False,
)

future_existing_assignments = thread_executor.submit(
get_application_assignments, application_id, True
)

users_for_fund = future_users_for_fund.result()
existing_assignments = future_existing_assignments.result()
all_assigned_users = set(
assignment["user_id"] for assignment in existing_assignments
)
assigned_lead_assessors = [
user
for user in users_for_fund
if user["account_id"] in all_assigned_users
and any(Config.LEAD_ASSESSOR in role for role in user["roles"])
]
assigned_assessors = [
user
for user in users_for_fund
if user["account_id"] in all_assigned_users
and any(Config.ASSESSOR in role for role in user["roles"])
]

thread_executor.executor.shutdown()

assigner_account, assignment_date, assigner_name = None, None, None
if len(existing_assignments) > 0:
assigner_account = get_bulk_accounts_dict(
[existing_assignments[-1]["assigner_id"]],
state.fund_short_name,
)
assigner_name = next(iter(assigner_account.values()))["full_name"]
assignment_date = existing_assignments[-1]["created_at"]

return render_template(
"assessor_tasklist.html",
sub_criteria_status_completed=sub_criteria_status_completed,
Expand All @@ -1654,6 +1719,12 @@ def application(application_id):
comment_id=comment_id,
comment_form=comment_form,
comments=theme_matched_comments,
assigned_lead_assessors=assigned_lead_assessors,
assigned_assessors=assigned_assessors,
assignment_date=assignment_date,
assigner_name=assigner_name,
round_short_name=fund_round.short_name,
fund_short_name=state.fund_short_name,
)


Expand Down
3 changes: 3 additions & 0 deletions app/blueprints/assessments/templates/assessor_tasklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{% from "macros/migration_banner.html" import migration_banner %}
{% from "macros/link_to_download_contract_docs.html" import link_to_download_contract_docs %}
{% from "macros/assessment_actions.html" import assessment_actions %}
{% from "macros/assigned_to.html" import assigned_to %}

{% set pageHeading = state.project_name %}

Expand Down Expand Up @@ -51,6 +52,8 @@
<div class="govuk-grid-row">
{# djlint:on #}
<div class="govuk-grid-column-one-quarter">
{{ assigned_to(assigned_assessors, assignment_date, assigner_name, form, application_id, fund_short_name, round_short_name) }}

{% if g.access_controller.is_assessor %}
{{ assessment_actions(application_id) }}
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion app/blueprints/assessments/templates/assessor_type.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% set pageHeading %}Team dashboard{% endset %}

{% block header %}
{{ team_dashboard_header.render(round_details, stats, team_flag_stats, is_active_status) }}
{{ team_dashboard_header.render(round_details, stats, team_flag_stats, is_active_status, selected_assessments, from_form) }}
{% endblock header %}

{% block content %}
Expand Down Expand Up @@ -57,6 +57,7 @@ <h2 class="govuk-error-summary__title">
round_short_name=round_details.round_short_name) }}">
{{ form.csrf_token }}
{% for assessment in selected_assessments %}
<input type="hidden" name="from_form" value="{{ from_form }}">
<input type="hidden" name="selected_assessments" value="{{ assessment }}">
{% endfor %}
<div class="govuk-radios" id="assessor-type-selection">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{% set pageHeading %}Team dashboard{% endset %}

{% block header %}
{{ team_dashboard_header.render(round_details, stats, team_flag_stats, is_active_status) }}
{{ team_dashboard_header.render(round_details, stats, team_flag_stats, is_active_status, selected_assessments, from_form) }}
{% endblock header %}

{% block content %}
Expand Down Expand Up @@ -72,6 +72,7 @@ <h1 class="govuk-heading-l">Assign assessments to {{ "lead" if assessor_role ==
{% for key, value in assessor_messages.items() %}
<input type="hidden" name="{{ key }}" value="{{ value }}">
{% endfor %}
<input type="hidden" name="from_form" value="{{ from_form }}">
<p class="govuk-body">
<button type="submit" class="govuk-link btn-link" name="change_roles" value="change_roles">Change roles</button> or
<button type="submit" class="govuk-link btn-link" name="change_users" value="change_users">Change users</button>
Expand Down
29 changes: 29 additions & 0 deletions app/blueprints/assessments/templates/macros/assigned_to.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% macro assigned_to(assigned_assessors, assignment_date, assigner_name, form, application_id, fund_short_name, round_short_name) %}
<h3 class="govuk-heading-m">Assigned to you</h3>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible section_break_blue">

{% if assigner_name is not none %}
<p class="govuk-body">
<strong>{{ assigner_name }}</strong> assigned the assessors:
</p>
<ul class="govuk-list">
{%for assessor in assigned_assessors%}
<li>{{ assessor.full_name }}</li>
{%endfor%}
</ul>
<p class="govuk-body">
{{ assignment_date | utc_to_bst }}
</p>
{% endif %}

{% if g.user.highest_role_map[fund_short_name] == 'LEAD_ASSESSOR' %}
<form method="post" action="{{ url_for('assessment_bp.assign_assessments', fund_short_name=fund_short_name, round_short_name=round_short_name) }}">
{{ form.csrf_token }}
<input type="hidden" id="selected_assessments" name="selected_assessments" value={{ application_id }} />
<input type="hidden" id="from_form" name="from_form" value="True" />
<button type="submit" class="govuk-button secondary-button govuk-!-margin-top-2 govuk-!-margin-bottom-6">
Reassign assessment
</button>
</form>
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{%- from 'govuk_frontend_jinja/components/back-link/macro.html' import govukBackLink -%}
{% from "macros/logout_partial.html" import logout_partial %}

{% macro render(round_details, stats, team_flag_stats, is_active_status, sso_logout_url) %}
{% macro render(round_details, stats, team_flag_stats, is_active_status, selected_assessments, from_form, sso_logout_url ) %}

<header role="banner" data-module="govuk-header">
<nav class="govuk-width-container govuk-header__navigation">
<div class="govuk-phase-banner flex-parent-element">
<p class="govuk-!-text-align-left govuk-!-margin-left-3 flex-parent-element flexed-element-margins-collapse">
{{ govukBackLink({'href': url_for("assessment_bp.landing"), 'html': 'Back to <b>assessment landing</b>',
'attributes': {'data-qa': 'back-to-assessment-overview-link'} }) }}
{% if from_form == 'True' %}
{{ govukBackLink({'href': url_for("assessment_bp.application", application_id=selected_assessments[0]), 'html': 'Back to <b>assessment</b>',
'attributes': {'data-qa': 'back-to-assessment-overview-link'} }) }}
{% else %}
{{ govukBackLink({'href': url_for("assessment_bp.landing"), 'html': 'Back to <b>assessment landing</b>',
'attributes': {'data-qa': 'back-to-assessment-overview-link'} }) }}
{% endif %}
</p>
{{ logout_partial(sso_logout_url) }}
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/blueprints/assessments/templates/select_assessor.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% set pageHeading %}Team dashboard{% endset %}

{% block header %}
{{ team_dashboard_header.render(round_details, stats, team_flag_stats, is_active_status) }}
{{ team_dashboard_header.render(round_details, stats, team_flag_stats, is_active_status, selected_assessments, from_form) }}
{% endblock header %}

{% block content %}
Expand Down Expand Up @@ -58,6 +58,7 @@ <h2 class="govuk-error-summary__title">
<input type="hidden" name="assigned_users" value="{{ user_id }}">
{% endfor %}
<input type="hidden" name="assessor_role" value="{{ assessor_role }}">
<input type="hidden" name="from_form" value="{{ from_form }}">
{% if form.form_errors %}
<p class="govuk-error-message">
{% for error in form.form_errors %}
Expand Down
1 change: 1 addition & 0 deletions app/blueprints/shared/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def utc_to_bst(value, tz="Europe/London", export_format=False):
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%d %H:%M:%S.%f%z",
"%d/%m/%Y %H:%M:%S",
"%Y-%m-%dT%H:%M:%S.%f%z",
]
for dt_format in dt_formats:
try:
Expand Down
Loading