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

Edit supplier declaration #135

Merged
merged 8 commits into from
Oct 14, 2015
Merged
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
7 changes: 3 additions & 4 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
feature_flags = flask_featureflags.FeatureFlag()
login_manager = LoginManager()

service_content = ContentLoader(
"app/content/frameworks/g-cloud-6/manifests/edit_service_as_admin.yml",
"app/content/frameworks/g-cloud-6/questions/services/"
)
content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'edit_service_as_admin')
content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration')


from app.main.helpers.service import parse_document_upload_time
Expand Down
1 change: 1 addition & 0 deletions app/assets/scss/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ $path: "/admin/static/images/";
@import "views/view_audits";
@import "_diff.scss";
@import "views/statistics";
@import "views/view_declaration";

// Graphs
@import "_c3";
3 changes: 3 additions & 0 deletions app/assets/scss/views/_view_declaration.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.declaration-summary thead .summary-item-field-heading-first {
width: 60%;
}
10 changes: 5 additions & 5 deletions app/main/views/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


from ... import data_api_client
from ... import service_content
from ... import content_loader
from .. import main
from . import get_template_data

Expand Down Expand Up @@ -51,7 +51,7 @@ def view(service_id):
return redirect(url_for('.index'))

service_data['priceString'] = format_service_price(service_data)
content = service_content.get_builder().filter(service_data)
content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service_data)

template_data = get_template_data(
sections=content,
Expand Down Expand Up @@ -101,7 +101,7 @@ def update_service_status(service_id):
def edit(service_id, section):
service_data = data_api_client.get_service(service_id)['services']

content = service_content.get_builder().filter(service_data)
content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service_data)

template_data = get_template_data(
section=content.get_section(section),
Expand Down Expand Up @@ -153,7 +153,7 @@ def validate_archived_services(old_archived_service, new_archived_service):
except (HTTPError, KeyError, ValueError):
return abort(404)

content = service_content.get_builder().filter(service_data)
content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service_data)

# It's possible to have an empty array if none of the lines were changed.
# TODO This possibility isn't actually handled.
Expand Down Expand Up @@ -188,7 +188,7 @@ def update(service_id, section_id):
abort(404)
service = service['services']

content = service_content.get_builder().filter(service)
content = content_loader.get_builder('g-cloud-6', 'edit_service_as_admin').filter(service)
section = content.get_section(section_id)
if section is None or not section.editable:
abort(404)
Expand Down
92 changes: 87 additions & 5 deletions app/main/views/suppliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

from .. import main
from . import get_template_data
from ... import data_api_client
from ... import data_api_client, content_loader
from ..forms import EmailAddressForm
from ..auth import role_required
from dmutils.apiclient.errors import HTTPError
from dmutils.apiclient.errors import HTTPError, APIError
from dmutils.audit import AuditTypes
from dmutils.email import send_email, \
generate_token, MandrillException
from dmutils.email import send_email, generate_token, MandrillException


@main.route('/suppliers', methods=['GET'])
@login_required
@role_required('admin', 'admin-ccs-category')
@role_required('admin', 'admin-ccs-category', 'admin-ccs-sourcing')
def find_suppliers():
suppliers = data_api_client.find_suppliers(prefix=request.args.get("supplier_name_prefix"))

Expand All @@ -39,6 +38,89 @@ def edit_supplier_name(supplier_id):
)


@main.route('/suppliers/<string:supplier_id>/edit/declarations/<string:framework_slug>', methods=['GET'])
@login_required
@role_required('admin-ccs-sourcing')
def view_supplier_declaration(supplier_id, framework_slug):
supplier = data_api_client.get_supplier(supplier_id)['suppliers']
framework = data_api_client.get_framework(framework_slug)['frameworks']
try:
declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration']
except APIError as e:
if e.status_code != 404:
raise
declaration = {}

content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration)

return render_template(
"suppliers/view_declaration.html",
supplier=supplier,
framework=framework,
declaration=declaration,
content=content,
**get_template_data())


