[CST-4875] improvements

This commit is contained in:
Rezart Vata
2021-12-09 12:46:50 +01:00
parent f74716a459
commit 01b200279b
4 changed files with 16 additions and 13 deletions

View File

@@ -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<boolean | UrlTree> {
return this.authorizationService.isAuthorized(FeatureID.CanSendFeedback);
}

View File

@@ -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;

View File

@@ -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'));

View File

@@ -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 {
}