Skip to content

Commit

Permalink
Try to add domain counting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
therealslimhsiehdy committed Oct 21, 2024
1 parent e7a6eb3 commit 199f669
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/registrar/assets/js/get-gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };

Expand All @@ -1963,23 +1964,34 @@ class MembersTable extends LoadTableBase {
const member_id = member.id;
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');
modal.setAttribute('class', 'usa-modal');
modal.setAttribute('id', `toggle-remove-member-${member_id}`);
modal.setAttribute('aria-labelledby', 'Are you sure you want to continue?');
modal.setAttribute('aria-describedby', 'Member will be removed');
modal.setAttribute('data-force-action', '');
modal.setAttribute('data-force-action', '');

modal.innerHTML = `
<div class="usa-modal__content">
Expand Down Expand Up @@ -2023,7 +2035,6 @@ class MembersTable extends LoadTableBase {
`
this.tableWrapper.appendChild(modal);


kebob = `
<a
role="button"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2098,7 +2107,7 @@ class MembersTable extends LoadTableBase {
const svg_icon = member.svg_icon;

const row = document.createElement('tr');

let admin_tagHTML = ``;
if (member.is_admin)
admin_tagHTML = `<span class="usa-tag margin-left-1 bg-primary">Admin</span>`
Expand Down Expand Up @@ -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')

});
Expand Down
8 changes: 8 additions & 0 deletions src/registrar/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,11 @@ def get_user_domain_request_ids(self, request):
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()
20 changes: 20 additions & 0 deletions src/registrar/views/portfolio_members_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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
Expand Down Expand Up @@ -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})

0 comments on commit 199f669

Please sign in to comment.