@main.route(
'/suppliers/<string:supplier_id>/edit/declarations/<string:framework_slug>/<string:section_id>',
methods=['GET'])
@login_required
@role_required('admin-ccs-sourcing')
def edit_supplier_declaration_section(supplier_id, framework_slug, section_id):
supplier = data_api_client.get_supplier(supplier_id)['suppliers']
framework = data_api_client.get_framework(framework_slug)['frameworks']
try:
declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration']
except APIError as e:
if e.status_code != 404:
raise
declaration = {}

content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration)
section = content.get_section(section_id)
if section is None:
abort(404)

return render_template(
"suppliers/edit_declaration.html",
supplier=supplier,
framework=framework,
declaration=declaration,
section=section,
**get_template_data())


@main.route(
'/suppliers/<string:supplier_id>/edit/declarations/<string:framework_slug>/<string:section_id>',
methods=['POST'])
def update_supplier_declaration_section(supplier_id, framework_slug, section_id):
supplier = data_api_client.get_supplier(supplier_id)['suppliers']
framework = data_api_client.get_framework(framework_slug)['frameworks']
try:
declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration']
except APIError as e:
if e.status_code != 404:
raise
declaration = {}

content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration)
section = content.get_section(section_id)
if section is None:
abort(404)

posted_data = section.get_data(request.form)

if section.has_changes_to_save(declaration, posted_data):
declaration.update(posted_data)
data_api_client.set_supplier_declaration(
supplier_id, framework_slug, declaration,
current_user.email_address)

return redirect(url_for('.view_supplier_declaration',
supplier_id=supplier_id, framework_slug=framework_slug))


@main.route('/suppliers/<string:supplier_id>/edit/name', methods=['POST'])
@login_required
@role_required('admin')
Expand Down
8 changes: 7 additions & 1 deletion app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
{% include "toolkit/page-heading.html" %}
{% endwith %}

{% if current_user.has_role('admin') or current_user.has_role('admin-ccs-category') %}
{% if current_user.has_any_role('admin', 'admin-ccs-category', 'admin-ccs-sourcing') %}
<div class="grid-row">
<div class="column-two-thirds">
{% if current_user.has_any_role('admin', 'admin-ccs-category') %}
<form action="{{ url_for('.find') }}" method="get" class="question">
<label class="question-heading" for="service_id">Find a service by service ID</label>
<p class='hint'>
Expand All @@ -61,6 +62,7 @@
<input type="text" name="supplier_id" id="supplier_id_for_users" class="text-box">
<input type="submit" value="Search" class="button-save">
</form>
{% endif %}

<form action="{{ url_for('.find_suppliers') }}" method="get" class="question">
<label class="question-heading" for="supplier_name_prefix">Find suppliers by name prefix</label>
Expand All @@ -71,6 +73,8 @@
<input type="submit" value="Search" class="button-save">
</form>

{% if current_user.has_any_role('admin') %}

<form action="{{ url_for('.find_user_by_email_address') }}" method="get" class="question">
<label class="question-heading" for="email_address">Find users by email address</label>
<p class='hint'>
Expand All @@ -79,6 +83,8 @@
<input type="text" name="email_address" id="email_address" class="text-box">
<input type="submit" value="Search" class="button-save">
</form>

{% endif %}
</div>
</div>
{% endif %}
Expand Down
46 changes: 46 additions & 0 deletions app/templates/suppliers/edit_declaration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% import 'macros/toolkit_forms.html' as forms %}

{% extends "_base_page.html" %}

{% block page_title %}
Change {{ framework.name }} declaration
{% endblock %}

{% block content %}
<div class="page-container edit-section">
<div class="grid-row">
<div class="service-title">
{%
with
context = supplier.name,
heading = section.name,
smaller = True
%}
{% include "toolkit/page-heading.html" %}
{% endwith %}
</div>
</div>

<form method="post" enctype="multipart/form-data">
<div class="grid-row">
<div class="column-two-thirds">
<div style="display:none;"><input id="csrf_token" name="csrf_token" type="hidden" value="{{ csrf_token() }}"></div>
{% for question in section.questions %}
{{ forms[question.type](question, declaration, {}) }}
{% endfor %}
{%
with
type = "save",
label = "Save and return to summary"
%}
{% include "toolkit/button.html" %}
{% endwith %}
<p>
<a href="{{ url_for('.view_supplier_declaration', supplier_id=supplier.id, framework_slug=framework.slug) }}">Return without saving</a>
</p>
</div>
</div>
</div>
</form>
</div>
{% endblock %}
44 changes: 44 additions & 0 deletions app/templates/suppliers/view_declaration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% import "toolkit/summary-table.html" as summary %}

