Merge branch 'main' into za/2348-csv-export-org-member-domain-export

This commit is contained in:
zandercymatics 2024-08-02 07:50:38 -06:00
commit a4f1170349
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
43 changed files with 435 additions and 172 deletions

View file

@ -29,6 +29,7 @@ on:
- hotgov - hotgov
- litterbox - litterbox
- ms - ms
- ad
# GitHub Actions has no "good" way yet to dynamically input branches # GitHub Actions has no "good" way yet to dynamically input branches
branch: branch:
description: 'Branch to deploy' description: 'Branch to deploy'

View file

@ -29,6 +29,7 @@ jobs:
|| startsWith(github.head_ref, 'litterbox/') || startsWith(github.head_ref, 'litterbox/')
|| startsWith(github.head_ref, 'ag/') || startsWith(github.head_ref, 'ag/')
|| startsWith(github.head_ref, 'ms/') || startsWith(github.head_ref, 'ms/')
|| startsWith(github.head_ref, 'ad/')
outputs: outputs:
environment: ${{ steps.var.outputs.environment}} environment: ${{ steps.var.outputs.environment}}
runs-on: "ubuntu-latest" runs-on: "ubuntu-latest"

View file

@ -16,6 +16,7 @@ on:
- stable - stable
- staging - staging
- development - development
- ad
- ms - ms
- ag - ag
- litterbox - litterbox

View file

@ -16,6 +16,7 @@ on:
options: options:
- staging - staging
- development - development
- ad
- ms - ms
- ag - ag
- litterbox - litterbox

View file

@ -0,0 +1,32 @@
---
applications:
- name: getgov-ad
buildpacks:
- python_buildpack
path: ../../src
instances: 1
memory: 512M
stack: cflinuxfs4
timeout: 180
command: ./run.sh
health-check-type: http
health-check-http-endpoint: /health
health-check-invocation-timeout: 40
env:
# Send stdout and stderr straight to the terminal without buffering
PYTHONUNBUFFERED: yup
# Tell Django where to find its configuration
DJANGO_SETTINGS_MODULE: registrar.config.settings
# Tell Django where it is being hosted
DJANGO_BASE_URL: https://getgov-ad.app.cloud.gov
# Tell Django how much stuff to log
DJANGO_LOG_LEVEL: INFO
# default public site location
GETGOV_PUBLIC_SITE_URL: https://get.gov
# Flag to disable/enable features in prod environments
IS_PRODUCTION: False
routes:
- route: getgov-ad.app.cloud.gov
services:
- getgov-credentials
- getgov-ad-database

9
src/package-lock.json generated
View file

@ -9,7 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@uswds/uswds": "^3.8.0", "@uswds/uswds": "^3.8.1",
"pa11y-ci": "^3.0.1", "pa11y-ci": "^3.0.1",
"sass": "^1.54.8" "sass": "^1.54.8"
}, },
@ -187,9 +187,10 @@
} }
}, },
"node_modules/@uswds/uswds": { "node_modules/@uswds/uswds": {
"version": "3.8.0", "version": "3.8.1",
"resolved": "https://registry.npmjs.org/@uswds/uswds/-/uswds-3.8.0.tgz", "resolved": "https://registry.npmjs.org/@uswds/uswds/-/uswds-3.8.1.tgz",
"integrity": "sha512-rMwCXe/u4HGkfskvS1Iuabapi/EXku3ChaIFW7y/dUhc7R1TXQhbbfp8YXEjmXPF0yqJnv9T08WPgS0fQqWZ8w==", "integrity": "sha512-bKG/B9mJF1v0yoqth48wQDzST5Xyu3OxxpePIPDyhKWS84oDrCehnu3Z88JhSjdIAJMl8dtjtH8YvdO9kZUpAg==",
"license": "SEE LICENSE IN LICENSE.md",
"dependencies": { "dependencies": {
"classlist-polyfill": "1.2.0", "classlist-polyfill": "1.2.0",
"object-assign": "4.1.1", "object-assign": "4.1.1",

View file

@ -10,7 +10,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@uswds/uswds": "^3.8.0", "@uswds/uswds": "^3.8.1",
"pa11y-ci": "^3.0.1", "pa11y-ci": "^3.0.1",
"sass": "^1.54.8" "sass": "^1.54.8"
}, },

View file

@ -207,15 +207,11 @@ function addOrRemoveSessionBoolean(name, add){
})(); })();
/** An IIFE for pages in DjangoAdmin that use a clipboard button /** An IIFE for pages in DjangoAdmin that use a clipboard button
*/ */
(function (){ (function (){
function copyInnerTextToClipboard(elem) {
let text = elem.innerText
navigator.clipboard.writeText(text)
}
function copyToClipboardAndChangeIcon(button) { function copyToClipboardAndChangeIcon(button) {
// Assuming the input is the previous sibling of the button // Assuming the input is the previous sibling of the button
let input = button.previousElementSibling; let input = button.previousElementSibling;
@ -224,7 +220,7 @@ function addOrRemoveSessionBoolean(name, add){
if (input) { if (input) {
navigator.clipboard.writeText(input.value).then(function() { navigator.clipboard.writeText(input.value).then(function() {
// Change the icon to a checkmark on successful copy // Change the icon to a checkmark on successful copy
let buttonIcon = button.querySelector('.usa-button__clipboard use'); let buttonIcon = button.querySelector('.copy-to-clipboard use');
if (buttonIcon) { if (buttonIcon) {
let currentHref = buttonIcon.getAttribute('xlink:href'); let currentHref = buttonIcon.getAttribute('xlink:href');
let baseHref = currentHref.split('#')[0]; let baseHref = currentHref.split('#')[0];
@ -233,21 +229,17 @@ function addOrRemoveSessionBoolean(name, add){
buttonIcon.setAttribute('xlink:href', baseHref + '#check'); buttonIcon.setAttribute('xlink:href', baseHref + '#check');
// Change the button text // Change the button text
nearestSpan = button.querySelector("span") let nearestSpan = button.querySelector("span")
let original_text = nearestSpan.innerText
nearestSpan.innerText = "Copied to clipboard" nearestSpan.innerText = "Copied to clipboard"
setTimeout(function() { setTimeout(function() {
// Change back to the copy icon // Change back to the copy icon
buttonIcon.setAttribute('xlink:href', currentHref); buttonIcon.setAttribute('xlink:href', currentHref);
if (button.classList.contains('usa-button__small-text')) { nearestSpan.innerText = original_text;
nearestSpan.innerText = "Copy email";
} else {
nearestSpan.innerText = "Copy";
}
}, 2000); }, 2000);
} }
}).catch(function(error) { }).catch(function(error) {
console.error('Clipboard copy failed', error); console.error('Clipboard copy failed', error);
}); });
@ -255,7 +247,7 @@ function addOrRemoveSessionBoolean(name, add){
} }
function handleClipboardButtons() { function handleClipboardButtons() {
clipboardButtons = document.querySelectorAll(".usa-button__clipboard") clipboardButtons = document.querySelectorAll(".copy-to-clipboard")
clipboardButtons.forEach((button) => { clipboardButtons.forEach((button) => {
// Handle copying the text to your clipboard, // Handle copying the text to your clipboard,
@ -278,20 +270,7 @@ function addOrRemoveSessionBoolean(name, add){
}); });
} }
function handleClipboardLinks() {
let emailButtons = document.querySelectorAll(".usa-button__clipboard-link");
if (emailButtons){
emailButtons.forEach((button) => {
button.addEventListener("click", ()=>{
copyInnerTextToClipboard(button);
})
});
}
}
handleClipboardButtons(); handleClipboardButtons();
handleClipboardLinks();
})(); })();
@ -605,3 +584,169 @@ function initializeWidgetOnList(list, parentId) {
} }
} }
})(); })();
/** An IIFE for copy summary button (appears in DomainRegistry models)
*/
(function (){
const copyButton = document.getElementById('id-copy-to-clipboard-summary');
if (copyButton) {
copyButton.addEventListener('click', function() {
/// Generate a rich HTML summary text and copy to clipboard
//------ Organization Type
const organizationTypeElement = document.getElementById('id_organization_type');
const organizationType = organizationTypeElement.options[organizationTypeElement.selectedIndex].text;
//------ Alternative Domains
const alternativeDomainsDiv = document.querySelector('.form-row.field-alternative_domains .readonly');
const alternativeDomainslinks = alternativeDomainsDiv.querySelectorAll('a');
const alternativeDomains = Array.from(alternativeDomainslinks).map(link => link.textContent);
//------ Existing Websites
const existingWebsitesDiv = document.querySelector('.form-row.field-current_websites .readonly');
const existingWebsiteslinks = existingWebsitesDiv.querySelectorAll('a');
const existingWebsites = Array.from(existingWebsiteslinks).map(link => link.textContent);
//------ Additional Contacts
// 1 - Create a hyperlinks map so we can display contact details and also link to the contact
const otherContactsDiv = document.querySelector('.form-row.field-other_contacts .readonly');
let otherContactLinks = [];
const nameToUrlMap = {};
if (otherContactsDiv) {
otherContactLinks = otherContactsDiv.querySelectorAll('a');
otherContactLinks.forEach(link => {
const name = link.textContent.trim();
const url = link.href;
nameToUrlMap[name] = url;
});
}
// 2 - Iterate through contact details and assemble html for summary
let otherContactsSummary = ""
const bulletList = document.createElement('ul');
// CASE 1 - Contacts are not in a table (this happens if there is only one or two other contacts)
const contacts = document.querySelectorAll('.field-other_contacts .dja-detail-list dd');
if (contacts) {
contacts.forEach(contact => {
// Check if the <dl> element is not empty
const name = contact.querySelector('a#contact_info_name')?.innerText;
const title = contact.querySelector('span#contact_info_title')?.innerText;
const email = contact.querySelector('span#contact_info_email')?.innerText;
const phone = contact.querySelector('span#contact_info_phone')?.innerText;
const url = nameToUrlMap[name] || '#';
// Format the contact information
const listItem = document.createElement('li');
listItem.innerHTML = `<a href="${url}">${name}</a>, ${title}, ${email}, ${phone}`;
bulletList.appendChild(listItem);
});
}
// CASE 2 - Contacts are in a table (this happens if there is more than 2 contacts)
const otherContactsTable = document.querySelector('.form-row.field-other_contacts table tbody');
if (otherContactsTable) {
const otherContactsRows = otherContactsTable.querySelectorAll('tr');
otherContactsRows.forEach(contactRow => {
// Extract the contact details
const name = contactRow.querySelector('th').textContent.trim();
const title = contactRow.querySelectorAll('td')[0].textContent.trim();
const email = contactRow.querySelectorAll('td')[1].textContent.trim();
const phone = contactRow.querySelectorAll('td')[2].textContent.trim();
const url = nameToUrlMap[name] || '#';
// Format the contact information
const listItem = document.createElement('li');
listItem.innerHTML = `<a href="${url}">${name}</a>, ${title}, ${email}, ${phone}`;
bulletList.appendChild(listItem);
});
}
otherContactsSummary += bulletList.outerHTML
//------ Requested Domains
const requestedDomainElement = document.getElementById('id_requested_domain');
const requestedDomain = requestedDomainElement.options[requestedDomainElement.selectedIndex].text;
//------ Submitter
// Function to extract text by ID and handle missing elements
function extractTextById(id, divElement) {
if (divElement) {
const element = divElement.querySelector(`#${id}`);
return element ? ", " + element.textContent.trim() : '';
}
return '';
}
// Extract the submitter name, title, email, and phone number
const submitterDiv = document.querySelector('.form-row.field-submitter');
const submitterNameElement = document.getElementById('id_submitter');
const submitterName = submitterNameElement.options[submitterNameElement.selectedIndex].text;
const submitterTitle = extractTextById('contact_info_title', submitterDiv);
const submitterEmail = extractTextById('contact_info_email', submitterDiv);
const submitterPhone = extractTextById('contact_info_phone', submitterDiv);
let submitterInfo = `${submitterName}${submitterTitle}${submitterEmail}${submitterPhone}`;
//------ Senior Official
const seniorOfficialDiv = document.querySelector('.form-row.field-senior_official');
const seniorOfficialElement = document.getElementById('id_senior_official');
const seniorOfficialName = seniorOfficialElement.options[seniorOfficialElement.selectedIndex].text;
const seniorOfficialTitle = extractTextById('contact_info_title', seniorOfficialDiv);
const seniorOfficialEmail = extractTextById('contact_info_email', seniorOfficialDiv);
const seniorOfficialPhone = extractTextById('contact_info_phone', seniorOfficialDiv);
let seniorOfficialInfo = `${seniorOfficialName}${seniorOfficialTitle}${seniorOfficialEmail}${seniorOfficialPhone}`;
const html_summary = `<strong>Recommendation:</strong></br>` +
`<strong>Organization Type:</strong> ${organizationType}</br>` +
`<strong>Requested Domain:</strong> ${requestedDomain}</br>` +
`<strong>Current Websites:</strong> ${existingWebsites.join(', ')}</br>` +
`<strong>Rationale:</strong></br>` +
`<strong>Alternative Domains:</strong> ${alternativeDomains.join(', ')}</br>` +
`<strong>Submitter:</strong> ${submitterInfo}</br>` +
`<strong>Senior Official:</strong> ${seniorOfficialInfo}</br>` +
`<strong>Other Employees:</strong> ${otherContactsSummary}</br>`;
//Replace </br> with \n, then strip out all remaining html tags (replace <...> with '')
const plain_summary = html_summary.replace(/<\/br>|<br>/g, '\n').replace(/<\/?[^>]+(>|$)/g, '');
// Create Blobs with the summary content
const html_blob = new Blob([html_summary], { type: 'text/html' });
const plain_blob = new Blob([plain_summary], { type: 'text/plain' });
// Create a ClipboardItem with the Blobs
const clipboardItem = new ClipboardItem({
'text/html': html_blob,
'text/plain': plain_blob
});
// Write the ClipboardItem to the clipboard
navigator.clipboard.write([clipboardItem]).then(() => {
// Change the icon to a checkmark on successful copy
let buttonIcon = copyButton.querySelector('use');
if (buttonIcon) {
let currentHref = buttonIcon.getAttribute('xlink:href');
let baseHref = currentHref.split('#')[0];
// Append the new icon reference
buttonIcon.setAttribute('xlink:href', baseHref + '#check');
// Change the button text
nearestSpan = copyButton.querySelector("span")
original_text = nearestSpan.innerText
nearestSpan.innerText = "Copied to clipboard"
setTimeout(function() {
// Change back to the copy icon
buttonIcon.setAttribute('xlink:href', currentHref);
nearestSpan.innerText = original_text
}, 2000);
}
console.log('Summary copied to clipboard successfully!');
}).catch(err => {
console.error('Failed to copy text: ', err);
});
});
}
})();

