Skip to content

Commit

Permalink
Merge pull request #2515 from cisagov/rjm/2505-org-view-only
Browse files Browse the repository at this point in the history
Issue #2505: Read-only view for portfolio org page - [RJM]
  • Loading branch information
rachidatecs authored Aug 2, 2024
2 parents 33234ac + 85f51ef commit f12c71a
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 58 deletions.
10 changes: 10 additions & 0 deletions src/registrar/assets/sass/_theme/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,13 @@ legend.float-left-tablet + button.float-right-tablet {
color: var(--close-button-hover-bg);
}
}

.read-only-label {
font-size: size('body', 'sm');
color: color('primary');
margin-bottom: units(0.5);
}

.read-only-value {
margin-top: units(0);
}
5 changes: 4 additions & 1 deletion src/registrar/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ def _has_portfolio_permission(self, portfolio_permission):

return portfolio_permission in portfolio_permissions

# the methods below are checks for individual portfolio permissions. they are defined here
# the methods below are checks for individual portfolio permissions. They are defined here
# to make them easier to call elsewhere throughout the application
def has_base_portfolio_permission(self):
return self._has_portfolio_permission(UserPortfolioPermissionChoices.VIEW_PORTFOLIO)

def has_edit_org_portfolio_permission(self):
return self._has_portfolio_permission(UserPortfolioPermissionChoices.EDIT_PORTFOLIO)

def has_domains_portfolio_permission(self):
return self._has_portfolio_permission(
UserPortfolioPermissionChoices.VIEW_ALL_DOMAINS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<section class="section--outlined domain-requests" id="domain-requests">
<div class="grid-row">
{% if portfolio is None %}
{% if not has_domain_requests_portfolio_permission %}
<div class="mobile:grid-col-12 desktop:grid-col-6">
<h2 id="domain-requests-header" class="flex-6">Domain requests</h2>
</div>
Expand Down
14 changes: 7 additions & 7 deletions src/registrar/templates/includes/domains_table.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% load static %}

<section class="section--outlined domains{% if portfolio is not None %} margin-top-0{% endif %}" id="domains">
<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 %}
<section class="section--outlined domains{% if not has_domains_portfolio_permission %} margin-top-0{% endif %}" id="domains">
<div class="section--outlined__header margin-bottom-3 {% if not has_domains_portfolio_permission %} section--outlined__header--no-portfolio justify-content-space-between{% else %} grid-row{% endif %}">
{% if not has_domains_portfolio_permission %}
<h2 id="domains-header" class="display-inline-block">Domains</h2>
<span class="display-none" id="no-portfolio-js-flag"></span>
{% else %}
<!-- Embedding the portfolio value in a data attribute -->
<span id="portfolio-js-value" data-portfolio="{{ portfolio.id }}"></span>
{% endif %}
<div class="section--outlined__search {% if portfolio %} mobile:grid-col-12 desktop:grid-col-6{% endif %}">
<div class="section--outlined__search {% if has_domains_portfolio_permission %} mobile:grid-col-12 desktop:grid-col-6{% endif %}">
<section aria-label="Domains search component" class="margin-top-2">
<form class="usa-search usa-search--small" method="POST" role="search">
{% csrf_token %}
Expand Down Expand Up @@ -37,7 +37,7 @@ <h2 id="domains-header" class="display-inline-block">Domains</h2>
</form>
</section>
</div>
<div class="section--outlined__utility-button mobile-lg:padding-right-105 {% if portfolio %} mobile:grid-col-12 desktop:grid-col-6 desktop:padding-left-3{% endif %}">
<div class="section--outlined__utility-button mobile-lg:padding-right-105 {% if has_domains_portfolio_permission %} mobile:grid-col-12 desktop:grid-col-6 desktop:padding-left-3{% endif %}">
<section aria-label="Domains report component" class="mobile-lg:margin-top-205">
<a href="{% url 'export_data_type_user' %}" class="usa-button usa-button--unstyled" role="button">
<svg class="usa-icon usa-icon--big margin-right-neg-4px" aria-hidden="true" focusable="false" role="img" width="24" height="24">
Expand All @@ -47,7 +47,7 @@ <h2 id="domains-header" class="display-inline-block">Domains</h2>
</section>
</div>
</div>
{% if portfolio %}
{% if has_domains_portfolio_permission %}
<div class="display-flex flex-align-center">
<span class="margin-right-2 margin-top-neg-1 usa-prose text-base-darker">Filter by</span>
<div class="usa-accordion usa-accordion--select margin-right-2">
Expand Down Expand Up @@ -150,7 +150,7 @@ <h2>Status</h2>
<th data-sortable="name" scope="col" role="columnheader">Domain name</th>
<th data-sortable="expiration_date" scope="col" role="columnheader">Expires</th>
<th data-sortable="state_display" scope="col" role="columnheader">Status</th>
{% if portfolio %}
{% if has_domains_portfolio_permission %}
<th data-sortable="suborganization" scope="col" role="columnheader">Suborganization</th>
{% endif %}
<th
Expand Down
8 changes: 4 additions & 4 deletions src/registrar/templates/includes/finish_profile_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h2>What contact information should we use to reach you?</h2>

