mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 04:29:44 +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('class', 'extra-actions-header');
|
||||
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');
|
||||
tableHeaderRow.appendChild(extraActionsHeader);
|
||||
}
|
||||
|
||||
data.members.forEach(member => {
|
||||
const member_name = member.name;
|
||||
const member_email = member.email;
|
||||
const member_display = member.member_display;
|
||||
const options = { year: 'numeric', month: 'short', day: 'numeric' };
|
||||
|
||||
|
@ -1964,14 +1965,25 @@ class MembersTable extends LoadTableBase {
|
|||
let isMemberInvited = !last_active || last_active === 'Invited';
|
||||
let cancelInvitationButton = isMemberInvited ? "Cancel invitation" : "Remove member";
|
||||
|
||||
let modalHeading = 'asdasdasd';
|
||||
let modalDescription = 'asdasdasdasdasd';
|
||||
// TODO: Create a function to fetch how many domains the member MANAGES
|
||||
// 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 = `
|
||||
<button type="button"
|
||||
class="usa-button usa-button--secondary usa-modal__submit"
|
||||
data-pk = ${member_id}
|
||||
name="">Proceed</button>
|
||||
name="">Yes, remove from organizaion</button>
|
||||
`
|
||||
|
||||
const modal = document.createElement('div');
|
||||
|
@ -2023,7 +2035,6 @@ class MembersTable extends LoadTableBase {
|
|||
`
|
||||
this.tableWrapper.appendChild(modal);
|
||||
|
||||
|
||||
kebob = `
|
||||
<a
|
||||
role="button"
|
||||
|
@ -2069,8 +2080,6 @@ class MembersTable extends LoadTableBase {
|
|||
`
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Handle 'Invited' or null/empty values differently from valid dates
|
||||
if (last_active && last_active !== invited) {
|
||||
try {
|
||||
|
@ -2142,8 +2151,8 @@ class MembersTable extends LoadTableBase {
|
|||
pageToDisplay--;
|
||||
}
|
||||
|
||||
// Use the PK
|
||||
// and call a separate function that triggers a new backend AJAX call to remove or delete
|
||||
// TODO: Use the PK to call a separate function that triggers a new backend AJAX call
|
||||
// to delete their UserDomainRoles only for this portfolio + remove their UserPortfolioPermissions
|
||||
alert('modal submit')
|
||||
|
||||
});
|
||||
|
|
|
@ -471,3 +471,11 @@ class User(AbstractUser):
|
|||
return DomainRequest.objects.filter(portfolio=portfolio).values_list("id", flat=True)
|
||||
else:
|
||||
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.user_portfolio_permission import UserPortfolioPermission
|
||||
from registrar.models.utility.portfolio_helper import UserPortfolioRoleChoices
|
||||
from registrar.models import DomainInformation, UserDomainRole
|
||||
from .models import User
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -169,3 +171,21 @@ def serialize_members(request, portfolio, item, user):
|
|||
"svg_icon": ("visibility" if view_only else "settings"),
|
||||
}
|
||||
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