View file

@ -369,9 +369,6 @@ input.admin-confirm-button {
padding: 10px 8px; padding: 10px 8px;
line-height: normal; line-height: normal;
} }
.usa-icon {
top: 2px;
}
a.button:active, a.button:focus { a.button:active, a.button:focus {
text-decoration: none; text-decoration: none;
} }
@ -447,15 +444,12 @@ address.margin-top-neg-1__detail-list {
} }
} }
td button.usa-button__clipboard-link, address.dja-address-contact-list { address.dja-address-contact-list {
font-size: unset; font-size: unset;
} }
address.dja-address-contact-list { address.dja-address-contact-list {
color: var(--body-quiet-color); color: var(--body-quiet-color);
button.usa-button__clipboard-link {
font-size: unset;
}
} }
// Mimic the normal label size // Mimic the normal label size
@ -464,11 +458,18 @@ address.dja-address-contact-list {
font-size: 0.875rem; font-size: 0.875rem;
color: var(--body-quiet-color); color: var(--body-quiet-color);
} }
}
address button.usa-button__clipboard-link, td button.usa-button__clipboard-link { // Targets the unstyled buttons in the form
font-size: 0.875rem !important; .button--clipboard {
} color: var(--link-fg);
}
// Targets the DJA buttom with a nested icon
button .usa-icon,
.button .usa-icon,
.button--clipboard .usa-icon {
vertical-align: middle;
} }
.errors span.select2-selection { .errors span.select2-selection {
@ -663,7 +664,7 @@ address.dja-address-contact-list {
align-items: center; align-items: center;
.usa-button__icon { .usa-button--icon {
position: absolute; position: absolute;
right: auto; right: auto;
left: 4px; left: 4px;
@ -681,10 +682,6 @@ address.dja-address-contact-list {
} }
} }
button.usa-button__clipboard {
color: var(--link-fg);
}
.no-outline-on-click:focus { .no-outline-on-click:focus {
outline: none !important; outline: none !important;
} }

View file

@ -15,3 +15,4 @@
margin-right: units(0.5); margin-right: units(0.5);
} }
} }

View file