<input type="hidden" name="redirect" value="{{ form.initial.redirect }}">

{% with show_edit_button=True show_readonly=True group_classes="usa-form-editable usa-form-editable--no-border padding-top-2" %}
{% with toggleable_input=True toggleable_label=True group_classes="usa-form-editable usa-form-editable--no-border padding-top-2" %}
{% input_with_errors form.full_name %}
{% endwith %}

Expand All @@ -53,12 +53,12 @@ <h2>What contact information should we use to reach you?</h2>
{% endwith %}
</div>

{% with show_edit_button=True show_readonly=True group_classes="usa-form-editable padding-top-2" %}
{% with toggleable_input=True toggleable_label=True group_classes="usa-form-editable padding-top-2" %}
{% input_with_errors form.title %}
{% endwith %}

{% public_site_url "help/account-management/#get-help-with-login.gov" as login_help_url %}
{% with show_readonly=True add_class="display-none" group_classes="usa-form-editable usa-form-editable padding-top-2 bold-usa-label" %}
{% with toggleable_input=True add_class="display-none" group_classes="usa-form-editable usa-form-editable padding-top-2 bold-usa-label" %}
{% with link_href=login_help_url %}
{% with sublabel_text="We recommend using your work email for your .gov account. If the wrong email is displayed below, you’ll need to update your Login.gov account and log back in. Get help with your Login.gov account." %}
{% with link_text="Get help with your Login.gov account" target_blank=True do_not_show_max_chars=True %}
Expand All @@ -68,7 +68,7 @@ <h2>What contact information should we use to reach you?</h2>
{% endwith %}
{% endwith %}

{% with show_edit_button=True show_readonly=True group_classes="usa-form-editable padding-top-2" %}
{% with toggleable_input=True toggleable_label=True group_classes="usa-form-editable padding-top-2" %}
{% with add_class="usa-input--medium" %}
{% input_with_errors form.phone %}
{% endwith %}
Expand Down
7 changes: 7 additions & 0 deletions src/registrar/templates/includes/input_read_only.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% comment %}
Template include for read-only form fields
{% endcomment %}


<h4 class="read-only-label">{{ field.label }}</h4>
<p class="read-only-value">{{ field.value }}</p>
8 changes: 4 additions & 4 deletions src/registrar/templates/includes/input_with_errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
{% endif %}

{% if not field.widget_type == "checkbox" %}
{% if show_edit_button %}
{% include "includes/label_with_edit_button.html" with bold_label=True %}
{% if toggleable_label %}
{% include "includes/toggleable_label.html" with bold_label=True %}
{% else %}
{% include "django/forms/label.html" %}
{% endif %}
Expand Down Expand Up @@ -63,8 +63,8 @@
<div class="display-flex flex-align-center">
{% endif %}

{% if show_readonly %}
{% include "includes/readonly_input.html" %}
{% if toggleable_input %}
{% include "includes/toggleable_input.html" %}
{% endif %}