{% extends "_base_page.html" %}

{% block page_title %}
Change {{ framework.name }} declaration
{% endblock %}

{% block content %}
<div class="page-container declaration-summary">
<div class="grid-row">
<div class="service-title">
{%
with
context = supplier.name,
heading = framework.name + " declaration",
smaller = True
%}
{% include "toolkit/page-heading.html" %}
{% endwith %}
</div>
</div>

{% for section in content %}
{{ summary.heading(section.name) }}
{{ summary.top_link("Edit", url_for('.edit_supplier_declaration_section', supplier_id=supplier.id, framework_slug=framework.slug, section_id=section.id)) }}
{% call(item) summary.list_table(
section.questions,
caption="Declaration",
empty_message="This supplier not made a declaration",
field_headings=[
'Declaration question',
'Declaration answer'
]
) %}
{% call summary.row() %}
{{ summary.field_name(item.question) }}
{{ summary[item.type](declaration[item.id]) }}
{% endcall %}
{% endcall %}
{% endfor %}
</div>

{% endblock %}
36 changes: 26 additions & 10 deletions app/templates/view_suppliers.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,45 @@
{% endwith %}

<div class="page-section">
{% call(item) summary.list_table(
suppliers,
caption="Suppliers",
empty_message="No suppliers were found",
field_headings=[
{% if current_user.has_role("admin") %}
{% set field_headings = [
"Name",
summary.hidden_field_heading("Edit name"),
summary.hidden_field_heading("Change name"),
summary.hidden_field_heading("Users"),
summary.hidden_field_heading("Services"),
] if current_user.has_role('admin') else [
] %}
{% elif current_user.has_role("admin-ccs-sourcing") %}
{% set field_headings = [
"Name",
summary.hidden_field_heading("Change declarations"),
] %}
{% else %}
{% set field_headings = [
"Name",
summary.hidden_field_heading("Users"),
summary.hidden_field_heading("Services"),
],
] %}
{% endif %}

{% call(item) summary.list_table(
suppliers,
caption="Suppliers",
empty_message="No suppliers were found",
field_headings=field_headings,
field_headings_visible=True)
%}
{% call summary.row() %}
{{ summary.field_name(item.name) }}
{% if current_user.has_role('admin') %}
{{ summary.edit_link("Change name", url_for(".edit_supplier_name", supplier_id=item.id)) }}
{% endif %}
{{ summary.edit_link("Users", url_for(".find_supplier_users", supplier_id=item.id)) }}
{{ summary.edit_link("Services", url_for(".find_supplier_services", supplier_id=item.id)) }}
{% if current_user.has_role('admin-ccs-sourcing') %}
{{ summary.edit_link("G-Cloud 7 declaration", url_for(".view_supplier_declaration", supplier_id=item.id, framework_slug="g-cloud-7")) }}
{% endif %}
{% if current_user.has_any_role('admin', 'admin-ccs-category') %}
{{ summary.edit_link("Users", url_for(".find_supplier_users", supplier_id=item.id)) }}
{{ summary.edit_link("Services", url_for(".find_supplier_services", supplier_id=item.id)) }}
{% endif %}
{% endcall %}
{% endcall %}
</div>
Expand Down
17 changes: 17 additions & 0 deletions example_responses/declaration_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"declaration": {
"PR1": true,
"PR2": false,
"SQC2": true,
"PR5": false,
"PR3": true,
"PR4": false,
"SQ1-3": [],
"SQA2": false,
"SQA3": true,
"SQA4": false,
"SQA5": true,
"AQA3": false,
"SQC3": ["race", "sexual orientation"]
}
}
6 changes: 6 additions & 0 deletions example_responses/framework_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"frameworks": {
"slug": "g-cloud-7",
"name": "G-Cloud 7"
}
}
Loading