mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-04 18:23:29 +02:00
Cleanup
This commit is contained in:
parent
c085512c70
commit
364e38792c
6 changed files with 37 additions and 73 deletions
|
@ -85,7 +85,6 @@ def login_callback(request):
|
||||||
"""Analyze the token returned by the authentication provider (OP)."""
|
"""Analyze the token returned by the authentication provider (OP)."""
|
||||||
global CLIENT
|
global CLIENT
|
||||||
try:
|
try:
|
||||||
request.session["is_new_user"] = False
|
|
||||||
# If the CLIENT is none, attempt to reinitialize before handling the request
|
# If the CLIENT is none, attempt to reinitialize before handling the request
|
||||||
if _client_is_none():
|
if _client_is_none():
|
||||||
logger.debug("OIDC client is None, attempting to initialize")
|
logger.debug("OIDC client is None, attempting to initialize")
|
||||||
|
@ -135,7 +134,7 @@ def login_callback(request):
|
||||||
|
|
||||||
def _set_authenticated_user_metadata(user, is_new_user):
|
def _set_authenticated_user_metadata(user, is_new_user):
|
||||||
"""Does checks on the recieved authenticated user from login_callback,
|
"""Does checks on the recieved authenticated user from login_callback,
|
||||||
and updates fields accordingly. U"""
|
and updates fields accordingly."""
|
||||||
should_update_user = False
|
should_update_user = False
|
||||||
# Fixture users kind of exist in a superposition of verification types,
|
# Fixture users kind of exist in a superposition of verification types,
|
||||||
# because while the system "verified" them, if they login,
|
# because while the system "verified" them, if they login,
|
||||||
|
|
|
@ -879,10 +879,10 @@ function hideDeletedForms() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputField) {
|
if (inputField) {
|
||||||
// Remove the "full_name" field
|
// Hide the "full_name" field
|
||||||
inputFieldParentDiv = inputField.closest("div");
|
inputFieldParentDiv = inputField.closest("div");
|
||||||
if (inputFieldParentDiv) {
|
if (inputFieldParentDiv) {
|
||||||
inputFieldParentDiv.remove();
|
inputFieldParentDiv.classList.add("display-none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -926,29 +926,24 @@ function hideDeletedForms() {
|
||||||
if (fieldIdParts && fieldIdParts.length > 0){
|
if (fieldIdParts && fieldIdParts.length > 0){
|
||||||
let fieldName = fieldIdParts[0]
|
let fieldName = fieldIdParts[0]
|
||||||
|
|
||||||
|
// Check if an error message exists for the given field
|
||||||
let errorMessage = document.querySelector(`#id_${fieldName}__error-message`);
|
let errorMessage = document.querySelector(`#id_${fieldName}__error-message`);
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
let nameFields = ["first_name", "middle_name", "last_name"]
|
|
||||||
|
// Show the input field of the field that errored out
|
||||||
button.click()
|
button.click()
|
||||||
|
|
||||||
// If either the full_name field errors out,
|
// If either the full_name field errors out,
|
||||||
// or if any of its associated fields do - show all name related fields.
|
// or if any of its associated fields do - show all name related fields.
|
||||||
// Otherwise, just show the problematic field.
|
let nameFields = ["first_name", "middle_name", "last_name"]
|
||||||
if (nameFields.includes(fieldName) && !fullNameButtonClicked){
|
if (nameFields.includes(fieldName) && !fullNameButtonClicked){
|
||||||
|
// Click the full name button if any of its related fields error out
|
||||||
fullNameButton = document.querySelector("#full_name__edit-button")
|
fullNameButton = document.querySelector("#full_name__edit-button")
|
||||||
if (fullNameButton) {
|
if (fullNameButton) {
|
||||||
fullNameButton.click()
|
fullNameButton.click()
|
||||||
fullNameButtonClicked = true
|
fullNameButtonClicked = true
|
||||||
}
|
}
|
||||||
|
|
||||||
let readonlyId = getReadonlyFieldId("full_name");
|
|
||||||
let readonlyField = document.querySelector(readonlyId);
|
|
||||||
if (readonlyField) {
|
|
||||||
readonlyField.classList.toggle("overlapped-full-name-field");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -960,4 +955,4 @@ function hideDeletedForms() {
|
||||||
|
|
||||||
// Show the input fields if an error exists
|
// Show the input fields if an error exists
|
||||||
showInputOnErrorFields();
|
showInputOnErrorFields();
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -42,12 +42,12 @@
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.usa-form-readonly--no-border {
|
||||||
|
border-top: None;
|
||||||
|
margin-top: 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
.usa-form-readonly:first-of-type {
|
|
||||||
border-top: None;
|
|
||||||
margin-top: 0px !important;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
.usa-form-readonly > .usa-form-group:first-of-type {
|
.usa-form-readonly > .usa-form-group:first-of-type {
|
||||||
margin-top: unset;
|
margin-top: unset;
|
||||||
|
|
|
@ -63,12 +63,12 @@
|
||||||
Your contact information
|
Your contact information
|
||||||
</legend>
|
</legend>
|
||||||
|
|
||||||
{% with show_edit_button=True show_readonly=True group_classes="usa-form-readonly padding-top-2" %}
|
{% with show_edit_button=True show_readonly=True group_classes="usa-form-readonly usa-form-readonly--no-border padding-top-2" %}
|
||||||
{% input_with_errors form.full_name %}
|
{% input_with_errors form.full_name %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
<div id="profile-name-fieldset" class="display-none" role="group">
|
<div id="profile-name-fieldset" class="display-none" role="group">
|
||||||
{% with group_classes="usa-form-readonly padding-top-2" %}
|
{% with group_classes="usa-form-readonly usa-form-readonly--no-border padding-top-2" %}
|
||||||
{% input_with_errors form.first_name %}
|
{% input_with_errors form.first_name %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
|
|
|
@ -326,41 +326,6 @@ class UserDeleteDomainRolePermission(PermissionsLoginMixin):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ContactPermission(PermissionsLoginMixin):
|
|
||||||
"""Permission mixin for UserDomainRole if user
|
|
||||||
has access, otherwise 403"""
|
|
||||||
|
|
||||||
def has_permission(self):
|
|
||||||
"""Check if this user has access to this domain request.
|
|
||||||
|
|
||||||
The user is in self.request.user and the domain needs to be looked
|
|
||||||
up from the domain's primary key in self.kwargs["pk"]
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Check if the user is authenticated
|
|
||||||
if not self.request.user.is_authenticated:
|
|
||||||
return False
|
|
||||||
|
|
||||||
given_contact_pk = self.kwargs["pk"]
|
|
||||||
|
|
||||||
# Grab the user in the DB to do a full object comparision, not just on ids
|
|
||||||
current_user = self.request.user
|
|
||||||
|
|
||||||
# Compare the PK that was passed in to the user currently logged in
|
|
||||||
if current_user.contact.pk != given_contact_pk:
|
|
||||||
# Don't allow users to modify other users profiles
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Check if the object at the id we're searching on actually exists
|
|
||||||
requested_user_exists = User.objects.filter(pk=current_user.pk).exists()
|
|
||||||
requested_contact_exists = Contact.objects.filter(user=current_user.pk, pk=given_contact_pk).exists()
|
|
||||||
|
|
||||||
if not requested_user_exists or not requested_contact_exists:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class DomainRequestPermissionWithdraw(PermissionsLoginMixin):
|
class DomainRequestPermissionWithdraw(PermissionsLoginMixin):
|
||||||
"""Permission mixin that redirects to withdraw action on domain request
|
"""Permission mixin that redirects to withdraw action on domain request
|
||||||
if user has access, otherwise 403"""
|
if user has access, otherwise 403"""
|
||||||
|
@ -430,7 +395,27 @@ class UserProfilePermission(PermissionsLoginMixin):
|
||||||
|
|
||||||
If the user is authenticated, they have access
|
If the user is authenticated, they have access
|
||||||
"""
|
"""
|
||||||
|
# Check if the user is authenticated
|
||||||
if not self.request.user.is_authenticated:
|
if not self.request.user.is_authenticated:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# If we are given a pk in the request, do checks on it
|
||||||
|
given_contact_pk = self.kwargs["pk"]
|
||||||
|
|
||||||
|
if given_contact_pk:
|
||||||
|
# Grab the user in the DB to do a full object comparision, not just on ids
|
||||||
|
current_user = self.request.user
|
||||||
|
|
||||||
|
# Compare the PK that was passed in to the user currently logged in
|
||||||
|
if current_user.contact.pk != given_contact_pk:
|
||||||
|
# Don't allow users to modify other users profiles
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Check if the object at the id we're searching on actually exists
|
||||||
|
requested_user_exists = User.objects.filter(pk=current_user.pk).exists()
|
||||||
|
requested_contact_exists = Contact.objects.filter(user=current_user.pk, pk=given_contact_pk).exists()
|
||||||
|
|
||||||
|
if not requested_user_exists or not requested_contact_exists:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -13,7 +13,6 @@ from .mixins import (
|
||||||
DomainRequestWizardPermission,
|
DomainRequestWizardPermission,
|
||||||
UserDeleteDomainRolePermission,
|
UserDeleteDomainRolePermission,
|
||||||
UserProfilePermission,
|
UserProfilePermission,
|
||||||
ContactPermission,
|
|
||||||
)
|
)
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -163,17 +162,3 @@ class UserProfilePermissionView(UserProfilePermission, DetailView, abc.ABC):
|
||||||
def template_name(self):
|
def template_name(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class ContactPermissionView(ContactPermission, DetailView, abc.ABC):
|
|
||||||
"""Abstract base view for domain requests that enforces permissions
|
|
||||||
|
|
||||||
This abstract view cannot be instantiated. Actual views must specify
|
|
||||||
`template_name`.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# DetailView property for what model this is viewing
|
|
||||||
model = Contact
|
|
||||||
object: Contact
|
|
||||||
|
|
||||||
# variable name in template context for the model object
|
|
||||||
context_object_name = "contact"
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue