Skip to content

Commit

Permalink
Merge branch 'main' into 2499-pol-repo-loggedout-view
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilR8 committed Feb 9, 2024
2 parents 92a7001 + 1d043a9 commit 30d9e84
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 15 deletions.
2 changes: 1 addition & 1 deletion solution/backend/cmcs_regulations/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'csp.middleware.CSPMiddleware',
'regulations.middleware.JsonErrors',
'regulations.middleware.NoIndex',
'regulations.middleware.ProcessResponse',
'regcore.middleware.HtmlApi',
]

Expand Down
9 changes: 8 additions & 1 deletion solution/backend/regulations/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
from regulations.models import SiteConfiguration


class NoIndex:
class ProcessResponse:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
config = SiteConfiguration.objects.first()
response = self.get_response(request)

# Add Strict-Transport-Security header if HTTPS
if request.is_secure() and not response.get("Strict-Transport-Security"):
response["Strict-Transport-Security"] = "max-age=63072000; includeSubDomains; preload"

# Add X-Robots-Tag header based on configuration
if not config.allow_indexing:
response["X-Robots-Tag"] = "noindex"

return response


Expand Down
84 changes: 80 additions & 4 deletions solution/ui/e2e/cypress/e2e/policy-repository.spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,61 @@ describe("Policy Repository", () => {
cy.url().should("include", "/resources");
});

it("returns you to the policy repo logged out view when you log out", () => {
it("should have the correct labels for public and internal documents", () => {
cy.intercept("**/v3/content-search/?q=test**", {
fixture: "policy-docs.json",
}).as("queriedFiles");
cy.viewport("macbook-15");
cy.eregsLogin({
username,
password,
landingPage: "/policy-repository/",
});
cy.visit("/policy-repository/");
cy.get("input#main-content")
.should("be.visible")
.type("test", { force: true });
cy.get(".search-field .v-input__icon--append button").click({
force: true,
});
cy.wait("@queriedFiles").then((interception) => {
expect(interception.response.statusCode).to.eq(200);
});

// Public doc
cy.get(".category-labels")
.eq(0)
.find(".doc-type__label")
.should("include.text", " Public ")
.find("i")
.should("have.class", "fa-users");
cy.get(".category-labels")
.eq(0)
.find(".category-label")
.should("include.text", " Subregulatory Guidance ");
cy.get(".category-labels")
.eq(0)
.find(".subcategory-label")
.should("include.text", "CMCS Informational Bulletin (CIB)");

// Internal doc
cy.get(".category-labels")
.eq(1)
.find(".doc-type__label")
.should("include.text", " Internal ")
.find("i")
.should("have.class", "fa-key");
cy.get(".category-labels")
.eq(1)
.find(".category-label")
.should("include.text", "TestCat");
cy.get(".category-labels")
.eq(1)
.find(".subcategory-label")
.should("include.text", "TestSubCat");
});

it("returns you to the custom eua login page when you log out", () => {
cy.viewport("macbook-15");
cy.eregsLogin({
username,
Expand Down Expand Up @@ -656,7 +710,7 @@ describe("Policy Repository Search", () => {
});
});

it("should have the correct public/internal label", () => {
it("should have the correct labels for public and internal documents", () => {
cy.intercept("**/v3/content-search/?q=test**", {
fixture: "policy-docs.json",
}).as("queriedFiles");
Expand All @@ -676,15 +730,37 @@ describe("Policy Repository Search", () => {
cy.wait("@queriedFiles").then((interception) => {
expect(interception.response.statusCode).to.eq(200);
});
cy.get(".doc-type__label")

// Public doc
cy.get(".category-labels")
.eq(0)
.find(".doc-type__label")
.should("include.text", " Public ")
.find("i")
.should("have.class", "fa-users");
cy.get(".doc-type__label")
cy.get(".category-labels")
.eq(0)
.find(".category-label")
.should("include.text", " Subregulatory Guidance ");
cy.get(".category-labels")
.eq(0)
.find(".subcategory-label")
.should("include.text", "CMCS Informational Bulletin (CIB)");

// Internal doc
cy.get(".category-labels")
.eq(1)
.find(".doc-type__label")
.should("include.text", " Internal ")
.find("i")
.should("have.class", "fa-key");
cy.get(".category-labels")
.eq(1)
.find(".category-label")
.should("include.text", "TestCat");
cy.get(".category-labels")
.eq(1)
.find(".subcategory-label")
.should("include.text", "TestSubCat");
});
});
17 changes: 16 additions & 1 deletion solution/ui/e2e/cypress/fixtures/policy-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,22 @@
"abbreviation": null
}
],
"category": {},
"category": {
"id": 2,
"name": "TestSubCat",
"description": "",
"order": 0,
"show_if_empty": false,
"type": "repositorysubcategory",
"parent": {
"id": 1,
"name": "TestCat",
"description": "This is a test category. It may have child subcategories.",
"order": 0,
"show_if_empty": false,
"type": ""
}
},
"url": "d89af093-8975-4bcb-a747-abe346ebb274",
"document_name_headline": "[Mock] Cypress Fixture",
"summary_headline": "This is the summary. Rubber <span class=\"search-highlight\">baby</span> buggy bumper"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,33 @@ const resultLinkClasses = (doc) => ({
/>
<template v-if="doc.resource_type === 'internal'">
<CategoryLabel
v-if="!_isEmpty(doc.document_type)"
:name="doc.document_type.name"
v-if="!_isEmpty(doc.category)"
:name="
doc.category?.parent
? doc.category?.parent?.name
: doc.category?.name
"
type="category"
/>
<CategoryLabel
v-if="doc.category?.parent"
:name="doc.category?.name"
type="subcategory"
/>
</template>
<template v-else>
<CategoryLabel
v-if="!_isEmpty(doc.category)"
:name="
doc.category.parent
? doc.category.parent.name
: doc.category.name
doc.category?.parent
? doc.category?.parent?.name
: doc.category?.name
"
type="category"
/>
<CategoryLabel
v-if="doc.category?.parent"
:name="doc.category.name"
:name="doc.category?.name"
type="subcategory"
/>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ exports[`Supplemental Content > Checks to see if the snap shot matches 1`] = `
>
Subpart A Resources
</h2>
<!---->
<div
class="supplemental-content-container"
>
Expand Down Expand Up @@ -5902,7 +5901,6 @@ exports[`Supplemental Content > Checks to see if the snap shot matches 1`] = `
>
Subpart A Resources
</h2>
<!---->
<div
class="supplemental-content-container"
>
Expand Down

0 comments on commit 30d9e84

Please sign in to comment.