Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'override' indicator to component answers in Site Detail Report #4041

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,20 @@ private void AddResponseComponentOverride(QuestionResponse resp, List<Answer_Com
if ((dbQ.Symbol_Name != symbolType)
|| (dbQ.ComponentName != componentName))
{
componentName = Helpers.Utilities.RemoveHtmlTags(dbQ.ComponentName, true);

qg = new QuestionGroup()
{
GroupHeadingText = dbQ.Question_Group_Heading,
GroupHeadingId = dbQ.GroupHeadingId,
StandardShortName = listname,
Symbol_Name = dbQ.Symbol_Name,
ComponentName = dbQ.ComponentName,
ComponentName = componentName,
IsOverride = true

};
groupList.Add(qg);
symbolType = dbQ.Symbol_Name;
componentName = dbQ.ComponentName;

curGroupHeading = qg.GroupHeadingText;
// start numbering again in new group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1316,11 +1316,11 @@ public List<ComponentQuestion> GetComponentQuestions()
QuestionId = q.Question_Id,
LayerName = q.LayerName,
SAL = q.SAL,
Zone = q.ZoneName
Zone = q.ZoneName,
IsOverride = (q.Answer_Id != null)
});
}


return l;
}

Expand Down
21 changes: 21 additions & 0 deletions CSETWebApi/CSETWeb_Api/CSETWebCore.Helpers/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.RegularExpressions;
using CSETWebCore.DataLayer.Model;
using CSETWebCore.Interfaces.Helpers;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -98,6 +99,26 @@ public string GetClientHost()
}


/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string RemoveHtmlTags(string input, bool replaceWithSpace)
{
// Remove script tags first to prevent potential XSS attacks
input = Regex.Replace(input, "<script[^>]*?>.*?</script>", string.Empty, RegexOptions.IgnoreCase);

// Remove style tags to avoid unwanted formatting
input = Regex.Replace(input, "<style[^>]*?>.*?</style>", string.Empty, RegexOptions.IgnoreCase);

// Remove all other HTML tags and attributes
input = Regex.Replace(input, "<[^>]*>", (replaceWithSpace ? " " : string.Empty), RegexOptions.IgnoreCase);

return input;
}


/// <summary>
/// One-time use function that moves Hydro-specific action items
/// out of the ISE_ACTIONS table and into the HYDRO_DATA table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public class ComponentQuestion
public string Zone { get; set; }
public string SAL { get; set; }
public string LayerName { get; set; }
public bool IsOverride { get; set; }
}

public class RankedQuestions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
<div class="row">
<div class="col-12">
<table class="assessment-summary">
<th colspan="2">Specific Component Name</th>
<tr>
<th colspan="2">Specific Component Name</th>
</tr>
<tr *ngFor="let q of questions; let i = index">
<td>{{q.componentName}}</td>
<td>{{ utilitiesSvc.removeHtmlTags(q.componentName, true) }}</td>
<td>
<div class="btn-group btn-group-toggle answer-group" data-toggle="buttons" style="float:right;">
<label *ngIf="showThisOption('Y')" class="btn btn-yes form-check-label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { ConfigService } from '../../services/config.service';
import { Answer } from '../../models/questions.model';
import { QuestionsService } from '../../services/questions.service';
import { Utilities } from '../../services/utilities.service';

@Component({
selector: 'component-override',
Expand All @@ -44,8 +45,11 @@ export class ComponentOverrideComponent {
/**
* Constructor.
*/
constructor(private dialog: MatDialogRef<ComponentOverrideComponent>,
public configSvc: ConfigService, public questionsSvc: QuestionsService,
constructor(
private dialog: MatDialogRef<ComponentOverrideComponent>,
public configSvc: ConfigService,
public questionsSvc: QuestionsService,
public utilitiesSvc: Utilities,
@Inject(MAT_DIALOG_DATA) public data: any) {
dialog.beforeClosed().subscribe(() => dialog.close(this.questionChanged));
this.questionsSvc.getOverrideQuestions(data.myQuestion.questionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ <h1>
</h1>

<table *ngIf="data?.length > 0" class="cset-table-3">
<tr>
<th>Component Name</th>
<th>Question</th>
<th>Answer</th>
</tr>
<tr *ngFor="let cq of data">
<td class="tint2" style="width: 20%" [innerHTML]="cq.componentName"> </td>
<td class="tint2" style="width: 20%">{{ cq.componentName }}</td>
<td [innerHTML]="cq.question"></td>
<td class="tint2" style="width: 20%">{{questionsSvc.answerDisplayLabel('', cq.answer)}}</td>
<td class="tint2" style="width: 20%">{{ questionsSvc.answerDisplayLabel('', cq.answer) }}
<div *ngIf="cq.isOverride">({{ tSvc.translate('extras.override') }})</div>
</td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
// SOFTWARE.
//
////////////////////////////////
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { QuestionsService } from '../../services/questions.service';
import { Utilities } from '../../services/utilities.service';
import { TranslocoService } from '@ngneat/transloco';

@Component({
selector: 'app-component-question-list',
templateUrl: './component-question-list.component.html',
styleUrls: ['../reports.scss']
})
export class ComponentQuestionListComponent implements OnInit {
export class ComponentQuestionListComponent implements OnInit, OnChanges {

@Input()
data: any[];
Expand All @@ -38,13 +40,22 @@ export class ComponentQuestionListComponent implements OnInit {
*
*/
constructor(
public questionsSvc: QuestionsService
public questionsSvc: QuestionsService,
public utilitiesSvc: Utilities,
public tSvc: TranslocoService
) { }

/**
*
*/
ngOnInit(): void {
}
ngOnInit(): void { }

/**
*
*/
ngOnChanges(): void {
this.data.forEach(x => {
x.componentName = this.utilitiesSvc.removeHtmlTags(x.componentName, true);
});
}
}
10 changes: 10 additions & 0 deletions CSETWebNg/src/app/services/utilities.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,14 @@
}
return result;
}

/**
*
*/
public removeHtmlTags(input: string, replaceWithSpace: boolean): string {
// Remove all other HTML tags and attributes
input = input.replace(/<[^>]*>/g, replaceWithSpace ? ' ' : '');

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.

return input;
}
}
Loading