Skip to content

Commit

Permalink
feat(jira issue save update with refactored code): updated current Ji…
Browse files Browse the repository at this point in the history
…ra functions for new table

Refactored Jira utility to have function documentation and broke apart functions. Updated vuln
controller API to export jira issues to use new Jira table.  Updated UI to handle new Jira table.
Updated UI to return if Jira is enabled.

feat #179
  • Loading branch information
alejandrosaenz117 committed Aug 12, 2020
1 parent 9730e0d commit 3b13445
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 490 deletions.
16 changes: 7 additions & 9 deletions frontend/src/app/asset-form/Asset.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
export class Asset {
constructor(
public id: number,
public name: string,
public organization: number,
public jiraUsername: string,
public jiraHost: string,
public jiraApiKey: string
) {}
import { Jira } from './Jira';

export interface Asset {
id: number;
name: string;
organization: number;
jira?: Jira;
}
7 changes: 7 additions & 0 deletions frontend/src/app/asset-form/Jira.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Jira {
id?: number;
username?: string;
host?: string;
url?: string;
apiKey?: string;
}
22 changes: 13 additions & 9 deletions frontend/src/app/asset-form/asset-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
<h5>Jira Integration</h5>
<hr />
</div>
<label for="assetName">JIRA Username</label>
<input formControlName="jiraUsername" type="text" class="form-control" id="jiraUsername" />
<label for="assetName">JIRA Host</label>
<input formControlName="jiraHost" type="text" class="form-control" id="jiraHost" />
<label for="assetName">JIRA API Key</label>
<input formControlName="jiraApiKey" type="password" class="form-control" id="jiraApiKey"
[placeholder]="keyPlaceholder" />
<div formGroupName="jira">
<label for="username">Username</label>
<input [readonly]="!canAddApiKey" formControlName="username" type="text" class="form-control"
id="username" />
<label for="host">Host</label>
<input [readonly]="!canAddApiKey" formControlName="host" type="text" class="form-control" id="host" />
<label for="apiKey">API Key</label>
<input [readonly]="!canAddApiKey" formControlName="apiKey" type="password" class="form-control" id="apiKey"
[placeholder]="canAddApiKey ? '':keyPlaceholder" />
</div>
<br>
<button type="button" class="float-right btn btn-warning" (click)="purgeJiraInfo()">Purge</button>
<button [disabled]="canAddApiKey" type="button" class="float-right btn btn-warning"
(click)="purgeJiraInfo()">Purge</button>
</div>
</div>
</div>
Expand All @@ -30,4 +34,4 @@ <h5>Jira Integration</h5>
Back to Assets
</button>
</form>
</div>
</div>
32 changes: 22 additions & 10 deletions frontend/src/app/asset-form/asset-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AssetFormComponent implements OnInit, OnChanges {
public orgId: number;
public assetId: number;
public keyPlaceholder = '************************';
public canAddApiKey: boolean;
constructor(
private fb: FormBuilder,
public appService: AppService,
Expand All @@ -30,6 +31,11 @@ export class AssetFormComponent implements OnInit, OnChanges {
if (asset) {
this.assetModel = asset;
this.rebuildForm();
if (asset.jira) {
this.canAddApiKey = false;
} else {
this.canAddApiKey = true;
}
}
});
this.activatedRoute.params.subscribe((params) => {
Expand All @@ -51,9 +57,11 @@ export class AssetFormComponent implements OnInit, OnChanges {
createForm() {
this.assetForm = this.fb.group({
name: ['', [Validators.required]],
jiraUsername: ['', []],
jiraHost: ['', []],
jiraApiKey: ['', []],
jira: this.fb.group({
username: ['', []],
host: ['', []],
apiKey: ['', []],
}),
});
}

Expand All @@ -63,9 +71,11 @@ export class AssetFormComponent implements OnInit, OnChanges {
rebuildForm() {
this.assetForm.reset({
name: this.assetModel.name,
jiraApiKey: this.assetModel?.jira?.apiKey,
jiraHost: this.assetModel?.jira?.host,
jiraUsername: this.assetModel?.jira?.username,
jira: {
username: this.assetModel?.jira?.username,
host: this.assetModel?.jira?.host,
apiKey: this.assetModel?.jira?.apiKey,
},
});
}

Expand All @@ -77,6 +87,9 @@ export class AssetFormComponent implements OnInit, OnChanges {
this.assetModel = asset.value;
this.assetModel.organization = this.orgId;
this.assetModel.id = this.assetId;
if (!this.canAddApiKey) {
this.assetModel.jira = null;
}
this.createOrUpdateAsset(this.assetModel);
}

Expand All @@ -88,16 +101,15 @@ export class AssetFormComponent implements OnInit, OnChanges {
}

purgeJiraInfo() {
const r = confirm(
`Purge API Key for username: "${this.assetModel.jira.username}"?`
);
const r = confirm(`Purge API Key for username: ""?`);
if (r) {
this.appService.purgeJira(this.assetForm['']).subscribe((res: string) => {
this.appService.purgeJira(this.assetId).subscribe((res: string) => {
this.alertService.success(res);
this.appService
.getAsset(this.assetId, this.orgId)
.subscribe((asset: Asset) => {
this.assetModel = asset;
this.canAddApiKey = true;
this.rebuildForm();
});
});
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/app/organization/organization.component.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<div class="container-fluid">
<div class="row">
<h3 class="mx-auto">{{ org?.name }} {{isArchive ? 'Archived':'Active'}} Assets</h3>
</div>
<br />
<h4 *ngIf="!assetAry.length">The organization {{ org?.name }} does not have any assets.</h4>
<table class="table" *ngIf="assetAry && assetAry.length">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Asset Name</th>
<th scope="col">Jira Enabled</th>
<th scope="col">Status</th>
<th scope="col"></th>
</tr>
</thead>
<tbody *ngFor="let asset of assetAry">
<td scope="row">{{ asset?.id }}</td>
<td>{{ asset?.name }}</td>
<td>{{asset?.jira?.id ? 'Yes' : 'No'}}</td>
<td>{{ asset?.status === 'A' ? 'Active':'Archived' }}</td>
<td>
<button *ngIf="!isArchive" class="btn btn-secondary" type="button" style="margin-right: 10px;"
Expand Down
Loading

0 comments on commit 3b13445

Please sign in to comment.