From 01b200279b6554de3f5d1d41ae2d9fb383c6f7e3 Mon Sep 17 00:00:00 2001 From: Rezart Vata Date: Thu, 9 Dec 2021 12:46:50 +0100 Subject: [PATCH] [CST-4875] improvements --- src/app/core/feedback/feedback.guard.ts | 13 +++---------- src/app/core/feedback/models/feedback.model.ts | 2 +- .../feedback-content/feedback-content.component.ts | 9 +++++++++ src/app/info/info.module.ts | 5 +++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/app/core/feedback/feedback.guard.ts b/src/app/core/feedback/feedback.guard.ts index e51b6990e3..26b73e3f29 100644 --- a/src/app/core/feedback/feedback.guard.ts +++ b/src/app/core/feedback/feedback.guard.ts @@ -5,21 +5,14 @@ import { FeatureID } from 'src/app/core/data/feature-authorization/feature-id'; import { Injectable } from '@angular/core'; /** - * An abstract guard for redirecting users to the user agreement page if a certain condition is met - * That condition is defined by abstract method hasAccepted + * An guard for redirecting users to the feedback page if user is authorized */ @Injectable() -export abstract class FeedbackGuard implements CanActivate { +export class FeedbackGuard implements CanActivate { - constructor(protected router: Router, private authorizationService: AuthorizationDataService) { + constructor(private authorizationService: AuthorizationDataService) { } - /** - * True when the user agreement has been accepted - * The user will be redirected to the End User Agreement page if they haven't accepted it before - * A redirect URL will be provided with the navigation so the component can redirect the user back to the blocked route - * when they're finished accepting the agreement - */ canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { return this.authorizationService.isAuthorized(FeatureID.CanSendFeedback); } diff --git a/src/app/core/feedback/models/feedback.model.ts b/src/app/core/feedback/models/feedback.model.ts index 33a7c3e150..165ec6d760 100644 --- a/src/app/core/feedback/models/feedback.model.ts +++ b/src/app/core/feedback/models/feedback.model.ts @@ -20,7 +20,7 @@ export class Feedback extends DSpaceObject { public email: string; /** - * A ring representing message the user inserted + * A string representing message the user inserted */ @autoserialize public message: string; diff --git a/src/app/info/feedback/feedback-content/feedback-content.component.ts b/src/app/info/feedback/feedback-content/feedback-content.component.ts index f76ab02469..d92fcf4307 100644 --- a/src/app/info/feedback/feedback-content/feedback-content.component.ts +++ b/src/app/info/feedback/feedback-content/feedback-content.component.ts @@ -19,6 +19,9 @@ import { EPerson } from '../../../core/eperson/models/eperson.model'; */ export class FeedbackContentComponent implements OnInit { + /** + * Form builder created used from the feedback from + */ feedbackForm = this.fb.group({ email: ['', [Validators.required, Validators.pattern('^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$')]], message: ['', Validators.required], @@ -34,6 +37,9 @@ export class FeedbackContentComponent implements OnInit { private authService: AuthService) { } + /** + * On init check if user is logged in and use its email if so + */ ngOnInit() { this.authService.getAuthenticatedUserFromStore().subscribe((user: EPerson) => { if (!!user) { @@ -42,6 +48,9 @@ export class FeedbackContentComponent implements OnInit { }); } + /** + * Function to create the feedback from form values + */ createFeedback() { this.feedbackDataService.createFeedback(this.feedbackForm.value).subscribe((response: Feedback) => { this.notificationsService.success(this.translate.instant('info.feedback.create.success')); diff --git a/src/app/info/info.module.ts b/src/app/info/info.module.ts index f8623d3377..1feb770e0e 100644 --- a/src/app/info/info.module.ts +++ b/src/app/info/info.module.ts @@ -11,7 +11,7 @@ import { ThemedPrivacyComponent } from './privacy/themed-privacy.component'; import { FeedbackComponent } from './feedback/feedback.component'; import { FeedbackContentComponent } from './feedback/feedback-content/feedback-content.component'; import { ThemedFeedbackComponent } from './feedback/themed-feedback.component'; -import { ReactiveFormsModule } from '@angular/forms'; +import { FeedbackGuard } from '../core/feedback/feedback.guard'; const DECLARATIONS = [ @@ -37,7 +37,8 @@ const DECLARATIONS = [ ], exports: [ ...DECLARATIONS - ] + ], + providers: [FeedbackGuard] }) export class InfoModule { }