@ -241,7 +241,6 @@ TEMPLATES = [
"registrar.context_processors.is_demo_site", "registrar.context_processors.is_demo_site",
"registrar.context_processors.is_production", "registrar.context_processors.is_production",
"registrar.context_processors.org_user_status", "registrar.context_processors.org_user_status",
"registrar.context_processors.add_portfolio_to_context",
"registrar.context_processors.add_path_to_context", "registrar.context_processors.add_path_to_context",
"registrar.context_processors.add_has_profile_feature_flag_to_context", "registrar.context_processors.add_has_profile_feature_flag_to_context",
"registrar.context_processors.portfolio_permissions", "registrar.context_processors.portfolio_permissions",
@ -665,6 +664,7 @@ ALLOWED_HOSTS = [
"getgov-stable.app.cloud.gov", "getgov-stable.app.cloud.gov",
"getgov-staging.app.cloud.gov", "getgov-staging.app.cloud.gov",
"getgov-development.app.cloud.gov", "getgov-development.app.cloud.gov",
"getgov-ad.app.cloud.gov",
"getgov-ms.app.cloud.gov", "getgov-ms.app.cloud.gov",
"getgov-ag.app.cloud.gov", "getgov-ag.app.cloud.gov",
"getgov-litterbox.app.cloud.gov", "getgov-litterbox.app.cloud.gov",

View file

@ -26,7 +26,6 @@ from registrar.views.domain_request import Step
from registrar.views.domain_requests_json import get_domain_requests_json from registrar.views.domain_requests_json import get_domain_requests_json
from registrar.views.domains_json import get_domains_json from registrar.views.domains_json import get_domains_json
from registrar.views.utility import always_404 from registrar.views.utility import always_404
from registrar.views.portfolios import PortfolioDomainsView, PortfolioDomainRequestsView, PortfolioOrganizationView
from api.views import available, get_current_federal, get_current_full from api.views import available, get_current_federal, get_current_full
@ -61,19 +60,19 @@ for step, view in [
urlpatterns = [ urlpatterns = [
path("", views.index, name="home"), path("", views.index, name="home"),
path( path(
"portfolio/<int:portfolio_id>/domains/", "domains/",
PortfolioDomainsView.as_view(), views.PortfolioDomainsView.as_view(),
name="portfolio-domains", name="domains",
), ),
path( path(
"portfolio/<int:portfolio_id>/domain_requests/", "requests/",
PortfolioDomainRequestsView.as_view(), views.PortfolioDomainRequestsView.as_view(),
name="portfolio-domain-requests", name="domain-requests",
), ),
path( path(
"portfolio/<int:portfolio_id>/organization/", "organization/",
PortfolioOrganizationView.as_view(), views.PortfolioOrganizationView.as_view(),
name="portfolio-organization", name="organization",
), ),
path( path(
"admin/logout/", "admin/logout/",

View file

@ -50,10 +50,6 @@ def org_user_status(request):
} }
def add_portfolio_to_context(request):
return {"portfolio": getattr(request, "portfolio", None)}
def add_path_to_context(request): def add_path_to_context(request):
return {"path": getattr(request, "path", None)} return {"path": getattr(request, "path", None)}
@ -70,11 +66,15 @@ def portfolio_permissions(request):
"has_base_portfolio_permission": False, "has_base_portfolio_permission": False,
"has_domains_portfolio_permission": False, "has_domains_portfolio_permission": False,
"has_domain_requests_portfolio_permission": False, "has_domain_requests_portfolio_permission": False,
"portfolio": None,
"has_organization_feature_flag": False,
} }
return { return {
"has_base_portfolio_permission": request.user.has_base_portfolio_permission(), "has_base_portfolio_permission": request.user.has_base_portfolio_permission(),
"has_domains_portfolio_permission": request.user.has_domains_portfolio_permission(), "has_domains_portfolio_permission": request.user.has_domains_portfolio_permission(),
"has_domain_requests_portfolio_permission": request.user.has_domain_requests_portfolio_permission(), "has_domain_requests_portfolio_permission": request.user.has_domain_requests_portfolio_permission(),
"portfolio": request.user.portfolio,
"has_organization_feature_flag": flag_is_active(request, "organization_feature"),
} }
except AttributeError: except AttributeError:
# Handles cases where request.user might not exist # Handles cases where request.user might not exist
@ -82,4 +82,6 @@ def portfolio_permissions(request):
"has_base_portfolio_permission": False, "has_base_portfolio_permission": False,
"has_domains_portfolio_permission": False, "has_domains_portfolio_permission": False,
"has_domain_requests_portfolio_permission": False, "has_domain_requests_portfolio_permission": False,
"portfolio": None,
"has_organization_feature_flag": False,
} }

View file

@ -22,6 +22,11 @@ class UserFixture:
""" """
ADMINS = [ ADMINS = [
{
"username": "aad084c3-66cc-4632-80eb-41cdf5c5bcbf",
"first_name": "Aditi",
"last_name": "Green",
},
{ {
"username": "be17c826-e200-4999-9389-2ded48c43691", "username": "be17c826-e200-4999-9389-2ded48c43691",
"first_name": "Matthew", "first_name": "Matthew",
@ -120,6 +125,11 @@ class UserFixture:
] ]
STAFF = [ STAFF = [
{
"username": "ffec5987-aa84-411b-a05a-a7ee5cbcde54",
"first_name": "Aditi-Analyst",
"last_name": "Green-Analyst",
},
{ {
"username": "d6bf296b-fac5-47ff-9c12-f88ccc5c1b99", "username": "d6bf296b-fac5-47ff-9c12-f88ccc5c1b99",
"first_name": "Matthew-Analyst", "first_name": "Matthew-Analyst",

View file

@ -215,6 +215,11 @@ class DomainRequest(TimeStampedModel):
} }
return org_election_map return org_election_map
@classmethod
def get_org_label(cls, org_name: str):
# Translating the key that is given to the direct readable value
return cls(org_name).label if org_name else None
class OrganizationChoicesVerbose(models.TextChoices): class OrganizationChoicesVerbose(models.TextChoices):
""" """
Tertiary organization choices Tertiary organization choices

View file

@ -149,10 +149,10 @@ class CheckPortfolioMiddleware:
request.portfolio = portfolio request.portfolio = portfolio
if request.user.has_domains_portfolio_permission(): if request.user.has_domains_portfolio_permission():
portfolio_redirect = reverse("portfolio-domains", kwargs={"portfolio_id": portfolio.id}) portfolio_redirect = reverse("domains")
else: else:
# View organization is the lowest access # View organization is the lowest access
portfolio_redirect = reverse("portfolio-organization", kwargs={"portfolio_id": portfolio.id}) portfolio_redirect = reverse("organization")
return HttpResponseRedirect(portfolio_redirect) return HttpResponseRedirect(portfolio_redirect)

View file

@ -1,4 +1,5 @@
{% extends "admin/change_form.html" %} {% extends "admin/change_form.html" %}
{% load static i18n %} <!-- Add this line to load static template tag -->
{% comment %} Replace the Django ul markup with a div. We'll edit the child markup accordingly in change_form_object_tools {% endcomment %} {% comment %} Replace the Django ul markup with a div. We'll edit the child markup accordingly in change_form_object_tools {% endcomment %}
{% block object-tools %} {% block object-tools %}

View file

@ -1,4 +1,5 @@
{% load i18n admin_urls %} {% load i18n admin_urls %}
{% load i18n static %}
{% comment %} Replace li with p for more semantic HTML if we have a single child {% endcomment %} {% comment %} Replace li with p for more semantic HTML if we have a single child {% endcomment %}
{% block object-tools-items %} {% block object-tools-items %}
@ -13,8 +14,21 @@
</li> </li>
</ul> </ul>
{% else %} {% else %}
<p class="margin-0 padding-0"> <ul>
<a href="{% add_preserved_filters history_url %}" class="historylink">{% translate "History" %}</a> <li>
</p> <a href="{% add_preserved_filters history_url %}">{% translate "History" %}</a>
</li>
{% if opts.model_name == 'domainrequest' %}
<li>
<a id="id-copy-to-clipboard-summary" class="button--clipboard" type="button" href="#">
<svg class="usa-icon" >
<use xlink:href="{%static 'img/sprite.svg'%}#content_copy"></use>
</svg>
<span>{% translate "Copy request summary" %}</span>
</a>
</li>
{% endif %}
</ul>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -8,7 +8,7 @@ Template for an input field with a clipboard
<div class="admin-icon-group"> <div class="admin-icon-group">
{{ field }} {{ field }}
<button <button
class="usa-button usa-button--unstyled padding-left-1 usa-button__icon usa-button__clipboard" class="usa-button usa-button--unstyled padding-left-1 usa-button--icon button--clipboard copy-to-clipboard"
type="button" type="button"
> >
<div class="no-outline-on-click"> <div class="no-outline-on-click">
@ -25,7 +25,7 @@ Template for an input field with a clipboard
<div class="admin-icon-group admin-icon-group__clipboard-link"> <div class="admin-icon-group admin-icon-group__clipboard-link">
<input aria-hidden="true" class="display-none" value="{{ field.email }}" /> <input aria-hidden="true" class="display-none" value="{{ field.email }}" />
<button <button
class="usa-button usa-button--unstyled padding-right-1 usa-button__icon usa-button__clipboard text-no-underline" class="usa-button usa-button--unstyled padding-right-1 usa-button--icon button--clipboard copy-to-clipboard text-no-underline"
type="button" type="button"
> >
<svg <svg

View file

@ -2,25 +2,28 @@
<address class="{% if no_title_top_padding %}margin-top-neg-1__detail-list{% endif %} {% if user.has_contact_info %}margin-bottom-1{% endif %} dja-address-contact-list"> <address class="{% if no_title_top_padding %}margin-top-neg-1__detail-list{% endif %} {% if user.has_contact_info %}margin-bottom-1{% endif %} dja-address-contact-list">
{% if show_formatted_name %} {% if show_formatted_name %}
{% if user.get_formatted_name %} {% if user.get_formatted_name %}
<a href="{% url 'admin:registrar_contact_change' user.id %}">{{ user.get_formatted_name }}</a><br /> <a id="contact_info_name" href="{% url 'admin:registrar_contact_change' user.id %}">{{ user.get_formatted_name }}</a>
{% else %} {% else %}
None<br /> None
{% endif %} {% endif %}
{% endif %} {% endif %}
</br>
{% if user.has_contact_info %} {% if user.has_contact_info %}
{# Title #} {# Title #}
{% if user.title %} {% if user.title %}
{{ user.title }} <span id="contact_info_title">{{ user.title }}</span>
<br>
{% else %} {% else %}
None<br> None
{% endif %} {% endif %}
</br>
{# Email #} {# Email #}
{% if user.email %} {% if user.email %}
{{ user.email }} <span id="contact_info_email">{{ user.email }}</span>
{% include "admin/input_with_clipboard.html" with field=user invisible_input_field=True %} {% include "admin/input_with_clipboard.html" with field=user invisible_input_field=True %}
<br class="admin-icon-group__br"> <br class="admin-icon-group__br">
{% else %} {% else %}
@ -29,7 +32,7 @@
{# Phone #} {# Phone #}
{% if user.phone %} {% if user.phone %}
{{ user.phone }} <span id="contact_info_phone">{{ user.phone }}</span>
<br> <br>
{% else %} {% else %}
None<br> None<br>
@ -40,6 +43,6 @@
{% endif %} {% endif %}
{% if user_verification_type %} {% if user_verification_type %}
{{ user_verification_type }} <span id="contact_info_phone">{{ user_verification_type }}</span>
{% endif %} {% endif %}
</address> </address>

View file

@ -5,8 +5,8 @@ accept and become a domain manager.
</p> </p>
<p> <p>
An “invited” status indicates that the recipient has not logged in to the registrar since the invitation was sent. An “invited” status indicates that the recipient has not logged in to the registrar since the invitation was sent. Deleting an invitation with an "invited" status will prevent the user from signing in.
A “received” status indicates that the recipient has logged in. A “received” status indicates that the recipient has logged in. Deleting an invitation with a "received" status will not revoke that user's access from the domain. To remove a user who has already signed in, go to <a class="text-underline" href="{% url 'admin:registrar_userdomainrole_changelist' %}">User domain roles</a> and delete the role for the correct domain/manager combination.
</p> </p>
<p> <p>

View file

@ -219,7 +219,7 @@ This is using a custom implementation fieldset.html (see admin/fieldset.html)
<td class="padding-left-1 text-size-small"> <td class="padding-left-1 text-size-small">
<input aria-hidden="true" class="display-none" value="{{ contact.email }}" /> <input aria-hidden="true" class="display-none" value="{{ contact.email }}" />
<button <button
class="usa-button usa-button--unstyled padding-right-1 usa-button__icon usa-button__clipboard usa-button__small-text text-no-underline" class="usa-button usa-button--unstyled padding-right-1 usa-button--icon button--clipboard copy-to-clipboard usa-button__small-text text-no-underline"
type="button" type="button"
> >
<svg <svg

View file

@ -40,39 +40,50 @@
{% include "includes/domain_dates.html" %} {% include "includes/domain_dates.html" %}
{% if is_portfolio_user and not is_domain_manager %}
<div class="usa-alert usa-alert--info usa-alert--slim">
<div class="usa-alert__body">
<p class="usa-alert__text ">
To manage information for this domain, you must add yourself as a domain manager.
</p>
</div>
</div>
{% endif %}
{% url 'domain-dns-nameservers' pk=domain.id as url %} {% url 'domain-dns-nameservers' pk=domain.id as url %}
{% if domain.nameservers|length > 0 %} {% if domain.nameservers|length > 0 %}
{% include "includes/summary_item.html" with title='DNS name servers' domains='true' value=domain.nameservers list='true' edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='DNS name servers' domains='true' value=domain.nameservers list='true' edit_link=url editable=is_editable %}
{% else %} {% else %}
{% if domain.is_editable %} {% if is_editable %}
<h2 class="margin-top-3"> DNS name servers </h2> <h2 class="margin-top-3"> DNS name servers </h2>
<p> No DNS name servers have been added yet. Before your domain can be used well need information about your domain name servers.</p> <p> No DNS name servers have been added yet. Before your domain can be used well need information about your domain name servers.</p>
<a class="usa-button margin-bottom-1" href="{{url}}"> Add DNS name servers </a> <a class="usa-button margin-bottom-1" href="{{url}}"> Add DNS name servers </a>
{% else %} {% else %}
{% include "includes/summary_item.html" with title='DNS name servers' domains='true' value='' edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='DNS name servers' domains='true' value='' edit_link=url editable=is_editable %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% url 'domain-org-name-address' pk=domain.id as url %} {% url 'domain-org-name-address' pk=domain.id as url %}
{% include "includes/summary_item.html" with title='Organization name and mailing address' value=domain.domain_info address='true' edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='Organization name and mailing address' value=domain.domain_info address='true' edit_link=url editable=is_editable %}
{% url 'domain-senior-official' pk=domain.id as url %} {% url 'domain-senior-official' pk=domain.id as url %}
{% include "includes/summary_item.html" with title='Senior official' value=domain.domain_info.senior_official contact='true' edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='Senior official' value=domain.domain_info.senior_official contact='true' edit_link=url editable=is_editable %}
{# Conditionally display profile #} {# Conditionally display profile #}
{% if not has_profile_feature_flag %} {% if not has_profile_feature_flag %}
{% url 'domain-your-contact-information' pk=domain.id as url %} {% url 'domain-your-contact-information' pk=domain.id as url %}
{% include "includes/summary_item.html" with title='Your contact information' value=request.user contact='true' edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='Your contact information' value=request.user contact='true' edit_link=url editable=is_editable %}
{% endif %} {% endif %}
{% url 'domain-security-email' pk=domain.id as url %} {% url 'domain-security-email' pk=domain.id as url %}
{% if security_email is not None and security_email not in hidden_security_emails%} {% if security_email is not None and security_email not in hidden_security_emails%}
{% include "includes/summary_item.html" with title='Security email' value=security_email edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='Security email' value=security_email edit_link=url editable=is_editable %}
{% else %} {% else %}
{% include "includes/summary_item.html" with title='Security email' value='None provided' edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='Security email' value='None provided' edit_link=url editable=is_editable %}
{% endif %} {% endif %}
{% url 'domain-users' pk=domain.id as url %} {% url 'domain-users' pk=domain.id as url %}
{% include "includes/summary_item.html" with title='Domain managers' users='true' list=True value=domain.permissions.all edit_link=url editable=domain.is_editable %} {% include "includes/summary_item.html" with title='Domain managers' users='true' list=True value=domain.permissions.all edit_link=url editable=is_editable %}
</div> </div>
{% endblock %} {# domain_content #} {% endblock %} {# domain_content #}

View file

@ -12,7 +12,7 @@
</a> </a>
</li> </li>
{% if domain.is_editable %} {% if is_editable %}
<li class="usa-sidenav__item"> <li class="usa-sidenav__item">
{% url 'domain-dns' pk=domain.id as url %} {% url 'domain-dns' pk=domain.id as url %}
<a href="{{ url }}" {% if request.path|startswith:url %}class="usa-current"{% endif %}> <a href="{{ url }}" {% if request.path|startswith:url %}class="usa-current"{% endif %}>

View file

@ -1,11 +1,9 @@
{% load static %} {% load static %}
<section class="section--outlined domains{% if portfolio is not None %} margin-top-0{% endif %}" id="domains"> <section class="section--outlined domains{% if portfolio is not None %} margin-top-0{% endif %}" id="domains">
<div class="grid-row"> <div class="section--outlined__header margin-bottom-3 {% if portfolio is None %} section--outlined__header--no-portfolio justify-content-space-between{% else %} grid-row{% endif %}">
{% if portfolio is None %} {% if portfolio is None %}
<div class="mobile:grid-col-12 desktop:grid-col-6"> <h2 id="domains-header" class="display-inline-block">Domains</h2>
<h2 id="domains-header" class="flex-6">Domains</h2>
</div>
<span class="display-none" id="no-portfolio-js-flag"></span> <span class="display-none" id="no-portfolio-js-flag"></span>
{% else %} {% else %}
<!-- Embedding the portfolio value in a data attribute --> <!-- Embedding the portfolio value in a data attribute -->

View file

@ -1,4 +1,5 @@
{% load static %} {% load static %}
{% load custom_filters %}
<header class="usa-header usa-header--extended"> <header class="usa-header usa-header--extended">
<div class="usa-navbar"> <div class="usa-navbar">
@ -14,8 +15,8 @@
<ul class="usa-nav__primary usa-accordion"> <ul class="usa-nav__primary usa-accordion">
{% if has_domains_portfolio_permission %} {% if has_domains_portfolio_permission %}
<li class="usa-nav__primary-item"> <li class="usa-nav__primary-item">
{% url 'portfolio-domains' portfolio.id as url %} {% url 'domains' as url %}
<a href="{{ url }}" class="usa-nav-link{% if request.path == url %} usa-current{% endif %}"> <a href="{{ url }}" class="usa-nav-link{% if 'domain'|in_path:request.path %} usa-current{% endif %}">
Domains Domains
</a> </a>
</li> </li>
@ -27,8 +28,8 @@
</li> </li>
{% if has_domain_requests_portfolio_permission %} {% if has_domain_requests_portfolio_permission %}
<li class="usa-nav__primary-item"> <li class="usa-nav__primary-item">
{% url 'portfolio-domain-requests' portfolio.id as url %} {% url 'domain-requests' as url %}
<a href="{{ url }}" class="usa-nav-link{% if request.path == url %} usa-current{% endif %}"> <a href="{{ url }}" class="usa-nav-link{% if 'request'|in_path:request.path %} usa-current{% endif %}">
Domain requests Domain requests
</a> </a>
</li> </li>
@ -39,7 +40,7 @@
</a> </a>
</li> </li>
<li class="usa-nav__primary-item"> <li class="usa-nav__primary-item">
{% url 'portfolio-organization' portfolio.id as url %} {% url 'organization' as url %}
<!-- Move the padding from the a to the span so that the descenders do not get cut off --> <!-- Move the padding from the a to the span so that the descenders do not get cut off -->
<a href="{{ url }}" class="usa-nav-link padding-y-0"> <a href="{{ url }}" class="usa-nav-link padding-y-0">
<span class="ellipsis ellipsis--23 ellipsis--desktop-50 padding-y-1 desktop:padding-y-2"> <span class="ellipsis ellipsis--23 ellipsis--desktop-50 padding-y-1 desktop:padding-y-2">

View file

@ -4,7 +4,7 @@
<nav aria-label="Domain sections"> <nav aria-label="Domain sections">
<ul class="usa-sidenav"> <ul class="usa-sidenav">
<li class="usa-sidenav__item"> <li class="usa-sidenav__item">
{% url 'portfolio-organization' portfolio_id=portfolio.id as url %} {% url 'organization' as url %}
<a href="{{ url }}" <a href="{{ url }}"
{% if request.path == url %}class="usa-current"{% endif %} {% if request.path == url %}class="usa-current"{% endif %}
> >

View file

@ -145,3 +145,8 @@ def format_phone(value):
phone_number = PhoneNumber.from_string(value) phone_number = PhoneNumber.from_string(value)
return phone_number.as_national return phone_number.as_national
return value return value
@register.filter
def in_path(url, path):
return url in path

View file

@ -164,7 +164,7 @@ class TestDomainInvitationAdmin(TestCase):
) )
# Assert that the filters are added # Assert that the filters are added
self.assertContains(response, "invited", count=4) self.assertContains(response, "invited", count=5)
self.assertContains(response, "Invited", count=2) self.assertContains(response, "Invited", count=2)
self.assertContains(response, "retrieved", count=2) self.assertContains(response, "retrieved", count=2)
self.assertContains(response, "Retrieved", count=2) self.assertContains(response, "Retrieved", count=2)
@ -584,7 +584,7 @@ class TestDomainInformationAdmin(TestCase):
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields) self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
# Test for the copy link # Test for the copy link
self.assertContains(response, "usa-button__clipboard", count=4) self.assertContains(response, "button--clipboard", count=4)
# cleanup this test # cleanup this test
domain_info.delete() domain_info.delete()

View file

@ -444,7 +444,7 @@ class TestDomainAdminWithClient(TestCase):
self.assertContains(response, "(555) 555 5557") self.assertContains(response, "(555) 555 5557")
# Test for the copy link # Test for the copy link
self.assertContains(response, "usa-button__clipboard") self.assertContains(response, "button--clipboard")
# cleanup from this test # cleanup from this test
domain.delete() domain.delete()

View file

@ -1411,7 +1411,7 @@ class TestDomainRequestAdmin(MockEppLib):
self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields) self.test_helper.assert_response_contains_distinct_values(response, expected_other_employees_fields)
# Test for the copy link # Test for the copy link
self.assertContains(response, "usa-button__clipboard", count=4) self.assertContains(response, "button--clipboard", count=5)
# Test that Creator counts display properly # Test that Creator counts display properly
self.assertNotContains(response, "Approved domains") self.assertNotContains(response, "Approved domains")

View file

@ -6,6 +6,7 @@ from django.urls import reverse
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from api.tests.common import less_console_noise_decorator from api.tests.common import less_console_noise_decorator
from registrar.models.portfolio import Portfolio
from .common import MockEppLib, MockSESClient, create_user # type: ignore from .common import MockEppLib, MockSESClient, create_user # type: ignore
from django_webtest import WebTest # type: ignore from django_webtest import WebTest # type: ignore
import boto3_mocking # type: ignore import boto3_mocking # type: ignore
@ -138,6 +139,7 @@ class TestWithDomainPermissions(TestWithUser):
Host.objects.all().delete() Host.objects.all().delete()
Domain.objects.all().delete() Domain.objects.all().delete()
UserDomainRole.objects.all().delete() UserDomainRole.objects.all().delete()
Portfolio.objects.all().delete()
except ValueError: # pass if already deleted except ValueError: # pass if already deleted
pass pass
super().tearDown() super().tearDown()
@ -310,6 +312,33 @@ class TestDomainDetail(TestDomainOverview):
self.assertContains(detail_page, "noinformation.gov") self.assertContains(detail_page, "noinformation.gov")
self.assertContains(detail_page, "Domain missing domain information") self.assertContains(detail_page, "Domain missing domain information")
@less_console_noise_decorator
def test_domain_readonly_on_detail_page(self):
"""Test that a domain, which is part of a portfolio, but for which the user is not a domain manager,
properly displays read only"""
portfolio, _ = Portfolio.objects.get_or_create(organization_name="Test org", creator=self.user)
# need to create a different user than self.user because the user needs permission assignments
user = get_user_model().objects.create(
first_name="Test",
last_name="User",
email="bogus@example.gov",
phone="8003111234",
title="test title",
portfolio=portfolio,
portfolio_roles=[User.UserPortfolioRoleChoices.ORGANIZATION_ADMIN],
)
domain, _ = Domain.objects.get_or_create(name="bogusdomain.gov")
DomainInformation.objects.get_or_create(creator=user, domain=domain, portfolio=portfolio)
self.client.force_login(user)
detail_page = self.client.get(f"/domain/{domain.id}")
# Check that alert message displays properly
self.assertContains(
detail_page, "To manage information for this domain, you must add yourself as a domain manager."
)
# Check that user does not have option to Edit domain
self.assertNotContains(detail_page, "Edit")
class TestDomainManagers(TestDomainOverview): class TestDomainManagers(TestDomainOverview):
def tearDown(self): def tearDown(self):

View file

@ -181,7 +181,8 @@ class GetDomainsJsonTest(TestWithUser, WebTest):
# Check svg_icon # Check svg_icon
svg_icon_expected = ( svg_icon_expected = (
"visibility" "visibility"
if expected_domains[i].state if not user_domain_role_exists
or expected_domains[i].state
in [ in [
Domain.State.DELETED, Domain.State.DELETED,
Domain.State.ON_HOLD, Domain.State.ON_HOLD,

View file

@ -111,9 +111,7 @@ class TestPortfolio(WebTest):
with override_flag("organization_feature", active=True): with override_flag("organization_feature", active=True):
# This will redirect the user to the portfolio page. # This will redirect the user to the portfolio page.
# Follow implicity checks if our redirect is working. # Follow implicity checks if our redirect is working.
response = self.app.get( response = self.app.get(reverse("domains"), status=403)
reverse("portfolio-domains", kwargs={"portfolio_id": self.portfolio.pk}), status=403
)
# Assert the response is a 403 Forbidden # Assert the response is a 403 Forbidden
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
@ -127,9 +125,7 @@ class TestPortfolio(WebTest):
with override_flag("organization_feature", active=True): with override_flag("organization_feature", active=True):
# This will redirect the user to the portfolio page. # This will redirect the user to the portfolio page.
# Follow implicity checks if our redirect is working. # Follow implicity checks if our redirect is working.
response = self.app.get( response = self.app.get(reverse("domain-requests"), status=403)
reverse("portfolio-domain-requests", kwargs={"portfolio_id": self.portfolio.pk}), status=403
)
# Assert the response is a 403 Forbidden # Assert the response is a 403 Forbidden
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
@ -143,9 +139,7 @@ class TestPortfolio(WebTest):
with override_flag("organization_feature", active=True): with override_flag("organization_feature", active=True):
# This will redirect the user to the portfolio page. # This will redirect the user to the portfolio page.
# Follow implicity checks if our redirect is working. # Follow implicity checks if our redirect is working.
response = self.app.get( response = self.app.get(reverse("organization"), status=403)
reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk}), status=403
)
# Assert the response is a 403 Forbidden # Assert the response is a 403 Forbidden
self.assertEqual(response.status_code, 403) self.assertEqual(response.status_code, 403)
@ -169,12 +163,8 @@ class TestPortfolio(WebTest):
self.assertContains(portfolio_page, self.portfolio.organization_name) self.assertContains(portfolio_page, self.portfolio.organization_name)
self.assertNotContains(portfolio_page, "<h1>Organization</h1>") self.assertNotContains(portfolio_page, "<h1>Organization</h1>")
self.assertContains(portfolio_page, '<h1 id="domains-header">Domains</h1>') self.assertContains(portfolio_page, '<h1 id="domains-header">Domains</h1>')
self.assertContains( self.assertContains(portfolio_page, reverse("domains"))
portfolio_page, reverse("portfolio-domains", kwargs={"portfolio_id": self.portfolio.pk}) self.assertContains(portfolio_page, reverse("domain-requests"))
)
self.assertContains(
portfolio_page, reverse("portfolio-domain-requests", kwargs={"portfolio_id": self.portfolio.pk})
)
# reducing portfolio permissions to just VIEW_PORTFOLIO, which should remove domains # reducing portfolio permissions to just VIEW_PORTFOLIO, which should remove domains
# and domain requests from nav # and domain requests from nav
@ -187,12 +177,8 @@ class TestPortfolio(WebTest):
self.assertContains(portfolio_page, self.portfolio.organization_name) self.assertContains(portfolio_page, self.portfolio.organization_name)
self.assertContains(portfolio_page, "<h1>Organization</h1>") self.assertContains(portfolio_page, "<h1>Organization</h1>")
self.assertNotContains(portfolio_page, '<h1 id="domains-header">Domains</h1>') self.assertNotContains(portfolio_page, '<h1 id="domains-header">Domains</h1>')
self.assertNotContains( self.assertNotContains(portfolio_page, reverse("domains"))
portfolio_page, reverse("portfolio-domains", kwargs={"portfolio_id": self.portfolio.pk}) self.assertNotContains(portfolio_page, reverse("domain-requests"))
)
self.assertNotContains(
portfolio_page, reverse("portfolio-domain-requests", kwargs={"portfolio_id": self.portfolio.pk})
)
class TestPortfolioOrganization(TestPortfolio): class TestPortfolioOrganization(TestPortfolio):
@ -209,7 +195,7 @@ class TestPortfolioOrganization(TestPortfolio):
self.user.save() self.user.save()
self.user.refresh_from_db() self.user.refresh_from_db()
page = self.app.get(reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk})) page = self.app.get(reverse("organization"))
self.assertContains( self.assertContains(
page, "The name of your federal agency will be publicly listed as the domain registrant." page, "The name of your federal agency will be publicly listed as the domain registrant."
) )
@ -228,7 +214,7 @@ class TestPortfolioOrganization(TestPortfolio):
self.portfolio.organization_name = "Hotel California" self.portfolio.organization_name = "Hotel California"
self.portfolio.save() self.portfolio.save()
page = self.app.get(reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk})) page = self.app.get(reverse("organization"))
# Once in the sidenav, once in the main nav, once in the form # Once in the sidenav, once in the main nav, once in the form
self.assertContains(page, "Hotel California", count=3) self.assertContains(page, "Hotel California", count=3)
@ -246,9 +232,7 @@ class TestPortfolioOrganization(TestPortfolio):
self.portfolio.address_line1 = "1600 Penn Ave" self.portfolio.address_line1 = "1600 Penn Ave"
self.portfolio.save() self.portfolio.save()
portfolio_org_name_page = self.app.get( portfolio_org_name_page = self.app.get(reverse("organization"))
reverse("portfolio-organization", kwargs={"portfolio_id": self.portfolio.pk})
)
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME] session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
portfolio_org_name_page.form["address_line1"] = "6 Downing st" portfolio_org_name_page.form["address_line1"] = "6 Downing st"

View file

@ -374,8 +374,9 @@ class DomainExport(BaseExport):
if first_ready_on is None: if first_ready_on is None:
first_ready_on = "(blank)" first_ready_on = "(blank)"
domain_org_type = model.get("generic_org_type") # organization_type has generic_org_type AND is_election
human_readable_domain_org_type = DomainRequest.OrganizationChoices.get_org_label(domain_org_type) domain_org_type = model.get("organization_type")
human_readable_domain_org_type = DomainRequest.OrgChoicesElectionOffice.get_org_label(domain_org_type)
domain_federal_type = model.get("federal_type") domain_federal_type = model.get("federal_type")
human_readable_domain_federal_type = BranchChoices.get_branch_label(domain_federal_type) human_readable_domain_federal_type = BranchChoices.get_branch_label(domain_federal_type)
domain_type = human_readable_domain_org_type domain_type = human_readable_domain_org_type

View file

@ -17,3 +17,4 @@ from .domain import (
from .user_profile import UserProfileView, FinishProfileSetupView from .user_profile import UserProfileView, FinishProfileSetupView
from .health import * from .health import *
from .index import * from .index import *
from .portfolios import *

View file

@ -170,6 +170,17 @@ class DomainView(DomainBaseView):
context["security_email"] = security_email context["security_email"] = security_email
return context return context
def can_access_domain_via_portfolio(self, pk):
"""Most views should not allow permission to portfolio users.
If particular views allow permissions, they will need to override
this function."""
if self.request.user.has_domains_portfolio_permission():
if Domain.objects.filter(id=pk).exists():
domain = Domain.objects.get(id=pk)
if domain.domain_info.portfolio == self.request.user.portfolio:
return True
return False
def in_editable_state(self, pk): def in_editable_state(self, pk):
"""Override in_editable_state from DomainPermission """Override in_editable_state from DomainPermission
Allow detail page to be viewable""" Allow detail page to be viewable"""

View file

@ -124,7 +124,7 @@ def serialize_domain(domain, user):
# Check if there is a UserDomainRole for this domain and user # Check if there is a UserDomainRole for this domain and user
user_domain_role_exists = UserDomainRole.objects.filter(domain_id=domain.id, user=user).exists() user_domain_role_exists = UserDomainRole.objects.filter(domain_id=domain.id, user=user).exists()
view_only = not user_domain_role_exists or domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD]
return { return {
"id": domain.id, "id": domain.id,
"name": domain.name, "name": domain.name,
@ -133,11 +133,7 @@ def serialize_domain(domain, user):
"state_display": domain.state_display(), "state_display": domain.state_display(),
"get_state_help_text": domain.get_state_help_text(), "get_state_help_text": domain.get_state_help_text(),
"action_url": reverse("domain", kwargs={"pk": domain.id}), "action_url": reverse("domain", kwargs={"pk": domain.id}),
"action_label": ( "action_label": ("View" if view_only else "Manage"),
"View" "svg_icon": ("visibility" if view_only else "settings"),
if not user_domain_role_exists or domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD]
else "Manage"
),
"svg_icon": ("visibility" if domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD] else "settings"),
"suborganization": suborganization_name, "suborganization": suborganization_name,
} }

View file

@ -1,5 +1,6 @@
import logging import logging
from django.shortcuts import get_object_or_404, render from django.http import Http404
from django.shortcuts import render
from django.urls import reverse from django.urls import reverse
from django.contrib import messages from django.contrib import messages
from registrar.forms.portfolio import PortfolioOrgAddressForm from registrar.forms.portfolio import PortfolioOrgAddressForm
@ -9,7 +10,6 @@ from registrar.views.utility.permission_views import (
PortfolioDomainsPermissionView, PortfolioDomainsPermissionView,
PortfolioBasePermissionView, PortfolioBasePermissionView,
) )
from waffle.decorators import flag_is_active
from django.views.generic import View from django.views.generic import View
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
@ -20,35 +20,21 @@ logger = logging.getLogger(__name__)
class PortfolioDomainsView(PortfolioDomainsPermissionView, View): class PortfolioDomainsView(PortfolioDomainsPermissionView, View):
template_name = "portfolio_domains.html" template_name = "portfolio_domains.html"
def get(self, request):
def get(self, request, portfolio_id):
context = {} context = {}
if self.request.user.is_authenticated: if self.request.user.is_authenticated:
context["has_profile_feature_flag"] = flag_is_active(request, "profile_feature")
context["has_organization_feature_flag"] = flag_is_active(request, "organization_feature")
portfolio = get_object_or_404(Portfolio, id=portfolio_id)
context["portfolio"] = portfolio
context["user_domain_count"] = self.request.user.get_user_domain_ids().count() context["user_domain_count"] = self.request.user.get_user_domain_ids().count()
return render(request, "portfolio_domains.html")
return render(request, "portfolio_domains.html", context)
class PortfolioDomainRequestsView(PortfolioDomainRequestsPermissionView, View): class PortfolioDomainRequestsView(PortfolioDomainRequestsPermissionView, View):
template_name = "portfolio_requests.html" template_name = "portfolio_requests.html"
def get(self, request, portfolio_id): def get(self, request):
context = {}
if self.request.user.is_authenticated: if self.request.user.is_authenticated:
context["has_profile_feature_flag"] = flag_is_active(request, "profile_feature")
context["has_organization_feature_flag"] = flag_is_active(request, "organization_feature")
portfolio = get_object_or_404(Portfolio, id=portfolio_id)
context["portfolio"] = portfolio
request.session["new_request"] = True request.session["new_request"] = True
return render(request, "portfolio_requests.html")
return render(request, "portfolio_requests.html", context)
class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin): class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
@ -64,14 +50,14 @@ class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
"""Add additional context data to the template.""" """Add additional context data to the template."""
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
# no need to add portfolio to request context here
context["has_profile_feature_flag"] = flag_is_active(self.request, "profile_feature")
context["has_organization_feature_flag"] = flag_is_active(self.request, "organization_feature")
return context return context
def get_object(self, queryset=None): def get_object(self, queryset=None):
"""Get the portfolio object based on the URL parameter.""" """Get the portfolio object based on the request user."""
return get_object_or_404(Portfolio, id=self.kwargs.get("portfolio_id")) portfolio = self.request.user.portfolio
if portfolio is None:
raise Http404("No organization found for this user")
return portfolio
def get_form_kwargs(self): def get_form_kwargs(self):
"""Include the instance in the form kwargs.""" """Include the instance in the form kwargs."""
@ -108,4 +94,4 @@ class PortfolioOrganizationView(PortfolioBasePermissionView, FormMixin):
def get_success_url(self): def get_success_url(self):
"""Redirect to the overview page for the portfolio.""" """Redirect to the overview page for the portfolio."""
return reverse("portfolio-organization", kwargs={"portfolio_id": self.object.pk}) return reverse("organization")

