Skip to content

Commit

Permalink
Merge pull request #2878 from cisagov/rh/2592-domain-request-export
Browse files Browse the repository at this point in the history
#2592: Domain Request CSV Export - [RH]
  • Loading branch information
therealslimhsiehdy authored Oct 7, 2024
2 parents 482b456 + ce6ad59 commit 286cf8e
Show file tree
Hide file tree
Showing 7 changed files with 398 additions and 183 deletions.
17 changes: 16 additions & 1 deletion src/registrar/assets/js/get-gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,12 +1498,23 @@ class DomainsTable extends LoadTableBase {
}
}


class DomainRequestsTable extends LoadTableBase {

constructor() {
super('.domain-requests__table', '.domain-requests__table-wrapper', '#domain-requests__search-field', '#domain-requests__search-field-submit', '.domain-requests__reset-search', '.domain-requests__reset-filters', '.domain-requests__no-data', '.domain-requests__no-search-results');
}

toggleExportButton(requests) {
const exportButton = document.getElementById('export-csv');
if (exportButton) {
if (requests.length > 0) {
showElement(exportButton);
} else {
hideElement(exportButton);
}
}
}

/**
* Loads rows in the domains list, as well as updates pagination around the domains list
* based on the supplied attributes.
Expand All @@ -1517,6 +1528,7 @@ class DomainRequestsTable extends LoadTableBase {
*/
loadTable(page, sortBy = this.currentSortBy, order = this.currentOrder, scroll = this.scrollToTable, status = this.currentStatus, searchTerm = this.currentSearchTerm, portfolio = this.portfolioValue) {
let baseUrl = document.getElementById("get_domain_requests_json_url");

if (!baseUrl) {
return;
}
Expand Down Expand Up @@ -1548,6 +1560,9 @@ class DomainRequestsTable extends LoadTableBase {
return;
}

// Manage "export as CSV" visibility for domain requests
this.toggleExportButton(data.domain_requests);

// handle the display of proper messaging in the event that no requests exist in the list or search returns no results
this.updateDisplay(data, this.tableWrapper, this.noTableWrapper, this.noSearchResultsWrapper, this.currentSearchTerm);

Expand Down
6 changes: 6 additions & 0 deletions src/registrar/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
AnalyticsView,
ExportDomainRequestDataFull,
ExportDataTypeUser,
ExportDataTypeRequests,
)

# --jsons
Expand Down Expand Up @@ -177,6 +178,11 @@
ExportDataTypeUser.as_view(),
name="export_data_type_user",
),
path(
"reports/export_data_type_requests/",
ExportDataTypeRequests.as_view(),
name="export_data_type_requests",
),
path(
"domain-request/<id>/edit/",
views.DomainRequestWizard.as_view(),
Expand Down
13 changes: 13 additions & 0 deletions src/registrar/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ def has_view_all_domains_portfolio_permission(self, portfolio):
"""Determines if the current user can view all available domains in a given portfolio"""
return self._has_portfolio_permission(portfolio, UserPortfolioPermissionChoices.VIEW_ALL_DOMAINS)

def has_view_all_domain_requests_portfolio_permission(self, portfolio):
"""Determines if the current user can view all available domains in a given portfolio"""
return self._has_portfolio_permission(portfolio, UserPortfolioPermissionChoices.VIEW_ALL_REQUESTS)

def has_any_requests_portfolio_permission(self, portfolio):
# BEGIN
# Note code below is to add organization_request feature
Expand Down Expand Up @@ -458,3 +462,12 @@ def get_user_domain_ids(self, request):
return DomainInformation.objects.filter(portfolio=portfolio).values_list("domain_id", flat=True)
else:
return UserDomainRole.objects.filter(user=self).values_list("domain_id", flat=True)

def get_user_domain_request_ids(self, request):
"""Returns either the domain request ids associated with this user on UserDomainRole or Portfolio"""
portfolio = request.session.get("portfolio")

if self.is_org_user(request) and self.has_view_all_domain_requests_portfolio_permission(portfolio):
return DomainRequest.objects.filter(portfolio=portfolio).values_list("id", flat=True)
else:
return UserDomainRole.objects.filter(user=self).values_list("id", flat=True)
Loading

0 comments on commit 286cf8e

Please sign in to comment.