{# this is the input field, itself #}
Expand Down
75 changes: 43 additions & 32 deletions src/registrar/templates/portfolio_organization.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,53 @@ <h1>Organization</h1>

<p>The name of your federal agency will be publicly listed as the domain registrant.</p>

<p>
The federal agency for your organization can’t be updated here.
To suggest an update, email <a href="mailto:[email protected]" class="usa-link">[email protected]</a>.
</p>

{% include "includes/form_errors.html" with form=form %}

{% include "includes/required_fields.html" %}

<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}

{% if has_edit_org_portfolio_permission %}
<p>
<strong class="text-primary display-block margin-bottom-1">Federal agency</strong>
{{ portfolio }}
The federal agency for your organization can’t be updated here.
To suggest an update, email <a href="mailto:[email protected]" class="usa-link">[email protected]</a>.
</p>

{% input_with_errors form.address_line1 %}

{% input_with_errors form.address_line2 %}

{% input_with_errors form.city %}

{% input_with_errors form.state_territory %}

{% with add_class="usa-input--small" %}
{% input_with_errors form.zipcode %}
{% endwith %}
{% include "includes/form_errors.html" with form=form %}
{% include "includes/required_fields.html" %}
<form class="usa-form usa-form--large" method="post" novalidate>
{% csrf_token %}
<h4 class="read-only-label">Federal agency</h4>
<p class="read-only-value">
{{ portfolio.federal_agency }}
</p>
{% input_with_errors form.address_line1 %}
{% input_with_errors form.address_line2 %}
{% input_with_errors form.city %}
{% input_with_errors form.state_territory %}
{% with add_class="usa-input--small" %}
{% input_with_errors form.zipcode %}
{% endwith %}
<button type="submit" class="usa-button">
Save
</button>
</form>
{% else %}
<h4 class="read-only-label">Federal agency</h4>
<p class="read-only-value">
{{ portfolio.federal_agency }}
</p>
{% if form.address_line1.value is not None %}
{% include "includes/input_read_only.html" with field=form.address_line1 %}
{% endif %}
{% if form.address_line2.value is not None %}
{% include "includes/input_read_only.html" with field=form.address_line2 %}
{% endif %}
{% if form.city.value is not None %}
{% include "includes/input_read_only.html" with field=form.city %}
{% endif %}
{% if form.state_territory.value is not None %}
{% include "includes/input_read_only.html" with field=form.state_territory %}
{% endif %}
{% if form.zipcode.value is not None %}
{% include "includes/input_read_only.html" with field=form.zipcode %}
{% endif %}
{% endif %}

<button
type="submit"
class="usa-button"
>
Save
</button>
</form>
</div>
</div>
{% endblock %}
4 changes: 2 additions & 2 deletions src/registrar/templatetags/field_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def input_with_errors(context, field=None): # noqa: C901
add_group_class: append to input element's surrounding tag's `class` attribute
attr_* - adds or replaces any single html attribute for the input
add_error_attr_* - like `attr_*` but only if field.errors is not empty
show_edit_button: shows a simple edit button, and adds display-none to the input field.
toggleable_input: shows a simple edit button, and adds display-none to the input field.
Example usage:
```
Expand Down Expand Up @@ -92,7 +92,7 @@ def input_with_errors(context, field=None): # noqa: C901
elif key == "add_group_class":
group_classes.append(value)

elif key == "show_edit_button":
elif key == "toggleable_input":
# Hide the primary input field.
# Used such that we can toggle it with JS
if "display-none" not in classes:
Expand Down
3 changes: 2 additions & 1 deletion src/registrar/tests/test_views_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from api.tests.common import less_console_noise_decorator
from registrar.models.portfolio import Portfolio
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
from .common import MockEppLib, MockSESClient, create_user # type: ignore
from django_webtest import WebTest # type: ignore
import boto3_mocking # type: ignore
Expand Down Expand Up @@ -326,7 +327,7 @@ def test_domain_readonly_on_detail_page(self):
phone="8003111234",
title="test title",
portfolio=portfolio,
portfolio_roles=[User.UserPortfolioRoleChoices.ORGANIZATION_ADMIN],
portfolio_roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN],
)
domain, _ = Domain.objects.get_or_create(name="bogusdomain.gov")
DomainInformation.objects.get_or_create(creator=user, domain=domain, portfolio=portfolio)
Expand Down
Loading

0 comments on commit f12c71a

Please sign in to comment.