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

Uncaught error when invalid link is clicked #1239

Merged
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
3 changes: 2 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const routes: Routes = [
{ path: 'phaseBugReporting', loadChildren: () => PhaseBugReportingModule, canLoad: [AuthGuard] },
{ path: 'phaseTeamResponse', loadChildren: () => PhaseTeamResponseModule, canLoad: [AuthGuard] },
{ path: 'phaseTesterResponse', loadChildren: () => PhaseTesterResponseModule, canLoad: [AuthGuard] },
{ path: 'phaseModeration', loadChildren: () => PhaseModerationModule, canLoad: [AuthGuard] }
{ path: 'phaseModeration', loadChildren: () => PhaseModerationModule, canLoad: [AuthGuard] },
{ path: '**', redirectTo: '' }
];

@NgModule({
Expand Down
32 changes: 32 additions & 0 deletions src/app/core/directives/internal-link-disable.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Directive, HostListener } from '@angular/core';
import { ErrorHandlingService } from '../services/error-handling.service';

class InvalidLinkError extends Error {
constructor() {
super('Invalid link!');
Object.setPrototypeOf(this, InvalidLinkError.prototype);
}
}

@Directive({
selector: '[disableInternalLink]'
})
export class InternalLinkDisableDirective {
constructor(private errorHandlingService: ErrorHandlingService) {}

@HostListener('click', ['$event'])
public onClick(e: MouseEvent): void {
const srcElement = e.target;

if (srcElement instanceof HTMLAnchorElement) {
const baseURI = srcElement.baseURI;
const href = srcElement.href;

if (href.startsWith(baseURI)) {
this.errorHandlingService.handleError(new InvalidLinkError());
e.preventDefault();
e.stopPropagation();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</mat-tab>
<mat-tab label="Preview">
<div class="tab-content" style="min-height: 228px">
<markdown #markdownArea *ngIf="commentField.value !== ''" [data]="sanitize(commentField.value)"></markdown>
<markdown #markdownArea *ngIf="commentField.value !== ''" [data]="sanitize(commentField.value)" disableInternalLink></markdown>
<div *ngIf="commentField.value === ''">Nothing to preview.</div>
</div>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h3 class="mat-title">{{ descriptionTitle }}</h3>
</button>
</div>
<div *ngIf="!isEditing" class="comment">
<markdown [data]="issue.description"></markdown>
<markdown [data]="issue.description" disableInternalLink></markdown>
</div>
<div *ngIf="isEditing">
<app-comment-editor
Expand Down
4 changes: 3 additions & 1 deletion src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { FormDisableControlDirective } from '../core/directives/form-disable-control.directive';
import { InternalLinkDisableDirective } from '../core/directives/internal-link-disable.directive';
import { ActionToasterModule } from './action-toasters/action-toasters.module';
import { ErrorToasterModule } from './error-toasters/error-toaster.module';
import { MaterialModule } from './material.module';

@NgModule({
imports: [CommonModule, FormsModule, ReactiveFormsModule, HttpClientModule, RouterModule, MaterialModule, ErrorToasterModule],
declarations: [FormDisableControlDirective],
declarations: [FormDisableControlDirective, InternalLinkDisableDirective],
exports: [
FormDisableControlDirective,
InternalLinkDisableDirective,
CommonModule,
FormsModule,
ReactiveFormsModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ <h3 class="mat-title">Disputes</h3>
<div class="container" *ngFor="let dispute of issue.issueDisputes; index as i; trackBy: trackDisputeList">
<div style="display: flex; align-items: center">
<div class="question-mark">?</div>
<markdown [data]="this.getItemTitleText(dispute.title)"></markdown>
<markdown [data]="this.getItemTitleText(dispute.title)" disableInternalLink></markdown>
</div>
<br />
<markdown [data]="dispute.description"></markdown>
<markdown [data]="dispute.description" disableInternalLink></markdown>
<br />
<div>
<mat-checkbox
Expand All @@ -27,7 +27,7 @@ <h3 class="mat-title">Disputes</h3>
<br />
<div>
<markdown data="### Tutor's Response: "></markdown>
<markdown [data]="dispute.tutorResponse" *ngIf="!isEditing"></markdown>
<markdown [data]="dispute.tutorResponse" *ngIf="!isEditing" disableInternalLink></markdown>
</div>
<div *ngIf="isEditing">
<app-comment-editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h3 class="mat-title">Team's Response</h3>
<button style="float: right" mat-button *ngIf="canEditIssue() && !isEditing" (click)="changeToEditMode()">Edit</button>
</div>
<div *ngIf="!isEditing" class="comment">
<markdown [data]="issue.teamResponse"></markdown>
<markdown [data]="issue.teamResponse" disableInternalLink></markdown>
</div>
<div *ngIf="isEditing">
<app-comment-editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 mat-dialog-title style="margin: 0">{{ 'The content you are editing has chang
<mat-expansion-panel-header>
<mat-panel-title class="response-title">
<div class="question-mark">?</div>
<markdown [data]="data.updatedResponses[i].getTitleInMarkDown()"></markdown>
<markdown [data]="data.updatedResponses[i].getTitleInMarkDown()" disableInternalLink></markdown>
</mat-panel-title>
<mat-panel-description>
<mat-chip-list>
Expand All @@ -25,7 +25,7 @@ <h1 mat-dialog-title style="margin: 0">{{ 'The content you are editing has chang
</mat-panel-description>
</mat-expansion-panel-header>
<br />
<markdown [data]="data.updatedResponses[i].description"></markdown>
<markdown [data]="data.updatedResponses[i].description" disableInternalLink></markdown>
<br />
<div
*ngIf="data.updatedResponses[i].isDisagree() === data.outdatedResponses[i].isDisagree() || !showDiff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ <h3 class="mat-title">Tester's Response</h3>
<div class="container" *ngFor="let response of issue.testerResponses; index as i; trackBy: trackDisagreeList">
<div style="display: flex; align-items: center">
<div class="question-mark">?</div>
<markdown [data]="response.getTitleInMarkDown()"></markdown>
<markdown [data]="response.getTitleInMarkDown()" disableInternalLink></markdown>
</div>
<br />
<markdown [data]="response.description"></markdown>
<markdown [data]="response.description" disableInternalLink></markdown>
<br />
<div>
<mat-radio-group
Expand All @@ -31,7 +31,7 @@ <h3 class="mat-title">Tester's Response</h3>
<div *ngIf="testerResponseForm.get(getDisagreeRadioFormId(i)).value">
<div>
<p style="font-weight: 500">Reason for Disagreement:</p>
<markdown [data]="response.reasonForDisagreement" *ngIf="!isEditing"></markdown>
<markdown [data]="response.reasonForDisagreement" *ngIf="!isEditing" disableInternalLink></markdown>
</div>
<div *ngIf="isEditing">
<app-comment-editor
Expand Down
Loading