From 73a0ffc30e8fd249305006a6346ededf97fa3a97 Mon Sep 17 00:00:00 2001 From: amentis Date: Fri, 21 Jun 2024 17:26:27 +0300 Subject: [PATCH] add user invitation errors to errors.yml --- .../errorcode/ErrorThesaurusProperties.java | 20 +++++++++++++++++++ .../service/user/UserServiceImpl.java | 15 +++++++------- .../web/src/main/resources/config/errors.yml | 8 +++++++- .../core/common/enum/respone-error-code.ts | 6 ++++++ .../user-invite-confirmation.component.ts | 4 +++- dmp-frontend/src/assets/i18n/baq.json | 4 +++- dmp-frontend/src/assets/i18n/de.json | 4 +++- dmp-frontend/src/assets/i18n/en.json | 4 +++- dmp-frontend/src/assets/i18n/es.json | 4 +++- dmp-frontend/src/assets/i18n/gr.json | 4 +++- dmp-frontend/src/assets/i18n/hr.json | 4 +++- dmp-frontend/src/assets/i18n/pl.json | 4 +++- dmp-frontend/src/assets/i18n/pt.json | 4 +++- dmp-frontend/src/assets/i18n/sk.json | 4 +++- dmp-frontend/src/assets/i18n/sr.json | 4 +++- dmp-frontend/src/assets/i18n/tr.json | 4 +++- 16 files changed, 77 insertions(+), 20 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java index 5d69b373f..cc60f35b1 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -358,4 +358,24 @@ public class ErrorThesaurusProperties { public void setPrefillingSourceCodeExists(ErrorDescription prefillingSourceCodeExists) { this.prefillingSourceCodeExists = prefillingSourceCodeExists; } + + private ErrorDescription inviteUserAlreadyConfirmed; + + public ErrorDescription getInviteUserAlreadyConfirmed() { + return inviteUserAlreadyConfirmed; + } + + public void setInviteUserAlreadyConfirmed(ErrorDescription inviteUserAlreadyConfirmed) { + this.inviteUserAlreadyConfirmed = inviteUserAlreadyConfirmed; + } + + private ErrorDescription requestHasExpired; + + public ErrorDescription getRequestHasExpired() { + return requestHasExpired; + } + + public void setRequestHasExpired(ErrorDescription requestHasExpired) { + this.requestHasExpired = requestHasExpired; + } } diff --git a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java index 45082de90..146979e47 100644 --- a/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java +++ b/backend/core/src/main/java/org/opencdmp/service/user/UserServiceImpl.java @@ -620,7 +620,7 @@ public class UserServiceImpl implements UserService { } if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - this.checkActionState(action); + this.checkActionState(action, false); MergeAccountConfirmationEntity mergeAccountConfirmationEntity = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, action.getData()); if (mergeAccountConfirmationEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{action.getId(), MergeAccountConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -646,7 +646,7 @@ public class UserServiceImpl implements UserService { this.entityManager.reloadTenantFilters(); } if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - this.checkActionState(action); + this.checkActionState(action, false); MergeAccountConfirmationEntity mergeAccountConfirmationEntity = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, action.getData()); if (mergeAccountConfirmationEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{action.getId(), MergeAccountConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -857,7 +857,7 @@ public class UserServiceImpl implements UserService { } if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - this.checkActionState(action); + this.checkActionState(action, false); RemoveCredentialRequestEntity removeCredentialRequestEntity = this.xmlHandlingService.fromXmlSafe(RemoveCredentialRequestEntity.class, action.getData()); if (removeCredentialRequestEntity == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{action.getId(), RemoveCredentialRequestEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); @@ -903,12 +903,13 @@ public class UserServiceImpl implements UserService { this.keycloakService.addUserToTenantRoleGroup(subjectId, this.tenantScope.getDefaultTenantCode(), this.authorizationConfiguration.getAuthorizationProperties().getTenantUserRole()); } - private void checkActionState(ActionConfirmationEntity action) throws MyApplicationException { + private void checkActionState(ActionConfirmationEntity action, boolean isUserInvite) throws MyApplicationException { if (action.getStatus().equals(ActionConfirmationStatus.Accepted)){ - throw new MyApplicationException("Account is already confirmed!"); + if (isUserInvite) throw new MyValidationException(this.errors.getInviteUserAlreadyConfirmed().getCode(), this.errors.getInviteUserAlreadyConfirmed().getMessage()); + else throw new MyApplicationException("Account is already confirmed!"); } if (action.getExpiresAt().compareTo(Instant.now()) < 0){ - throw new MyApplicationException("Token has expired!"); + throw new MyValidationException(this.errors.getRequestHasExpired().getCode(), this.errors.getRequestHasExpired().getMessage()); } } @@ -998,7 +999,7 @@ public class UserServiceImpl implements UserService { } if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale())); - this.checkActionState(action); + this.checkActionState(action, true); UserInviteToTenantRequestEntity userInviteToTenantRequest = this.xmlHandlingService.fromXmlSafe(UserInviteToTenantRequestEntity.class, action.getData()); if (userInviteToTenantRequest == null) diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index 08b179d3c..c26f12d4c 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -112,4 +112,10 @@ error-thesaurus: message: Reference type exists prefillingSourceCodeExists: code: 141 - message: Prefilling source code exists \ No newline at end of file + message: Prefilling source code exists + inviteUserAlreadyConfirmed: + code: 142 + message: Invite user already confirmed + requestHasExpired: + code: 143 + message: Request has expired \ No newline at end of file diff --git a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts index ef94dfcb2..d09a578c8 100644 --- a/dmp-frontend/src/app/core/common/enum/respone-error-code.ts +++ b/dmp-frontend/src/app/core/common/enum/respone-error-code.ts @@ -39,6 +39,8 @@ export enum ResponseErrorCode { DmpBlueprintNewVersionAlreadyCreatedDraft = 139, ReferenceTypeCodeExists = 140, PrefillingSourceCodeExists = 141, + InviteUserAlreadyConfirmed = 142, + RequestHasExpired = 143, // Notification & Annotation Errors InvalidApiKey = 200, @@ -147,6 +149,10 @@ export class ResponseErrorCodeHelper { return language.instant("GENERAL.BACKEND-ERRORS.REFERENCE-TYPE-CODE-EXISTS"); case ResponseErrorCode.PrefillingSourceCodeExists: return language.instant("GENERAL.BACKEND-ERRORS.PREFILLING-SOURCE-CODE-EXISTS"); + case ResponseErrorCode.InviteUserAlreadyConfirmed: + return language.instant("GENERAL.BACKEND-ERRORS.INVITE-USER-ALREADY-CONFIRMED"); + case ResponseErrorCode.RequestHasExpired: + return language.instant("GENERAL.BACKEND-ERRORS.REQUEST-HAS-EXPIRED"); default: return language.instant("GENERAL.SNACK-BAR.NOT-FOUND"); } diff --git a/dmp-frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts b/dmp-frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts index c2d2c14f7..a57f65932 100644 --- a/dmp-frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/user-invite-confirmation/user-invite-confirmation.component.ts @@ -1,6 +1,7 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; +import { SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service'; import { RouterUtilsService } from '@app/core/services/router/router-utils.service'; import { UserService } from '@app/core/services/user/user.service'; import { BaseComponent } from '@common/base/base.component'; @@ -68,11 +69,12 @@ export class UserInviteConfirmation extends BaseComponent implements OnInit { let errorOverrides = new Map(); errorOverrides.set(302, this.language.instant('EMAIL-CONFIRMATION.EMAIL-FOUND')); errorOverrides.set(-1, this.language.instant('EMAIL-CONFIRMATION.EXPIRED-EMAIL')); - this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides) + this.httpErrorHandlingService.handleBackedRequestError(errorResponse, errorOverrides, SnackBarNotificationLevel.Error) const error: HttpError = this.httpErrorHandlingService.getError(errorResponse); if (error.statusCode === 302) { this.router.navigate([this.routerUtils.generateUrl('home')]); } + this.router.navigate([this.routerUtils.generateUrl('home')]); } } diff --git a/dmp-frontend/src/assets/i18n/baq.json b/dmp-frontend/src/assets/i18n/baq.json index d44f0d128..0f72330d4 100644 --- a/dmp-frontend/src/assets/i18n/baq.json +++ b/dmp-frontend/src/assets/i18n/baq.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Kontuz!", diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index 3dfe4a5c9..c229c060b 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warnung!", diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index da68dc2ba..5f351fd35 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warning!", diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index ebb72c47d..dad28c817 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atención!", diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index 97b12acf1..fe00e37eb 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Προσοχή!", diff --git a/dmp-frontend/src/assets/i18n/hr.json b/dmp-frontend/src/assets/i18n/hr.json index 81d2fb4b7..3e4cd6a5d 100644 --- a/dmp-frontend/src/assets/i18n/hr.json +++ b/dmp-frontend/src/assets/i18n/hr.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/dmp-frontend/src/assets/i18n/pl.json b/dmp-frontend/src/assets/i18n/pl.json index bc66ecdba..53e827c9a 100644 --- a/dmp-frontend/src/assets/i18n/pl.json +++ b/dmp-frontend/src/assets/i18n/pl.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Ostrzeżenie!", diff --git a/dmp-frontend/src/assets/i18n/pt.json b/dmp-frontend/src/assets/i18n/pt.json index 36033e17a..84b9f24c7 100644 --- a/dmp-frontend/src/assets/i18n/pt.json +++ b/dmp-frontend/src/assets/i18n/pt.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atenção!", diff --git a/dmp-frontend/src/assets/i18n/sk.json b/dmp-frontend/src/assets/i18n/sk.json index b4a470542..ef3e3de52 100644 --- a/dmp-frontend/src/assets/i18n/sk.json +++ b/dmp-frontend/src/assets/i18n/sk.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Upozornenie!", diff --git a/dmp-frontend/src/assets/i18n/sr.json b/dmp-frontend/src/assets/i18n/sr.json index 41b87816a..9c587b000 100644 --- a/dmp-frontend/src/assets/i18n/sr.json +++ b/dmp-frontend/src/assets/i18n/sr.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index da359a3cd..9bee37073 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -76,7 +76,9 @@ "DMP-BLUEPRINT-NEW-VERSION-ALREADY-CREATED-DRAFT": "You have already created a new draft version for this blueprint.", "REFERENCE-TYPE-CODE-EXISTS": "The reference type code you provided already exists. Please choose a different code.", "PREFILLING-SOURCE-CODE-EXISTS": "The prefilling source code you provided already exists. Please choose a different code.", - "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once" + "DUPLICATE-DMP-USER": "You can't invite authors with same role and plan section more than once", + "INVITE-USER-ALREADY-CONFIRMED": "Ιnvitation has already confirmed", + "REQUEST-HAS-EXPIRED": "Request has expired" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Uyarı!",