Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #170 from cisagov/feature/cpd-433-450
Browse files Browse the repository at this point in the history
feature: cpd 433 - 450 un request categorization and add email toggle to cat page
  • Loading branch information
zenine07 authored Oct 6, 2021
2 parents e42192a + e8a2778 commit d22b1bd
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,76 +4,93 @@ <h4>Proxy Categorization - Domains To Submit</h4>
categorization service(s). Select the categorize button to link to the proxy
categorization website to allow you to select a category for a domain.
</div>
<div>
<mat-table [dataSource]="categoryList" matSort>
<!-- Domain Name -->
<ng-container matColumnDef="domain">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Domain</mat-header-cell
<div *ngFor="let domain of domainData">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
{{ domain.domain_name }}
</mat-panel-title>
<button
*ngIf="!domain.email_active"
mat-raised-button
class="domain-button"
color="primary"
(click)="toggleEmail(domain.domain_id)"
>
<mat-cell *matCellDef="let row">{{ row.domain_name }}</mat-cell>
</ng-container>

<!-- Proxy Name -->
<ng-container matColumnDef="proxy">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Proxy Source</mat-header-cell
Enable Email
</button>
<button
*ngIf="canReject(domain.categories.data)"
mat-stroked-button
class="domain-button"
color="warn"
(click)="reject(domain.domain_id)"
>
<mat-cell *matCellDef="let row">{{ row.proxy }}</mat-cell>
</ng-container>
Reject
</button>
</mat-expansion-panel-header>
<mat-table [dataSource]="domain.categories" matSort>
<!-- Proxy Name -->
<ng-container matColumnDef="proxy">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Proxy Source</mat-header-cell
>
<mat-cell *matCellDef="let row">{{ row.proxy }}</mat-cell>
</ng-container>

<!-- Status -->
<ng-container matColumnDef="status">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Status</mat-header-cell
>
<mat-cell *matCellDef="let row">{{ row.status }}</mat-cell>
</ng-container>
<!-- Status -->
<ng-container matColumnDef="status">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Status</mat-header-cell
>
<mat-cell *matCellDef="let row">{{ row.status }}</mat-cell>
</ng-container>

<!-- Category Name -->
<ng-container matColumnDef="category">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Preferred Category</mat-header-cell
>
<mat-cell *matCellDef="let row">{{ row.category }}</mat-cell>
</ng-container>
<!-- Category Name -->
<ng-container matColumnDef="category">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Preferred Category</mat-header-cell
>
<mat-cell *matCellDef="let row">{{ row.category }}</mat-cell>
</ng-container>

<!-- Date Requested -->
<ng-container matColumnDef="updated">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Date Requested</mat-header-cell
>
<mat-cell *matCellDef="let row">
<ng-container *ngIf="row['updated']; else elseCreated">{{
row.updated | date: "MM/dd/yy"
}}</ng-container>
<ng-template #elseCreated>{{
row.created | date: "MM/dd/yy"
}}</ng-template>
</mat-cell>
</ng-container>
<!-- Date Requested -->
<ng-container matColumnDef="updated">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Date Requested</mat-header-cell
>
<mat-cell *matCellDef="let row">
<ng-container *ngIf="row['updated']; else elseCreated">{{
row.updated | date: "MM/dd/yy"
}}</ng-container>
<ng-template #elseCreated>{{
row.created | date: "MM/dd/yy"
}}</ng-template>
</mat-cell>
</ng-container>

<!-- Categorize -->
<ng-container matColumnDef="categorize">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Categorize</mat-header-cell
>
<mat-cell *matCellDef="let row">
<button
mat-raised-button
(click)="categorize(row._id, row.categorize_url, row.category)"
color="primary"
<!-- Categorize -->
<ng-container matColumnDef="categorize">
<mat-header-cell *matHeaderCellDef mat-sort-header
>Categorize</mat-header-cell
>
Categorize
</button>
</mat-cell>
</ng-container>
<mat-cell *matCellDef="let row">
<button
mat-raised-button
(click)="categorize(row._id, row.categorize_url, row.category)"
color="primary"
>
Categorize
</button>
</mat-cell>
</ng-container>

<!-- Header Info -->
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row
class="table-row cursor-pointer"
*matRowDef="let row; columns: displayedColumns"
></mat-row>
</mat-table>
<!-- Header Info -->
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row
class="table-row cursor-pointer"
*matRowDef="let row; columns: displayedColumns"
></mat-row>
</mat-table>
</mat-expansion-panel>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mat-panel-title {
font-weight: bold;
margin-top: 5px;
}

