mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 21:19:42 +02:00
Addressed feedback
This commit is contained in:
parent
a5499dcc6f
commit
e0223e17b9
4 changed files with 1029 additions and 175 deletions
1130
src/package-lock.json
generated
1130
src/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,5 @@
|
||||||
import { uswdsInitializeModals } from './helpers-uswds.js';
|
import { uswdsInitializeModals } from './helpers-uswds.js';
|
||||||
|
import { getCsrfToken } from './helpers.js';
|
||||||
import { generateKebabHTML } from './table-base.js';
|
import { generateKebabHTML } from './table-base.js';
|
||||||
import { MembersTable } from './table-members.js';
|
import { MembersTable } from './table-members.js';
|
||||||
|
|
||||||
|
@ -82,6 +83,14 @@ export function initAddNewMemberPageListeners() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
Helper function to capitalize the first letter in a string (for display purposes)
|
||||||
|
*/
|
||||||
|
function capitalizeFirstLetter(text) {
|
||||||
|
if (!text) return ''; // Return empty string if input is falsy
|
||||||
|
return text.charAt(0).toUpperCase() + text.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Populates contents of the "Add Member" confirmation modal
|
Populates contents of the "Add Member" confirmation modal
|
||||||
*/
|
*/
|
||||||
|
@ -90,7 +99,7 @@ export function initAddNewMemberPageListeners() {
|
||||||
permissionDetailsContainer.innerHTML = ""; // Clear previous content
|
permissionDetailsContainer.innerHTML = ""; // Clear previous content
|
||||||
|
|
||||||
// Get all permission sections (divs with h3 and radio inputs)
|
// Get all permission sections (divs with h3 and radio inputs)
|
||||||
const permissionSections = document.querySelectorAll("#"+permission_details_div_id+" > h3");
|
const permissionSections = document.querySelectorAll(`#${permission_details_div_id} > h3`);
|
||||||
|
|
||||||
permissionSections.forEach(section => {
|
permissionSections.forEach(section => {
|
||||||
// Find the <h3> element text
|
// Find the <h3> element text
|
||||||
|
@ -138,7 +147,9 @@ export function initAddNewMemberPageListeners() {
|
||||||
|
|
||||||
// Get selected radio button for access level
|
// Get selected radio button for access level
|
||||||
let selectedAccess = document.querySelector('input[name="member_access_level"]:checked');
|
let selectedAccess = document.querySelector('input[name="member_access_level"]:checked');
|
||||||
let accessText = selectedAccess ? selectedAccess.value : "No access level selected"; //nextElementSibling.textContent.trim()
|
// Set the selected permission text to 'Basic' or 'Admin' (the value of the selected radio button)
|
||||||
|
// This value does not have the first letter capitalized so let's capitalize it
|
||||||
|
let accessText = selectedAccess ? capitalizeFirstLetter(selectedAccess.value) : "No access level selected";
|
||||||
document.getElementById('modalAccessLevel').textContent = accessText;
|
document.getElementById('modalAccessLevel').textContent = accessText;
|
||||||
|
|
||||||
// Populate permission details based on access level
|
// Populate permission details based on access level
|
||||||
|
|
|
@ -1876,7 +1876,7 @@ class TestPortfolio(WebTest):
|
||||||
portfolio=self.portfolio,
|
portfolio=self.portfolio,
|
||||||
roles=[UserPortfolioRoleChoices.ORGANIZATION_MEMBER],
|
roles=[UserPortfolioRoleChoices.ORGANIZATION_MEMBER],
|
||||||
)
|
)
|
||||||
with patch("django.contrib.messages.success") as mock_success:
|
e with patch("django.contrib.messages.success") as mock_success:
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse("invitedmember-delete", kwargs={"pk": invitation.pk}),
|
reverse("invitedmember-delete", kwargs={"pk": invitation.pk}),
|
||||||
|
|
|
@ -548,6 +548,7 @@ class NewMemberView(PortfolioMembersPermissionView, FormMixin):
|
||||||
# Check to see if an invite has already been sent
|
# Check to see if an invite has already been sent
|
||||||
try:
|
try:
|
||||||
invite = PortfolioInvitation.objects.get(email=email, portfolio=self.object)
|
invite = PortfolioInvitation.objects.get(email=email, portfolio=self.object)
|
||||||
|
if invite: # We have an existin invite
|
||||||
# check if the invite has already been accepted
|
# check if the invite has already been accepted
|
||||||
if invite.status == PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED:
|
if invite.status == PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED:
|
||||||
add_success = False
|
add_success = False
|
||||||
|
@ -557,8 +558,9 @@ class NewMemberView(PortfolioMembersPermissionView, FormMixin):
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
add_success = False
|
add_success = False
|
||||||
# else if it has been sent but not accepted
|
# it has been sent but not accepted
|
||||||
messages.warning(self.request, f"{email} has already been invited to this portfolio")
|
messages.warning(self.request, f"{email} has already been invited to this portfolio")
|
||||||
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error("An error occured")
|
logger.error("An error occured")
|
||||||
|
|
||||||
|
@ -586,11 +588,23 @@ class NewMemberView(PortfolioMembersPermissionView, FormMixin):
|
||||||
if add_success:
|
if add_success:
|
||||||
messages.success(self.request, f"{email} has been invited.")
|
messages.success(self.request, f"{email} has been invited.")
|
||||||
|
|
||||||
def _make_invitation(self, email_address: str, requestor: User):
|
def _make_invitation(self, email_address: str, requestor: User, add_success=True):
|
||||||
"""Make a Member invitation for this email and redirect with a message."""
|
"""Make a Member invitation for this email and redirect with a message."""
|
||||||
try:
|
try:
|
||||||
self._send_portfolio_invitation_email(email=email_address, requestor=requestor)
|
self._send_portfolio_invitation_email(email=email_address, requestor=requestor, add_success=add_success)
|
||||||
except EmailSendingError:
|
except EmailSendingError:
|
||||||
|
logger.warn(
|
||||||
|
"Could not send email invitation (EmailSendingError)",
|
||||||
|
self.object,
|
||||||
|
exc_info=True,
|
||||||
|
)
|
||||||
|
messages.warning(self.request, "Could not send email invitation.")
|
||||||
|
except Exception:
|
||||||
|
logger.warn(
|
||||||
|
"Could not send email invitation (Other Exception)",
|
||||||
|
self.object,
|
||||||
|
exc_info=True,
|
||||||
|
)
|
||||||
messages.warning(self.request, "Could not send email invitation.")
|
messages.warning(self.request, "Could not send email invitation.")
|
||||||
else:
|
else:
|
||||||
# (NOTE: only create a MemberInvitation if the e-mail sends correctly)
|
# (NOTE: only create a MemberInvitation if the e-mail sends correctly)
|
||||||
|
@ -604,6 +618,21 @@ class NewMemberView(PortfolioMembersPermissionView, FormMixin):
|
||||||
requested_email = form.cleaned_data["email"]
|
requested_email = form.cleaned_data["email"]
|
||||||
requestor = self.request.user
|
requestor = self.request.user
|
||||||
|
|
||||||
|
requested_user = User.objects.filter(email=requested_email).first()
|
||||||
|
permission_exists = UserPortfolioPermission.objects.filter(user=requested_user, portfolio=self.object).exists()
|
||||||
|
if not requested_user or not permission_exists:
|
||||||
|
return self._make_invitation(requested_email, requestor)
|
||||||
|
else:
|
||||||
|
if permission_exists:
|
||||||
|
messages.warning(self.request, "User is already a member of this portfolio.")
|
||||||
|
return redirect(self.get_success_url())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# look up a user with that email
|
# look up a user with that email
|
||||||
try:
|
try:
|
||||||
requested_user = User.objects.get(email=requested_email)
|
requested_user = User.objects.get(email=requested_email)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue