From a504128817226a6dbcad6bb99f01f8b765bdf31b Mon Sep 17 00:00:00 2001 From: Rob Young Date: Fri, 9 Oct 2015 16:37:40 +0100 Subject: [PATCH] Add ability to edit supplier declarations This adds the ability for a CCS Sourcing team member to view and edit G-Cloud 7 supplier declarations. In the supplier listing the only link they will see alongside a supplier is 'G-Cloud 7 declaration'. This will take them to the G-Cloud 7 supplier declaration overview where they can edit each section. This uses the new ContentLoader but hard codes the G-Cloud 7 link in the supplier list as it is the only framework they can edit at the moment. Note that this does no validation, it is assumed that the CCS Sourcing team know the rules. --- app/__init__.py | 1 + app/assets/scss/application.scss | 1 + app/assets/scss/views/_view_declaration.scss | 3 + app/main/views/suppliers.py | 72 +++++++++++++++++-- app/templates/index.html | 2 +- app/templates/suppliers/edit_declaration.html | 46 ++++++++++++ app/templates/suppliers/view_declaration.html | 44 ++++++++++++ app/templates/view_suppliers.html | 36 +++++++--- 8 files changed, 189 insertions(+), 16 deletions(-) create mode 100644 app/assets/scss/views/_view_declaration.scss create mode 100644 app/templates/suppliers/edit_declaration.html create mode 100644 app/templates/suppliers/view_declaration.html diff --git a/app/__init__.py b/app/__init__.py index f515b9b2f..c16390e78 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -20,6 +20,7 @@ content_loader = ContentLoader('app/content') content_loader.load_manifest('g-cloud-6', 'edit_service_as_admin', 'services') +content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration') from app.main.helpers.service import parse_document_upload_time diff --git a/app/assets/scss/application.scss b/app/assets/scss/application.scss index c78e8be67..8cfa4c7b7 100644 --- a/app/assets/scss/application.scss +++ b/app/assets/scss/application.scss @@ -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"; diff --git a/app/assets/scss/views/_view_declaration.scss b/app/assets/scss/views/_view_declaration.scss new file mode 100644 index 000000000..4c0b62704 --- /dev/null +++ b/app/assets/scss/views/_view_declaration.scss @@ -0,0 +1,3 @@ +.my-special-page thead .summary-item-field-heading-first { + width: 60%; +} diff --git a/app/main/views/suppliers.py b/app/main/views/suppliers.py index 48f184e99..20176b950 100644 --- a/app/main/views/suppliers.py +++ b/app/main/views/suppliers.py @@ -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")) @@ -39,6 +38,69 @@ def edit_supplier_name(supplier_id): ) +@main.route('/suppliers//edit/declarations/', 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'] + declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['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//edit/declarations//', + 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'] + declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration'] + + content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration) + + return render_template( + "suppliers/edit_declaration.html", + supplier=supplier, + framework=framework, + declaration=declaration, + section=content.get_section(section_id), + **get_template_data()) + + +@main.route( + '/suppliers//edit/declarations//', + 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'] + declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration'] + + content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration) + section = content.get_section(section_id) + + 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//edit/name', methods=['POST']) @login_required @role_required('admin') diff --git a/app/templates/index.html b/app/templates/index.html index d1e3af32a..b14cb7e3e 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -32,7 +32,7 @@ {% 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') %}
diff --git a/app/templates/suppliers/edit_declaration.html b/app/templates/suppliers/edit_declaration.html new file mode 100644 index 000000000..adbc99e0c --- /dev/null +++ b/app/templates/suppliers/edit_declaration.html @@ -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 %} +
+
+
+ {% + with + context = supplier.name, + heading = section.name, + smaller = True + %} + {% include "toolkit/page-heading.html" %} + {% endwith %} +
+
+ + +
+
+
+ {% 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 %} +

+ Return without saving +

+
+
+
+
+
+{% endblock %} diff --git a/app/templates/suppliers/view_declaration.html b/app/templates/suppliers/view_declaration.html new file mode 100644 index 000000000..698a1771e --- /dev/null +++ b/app/templates/suppliers/view_declaration.html @@ -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 %} +
+
+
+ {% + with + context = supplier.name, + heading = framework.name + " declaration", + smaller = True + %} + {% include "toolkit/page-heading.html" %} + {% endwith %} +
+
+ + {% 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 %} +
+ +{% endblock %} diff --git a/app/templates/view_suppliers.html b/app/templates/view_suppliers.html index 2c2a55e0d..fa3098c35 100644 --- a/app/templates/view_suppliers.html +++ b/app/templates/view_suppliers.html @@ -23,20 +23,31 @@ {% endwith %}
- {% 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() %} @@ -44,8 +55,13 @@ {% 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 %}