View file

@ -184,11 +184,17 @@ class DomainPermission(PermissionsLoginMixin):
# user needs to have a role on the domain # user needs to have a role on the domain
if not UserDomainRole.objects.filter(user=self.request.user, domain__id=pk).exists(): if not UserDomainRole.objects.filter(user=self.request.user, domain__id=pk).exists():
return False return self.can_access_domain_via_portfolio(pk)
# if we need to check more about the nature of role, do it here. # if we need to check more about the nature of role, do it here.
return True return True
def can_access_domain_via_portfolio(self, pk):
"""Most views should not allow permission to portfolio users.
If particular views allow access to the domain pages, they will need to override
this function."""
return False
def in_editable_state(self, pk): def in_editable_state(self, pk):
"""Is the domain in an editable state""" """Is the domain in an editable state"""

View file

@ -43,6 +43,9 @@ class DomainPermissionView(DomainPermission, DetailView, abc.ABC):
context["is_analyst_or_superuser"] = user.has_perm("registrar.analyst_access_permission") or user.has_perm( context["is_analyst_or_superuser"] = user.has_perm("registrar.analyst_access_permission") or user.has_perm(
"registrar.full_access_permission" "registrar.full_access_permission"
) )
context["is_domain_manager"] = UserDomainRole.objects.filter(user=user, domain=self.object).exists()
context["is_portfolio_user"] = self.can_access_domain_via_portfolio(self.object.pk)
context["is_editable"] = self.is_editable()
# Stored in a variable for the linter # Stored in a variable for the linter
action = "analyst_action" action = "analyst_action"
action_location = "analyst_action_location" action_location = "analyst_action_location"
@ -54,6 +57,22 @@ class DomainPermissionView(DomainPermission, DetailView, abc.ABC):
return context return context
def is_editable(self):
"""Returns whether domain is editable in the context of the view"""
logger.info("checking if is_editable")
domain_editable = self.object.is_editable()
if not domain_editable:
return False
# if user is domain manager or analyst or admin, return True
if (
self.can_access_other_user_domains(self.object.id)
or UserDomainRole.objects.filter(user=self.request.user, domain=self.object).exists()
):
return True
return False
# Abstract property enforces NotImplementedError on an attribute. # Abstract property enforces NotImplementedError on an attribute.
@property @property
@abc.abstractmethod @abc.abstractmethod