.domain-button {
margin-right: 20px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { CategoryService } from 'src/app/services/category.service';
import { ConfirmCategoryDialogComponent } from 'src/app/components/dialog-windows/confirm-categorize/confirm-categorize-dialog.component';
import { LayoutService } from 'src/app/services/layout.service';
import { CategorizationTabService } from 'src/app/services/tab-services/categorization-tabs.service';
import { ConfirmDialogComponent } from 'src/app/components/dialog-windows/confirm/confirm-dialog.component';
import { ConfirmDialogSettings } from 'src/app/models/confirmDialogSettings.model';

@Component({
selector: 'app-categorization-submit',
Expand All @@ -18,15 +20,10 @@ import { CategorizationTabService } from 'src/app/services/tab-services/categori
})
export class CategorizationSubmitComponent {
categoryData = [];
displayedColumns = [
'domain',
'proxy',
'status',
'category',
'updated',
'categorize',
];
domainData = [];
displayedColumns = ['proxy', 'status', 'category', 'updated', 'categorize'];
categoryList: MatTableDataSource<any> = new MatTableDataSource<any>();
domainDetails = {};

@ViewChild(MatSort) sort: MatSort;
constructor(
Expand All @@ -51,8 +48,39 @@ export class CategorizationSubmitComponent {
(success) => {
if (Array.isArray(success)) {
this.categoryData = success as Array<any>;
this.categoryList = new MatTableDataSource<any>(success);
this.categoryList.sort = this.sort;
let uniqueVals = [
...new Set(this.categoryData.map((item) => item.domain_id)),
];
uniqueVals.forEach((val) => {
this.categorizationTabSvc.domainDetails(val).subscribe(
(success: any) => {
this.domainDetails = success as Object;
this.categoryData
.filter((x) => x.domain_id == val)
.forEach((cd) => {
let found = this.domainData.some(
(el) => el.domain_name === cd.domain_name
);
if (!found) {
this.domainData.push({
domain_name: cd.domain_name,
domain_id: cd.domain_id,
email_active: success.is_email_active,
categories: new MatTableDataSource<any>(
this.categoryData.filter(
(x) => x.domain_name == cd.domain_name
)
),
});
}
});
},
(failure) => {
console.log(failure);
return;
}
);
});
} else {
this.alertsSvc.alert('No domains for proxy submission.');
}
Expand All @@ -63,6 +91,22 @@ export class CategorizationSubmitComponent {
);
}

canEmail(domainId) {
this.categorizationTabSvc.domainDetails(domainId).subscribe(
(success) => {
this.domainDetails = success as Object;
},
(failure) => {
console.log(failure);
return;
}
);
}

canReject(categories) {
return categories.length === 8;
}

categorize(categorization_id, categorize_url, preferred_category) {
const dialogSettings = {
categoryList: this.categories,
Expand Down Expand Up @@ -95,4 +139,63 @@ export class CategorizationSubmitComponent {
});
window.open(categorize_url, '_blank');
}

reject(domain_id) {
const dialogSettings = new ConfirmDialogSettings();
dialogSettings.itemConfirming = 'Confirm Proxy Requests Delete';
dialogSettings.actionConfirming = `Are you sure you want to delete all proxies for this domain?`;
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: dialogSettings,
});

dialogRef.afterClosed().subscribe((result) => {
if (result === 'confirmed') {
this.categorizationTabSvc.deleteProxies(domain_id).subscribe(
(success) => {
this.alertsSvc.alert(
'Proxy requests for this domain have been deleted.'
);
const proxies = this.domainData.findIndex(
(obj) => obj.domain_id === domain_id
);
this.domainData.splice(proxies, 1);
this.domainData = this.domainData;
},
(failure) => {
console.log(failure);
this.alertsSvc.alert(`${failure.error.error}`);
}
);
} else {
dialogRef.close();
}
});
}

toggleEmail(domain_id) {
const dialogSettings = new ConfirmDialogSettings();
dialogSettings.itemConfirming = 'Enable Email Receiving';
dialogSettings.actionConfirming = `Are you sure you want to receive emails to this domain?`;
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
data: dialogSettings,
});

dialogRef.afterClosed().subscribe((result) => {
if (result === 'confirmed') {
this.categorizationTabSvc.enableEmailReceiving(domain_id).subscribe(
(success) => {
this.alertsSvc.alert(
'Email receiving for this domain has been enabled.'
);
},
(failure) => {
console.log(failure);
this.alertsSvc.alert(`${failure.error.error}`);
}
);
} else {
dialogRef.close();
}
});
}
}
10 changes: 10 additions & 0 deletions src/domainManagementUI/src/app/services/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export class CategoryService {
return this.http.get(url);
}

domainDetails(domainId: string) {
const url = `${this.settingsService.settings.apiUrl}/api/domain/${domainId}`;
return this.http.get(url);
}

submitCategory(domainId: string, categoryName: string) {
const url = `${this.settingsService.settings.apiUrl}/api/domain/${domainId}/categorize/`;
return this.http.post(url, { category: categoryName });
Expand All @@ -57,4 +62,9 @@ export class CategoryService {
const url = `${this.settingsService.settings.apiUrl}/api/categorization/${id}/`;
return this.http.put(url, data);
}

deleteProxyRequests(domainId: string) {
const url = `${this.settingsService.settings.apiUrl}/api/domain/${domainId}/categorize/`;
return this.http.delete(url);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Injectable, OnInit } from '@angular/core';
// Local Servie Imports
import { AlertsService } from 'src/app/services/alerts.service';
import { CategoryService } from 'src/app/services/category.service';
import { DomainService } from '../domain.service';
import { EmailService } from '../email.service';
import { UserAuthService } from 'src/app/services/user-auth.service';

// Models
Expand All @@ -27,6 +29,8 @@ export class CategorizationTabService {

constructor(
public alertsSvc: AlertsService,
public domainSvc: DomainService,
public emailSvc: EmailService,
public categorySvc: CategoryService,
private userAuthSvc: UserAuthService
) {
Expand All @@ -37,7 +41,19 @@ export class CategorizationTabService {
return this.categorySvc.getCategorizations(status);
}

domainDetails(domainId: string) {
return this.categorySvc.domainDetails(domainId);
}

updateCategory(id: string, data: object) {
return this.categorySvc.updateCategorization(id, data);
}

deleteProxies(domainId: string) {
return this.categorySvc.deleteProxyRequests(domainId);
}

enableEmailReceiving(domainId: string) {
return this.emailSvc.setDomainEmailsStatus(domainId, true);
}
}

0 comments on commit d22b1bd

Please sign in to comment.