mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 12:39:43 +02:00
Try to add domain counting logic
This commit is contained in:
parent
e7a6eb30e0
commit
199f669fad
3 changed files with 49 additions and 12 deletions
|
@ -1943,13 +1943,14 @@ class MembersTable extends LoadTableBase {
|
||||||
extraActionsHeader.setAttribute('role', 'columnheader');
|
extraActionsHeader.setAttribute('role', 'columnheader');
|
||||||
extraActionsHeader.setAttribute('class', 'extra-actions-header');
|
extraActionsHeader.setAttribute('class', 'extra-actions-header');
|
||||||
extraActionsHeader.innerHTML = `
|
extraActionsHeader.innerHTML = `
|
||||||
<span class="usa-sr-only">Cancel invitation</span>`;
|
<span class="usa-sr-only">Extra Actions</span>`;
|
||||||
let tableHeaderRow = document.querySelector('#members thead tr');
|
let tableHeaderRow = document.querySelector('#members thead tr');
|
||||||
tableHeaderRow.appendChild(extraActionsHeader);
|
tableHeaderRow.appendChild(extraActionsHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.members.forEach(member => {
|
data.members.forEach(member => {
|
||||||
const member_name = member.name;
|
const member_name = member.name;
|
||||||
|
const member_email = member.email;
|
||||||
const member_display = member.member_display;
|
const member_display = member.member_display;
|
||||||
const options = { year: 'numeric', month: 'short', day: 'numeric' };
|
const options = { year: 'numeric', month: 'short', day: 'numeric' };
|
||||||
|
|
||||||
|
@ -1963,15 +1964,26 @@ class MembersTable extends LoadTableBase {
|
||||||
const member_id = member.id;
|
const member_id = member.id;
|
||||||
let isMemberInvited = !last_active || last_active === 'Invited';
|
let isMemberInvited = !last_active || last_active === 'Invited';
|
||||||
let cancelInvitationButton = isMemberInvited ? "Cancel invitation" : "Remove member";
|
let cancelInvitationButton = isMemberInvited ? "Cancel invitation" : "Remove member";
|
||||||
|
|
||||||
let modalHeading = 'asdasdasd';
|
// TODO: Create a function to fetch how many domains the member MANAGES
|
||||||
let modalDescription = 'asdasdasdasdasd';
|
// Created get_user_domain_count figure out how to call here and maybe view?
|
||||||
|
// let modalHeading = '';
|
||||||
|
// let modalDescription = '';
|
||||||
|
// If member manages 1 or more domains:
|
||||||
|
let modalHeading = `Are you sure you want to delete ${member_email}?`;
|
||||||
|
let modalDescription = `${member_email} current manages COUNTHERE domains in the organization \n
|
||||||
|
Removing them from the organization will remove all of their domains. They will no longer be able to \n
|
||||||
|
access this organization. This action cannot be undone.`;
|
||||||
|
// If member manages no domains:
|
||||||
|
// modalHeading = `Are you sure you want to delete ${member_email}?`;
|
||||||
|
// modalDescription = `They will no longer be able to access this organization. \n
|
||||||
|
// This action cannot be undone.`;
|
||||||
|
|
||||||
const modalSubmit = `
|
const modalSubmit = `
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="usa-button usa-button--secondary usa-modal__submit"
|
class="usa-button usa-button--secondary usa-modal__submit"
|
||||||
data-pk = ${member_id}
|
data-pk = ${member_id}
|
||||||
name="">Proceed</button>
|
name="">Yes, remove from organizaion</button>
|
||||||
`
|
`
|
||||||
|
|
||||||
const modal = document.createElement('div');
|
const modal = document.createElement('div');
|
||||||
|
@ -1979,7 +1991,7 @@ class MembersTable extends LoadTableBase {
|
||||||
modal.setAttribute('id', `toggle-remove-member-${member_id}`);
|
modal.setAttribute('id', `toggle-remove-member-${member_id}`);
|
||||||
modal.setAttribute('aria-labelledby', 'Are you sure you want to continue?');
|
modal.setAttribute('aria-labelledby', 'Are you sure you want to continue?');
|
||||||
modal.setAttribute('aria-describedby', 'Member will be removed');
|
modal.setAttribute('aria-describedby', 'Member will be removed');
|
||||||
modal.setAttribute('data-force-action', '');
|
modal.setAttribute('data-force-action', '');
|
||||||
|
|
||||||
modal.innerHTML = `
|
modal.innerHTML = `
|
||||||
<div class="usa-modal__content">
|
<div class="usa-modal__content">
|
||||||
|
@ -2023,7 +2035,6 @@ class MembersTable extends LoadTableBase {
|
||||||
`
|
`
|
||||||
this.tableWrapper.appendChild(modal);
|
this.tableWrapper.appendChild(modal);
|
||||||
|
|
||||||
|
|
||||||
kebob = `
|
kebob = `
|
||||||
<a
|
<a
|
||||||
role="button"
|
role="button"
|
||||||
|
@ -2069,8 +2080,6 @@ class MembersTable extends LoadTableBase {
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Handle 'Invited' or null/empty values differently from valid dates
|
// Handle 'Invited' or null/empty values differently from valid dates
|
||||||
if (last_active && last_active !== invited) {
|
if (last_active && last_active !== invited) {
|
||||||
try {
|
try {
|
||||||
|
@ -2098,7 +2107,7 @@ class MembersTable extends LoadTableBase {
|
||||||
const svg_icon = member.svg_icon;
|
const svg_icon = member.svg_icon;
|
||||||
|
|
||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
|
|
||||||
let admin_tagHTML = ``;
|
let admin_tagHTML = ``;
|
||||||
if (member.is_admin)
|
if (member.is_admin)
|
||||||
admin_tagHTML = `<span class="usa-tag margin-left-1 bg-primary">Admin</span>`
|
admin_tagHTML = `<span class="usa-tag margin-left-1 bg-primary">Admin</span>`
|
||||||
|
@ -2142,8 +2151,8 @@ class MembersTable extends LoadTableBase {
|
||||||
pageToDisplay--;
|
pageToDisplay--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the PK
|
// TODO: Use the PK to call a separate function that triggers a new backend AJAX call
|
||||||
// and call a separate function that triggers a new backend AJAX call to remove or delete
|
// to delete their UserDomainRoles only for this portfolio + remove their UserPortfolioPermissions
|
||||||
alert('modal submit')
|
alert('modal submit')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -471,3 +471,11 @@ class User(AbstractUser):
|
||||||
return DomainRequest.objects.filter(portfolio=portfolio).values_list("id", flat=True)
|
return DomainRequest.objects.filter(portfolio=portfolio).values_list("id", flat=True)
|
||||||
else:
|
else:
|
||||||
return UserDomainRole.objects.filter(user=self).values_list("id", flat=True)
|
return UserDomainRole.objects.filter(user=self).values_list("id", flat=True)
|
||||||
|
|
||||||
|
# def get_user_domain_count(self, request):
|
||||||
|
# """Returns the count of domains associated with this user on UserDomainRole or Portfolio"""
|
||||||
|
# portfolio = request.session.get("portfolio")
|
||||||
|
# if self.is_org_user(request) and self.has_view_all_domains_portfolio_permission(portfolio):
|
||||||
|
# return DomainInformation.objects.filter(portfolio=portfolio).count()
|
||||||
|
# else:
|
||||||
|
# return UserDomainRole.objects.filter(user=self).count()
|
||||||
|
|
|
@ -9,6 +9,8 @@ from django.db.models.functions import Cast
|
||||||
from registrar.models.portfolio_invitation import PortfolioInvitation
|
from registrar.models.portfolio_invitation import PortfolioInvitation
|
||||||
from registrar.models.user_portfolio_permission import UserPortfolioPermission
|
from registrar.models.user_portfolio_permission import UserPortfolioPermission
|
||||||
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
||||||
|
from registrar.models import DomainInformation, UserDomainRole
|
||||||
|
from .models import User
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -169,3 +171,21 @@ def serialize_members(request, portfolio, item, user):
|
||||||
"svg_icon": ("visibility" if view_only else "settings"),
|
"svg_icon": ("visibility" if view_only else "settings"),
|
||||||
}
|
}
|
||||||
return member_json
|
return member_json
|
||||||
|
|
||||||
|
|
||||||
|
def get_user_domain_count(request, user_id):
|
||||||
|
"""Returns the count of domains associated with the specified user on UserDomainRole or Portfolio"""
|
||||||
|
# Fetch the target user based on the user_id provided
|
||||||
|
try:
|
||||||
|
target_user = User.objects.get(id=user_id)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return JsonResponse({"error": "User not found."}, status=404)
|
||||||
|
|
||||||
|
portfolio = request.session.get("portfolio")
|
||||||
|
|
||||||
|
if target_user.is_org_user(request) and target_user.has_view_all_domains_portfolio_permission(portfolio):
|
||||||
|
domain_count = DomainInformation.objects.filter(portfolio=portfolio).count()
|
||||||
|
else:
|
||||||
|
domain_count = UserDomainRole.objects.filter(user=target_user).count()
|
||||||
|
|
||||||
|
return JsonResponse({"domain_count": domain_count})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue