From b9cf5770125dc4d03623a1d477c9768c3cfd0e56 Mon Sep 17 00:00:00 2001 From: "CITE\\amentis" Date: Mon, 5 Aug 2024 12:25:41 +0300 Subject: [PATCH] add validation errors on user roles persist --- .../errorcode/ErrorThesaurusProperties.java | 20 +++++++++++++++++++ .../service/user/UserServiceImpl.java | 16 +++++++++++++-- .../web/src/main/resources/config/errors.yml | 8 +++++++- frontend/src/assets/i18n/de.json | 4 +++- frontend/src/assets/i18n/en.json | 4 +++- frontend/src/assets/i18n/es.json | 4 +++- frontend/src/assets/i18n/gr.json | 4 +++- frontend/src/assets/i18n/hr.json | 4 +++- frontend/src/assets/i18n/pl.json | 4 +++- frontend/src/assets/i18n/pt.json | 4 +++- frontend/src/assets/i18n/sk.json | 4 +++- frontend/src/assets/i18n/sr.json | 4 +++- frontend/src/assets/i18n/tr.json | 4 +++- 13 files changed, 71 insertions(+), 13 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 749785e11..bfb82d148 100644 --- a/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java +++ b/backend/core/src/main/java/org/opencdmp/errorcode/ErrorThesaurusProperties.java @@ -518,4 +518,24 @@ public class ErrorThesaurusProperties { public void setPlanBlueprintImportDraft(ErrorDescription planBlueprintImportDraft) { this.planBlueprintImportDraft = planBlueprintImportDraft; } + + private ErrorDescription missingTenantRole; + + public ErrorDescription getMissingTenantRole() { + return missingTenantRole; + } + + public void setMissingTenantRole(ErrorDescription missingTenantRole) { + this.missingTenantRole = missingTenantRole; + } + + private ErrorDescription missingGlobalRole; + + public ErrorDescription getMissingGlobalRole() { + return missingGlobalRole; + } + + public void setMissingGlobalRole(ErrorDescription missingGlobalRole) { + this.missingGlobalRole = missingGlobalRole; + } } 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 b1dd5a25c..7dc349fa8 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 @@ -334,8 +334,20 @@ public class UserServiceImpl implements UserService { public User patchRoles(UserRolePatchPersist model, FieldSet fields) throws InvalidApplicationException { logger.debug(new MapLogEntry("persisting data UserRole").And("model", model).And("fields", fields)); - if (!model.getHasTenantAdminMode()) this.authorizationService.authorizeForce(Permission.EditUser); - else this.authorizationService.authorizeForce(Permission.EditTenantUserRole); + if (!model.getHasTenantAdminMode()) { + this.authorizationService.authorizeForce(Permission.EditUser); + boolean foundGlobalRole = false; + boolean foundTenantRole = false; + for (String role: model.getRoles()) { + if (authorizationConfiguration.getAuthorizationProperties().getAllowedGlobalRoles().contains(role)) foundGlobalRole = true; + if (authorizationConfiguration.getAuthorizationProperties().getAllowedTenantRoles().contains(role)) foundTenantRole = true; + } + if (!foundGlobalRole && !foundTenantRole) throw new MyValidationException("Wrong role type"); + if (!foundGlobalRole) throw new MyValidationException(this.errors.getMissingGlobalRole().getCode(), this.errors.getMissingGlobalRole().getMessage()); + if (!foundTenantRole) throw new MyValidationException(this.errors.getMissingTenantRole().getCode(), this.errors.getMissingTenantRole().getMessage()); + } else { + this.authorizationService.authorizeForce(Permission.EditTenantUserRole); + } UserEntity data = this.entityManager.find(UserEntity.class, model.getId(), true); if (data == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), User.class.getSimpleName()}, LocaleContextHolder.getLocale())); diff --git a/backend/web/src/main/resources/config/errors.yml b/backend/web/src/main/resources/config/errors.yml index ea244243e..9991b3a18 100644 --- a/backend/web/src/main/resources/config/errors.yml +++ b/backend/web/src/main/resources/config/errors.yml @@ -160,4 +160,10 @@ error-thesaurus: message: Description template type is not finalised planBlueprintImportDraft: code: 157 - message: Plan blueprint is not finalised \ No newline at end of file + message: Plan blueprint is not finalised + missingTenantRole: + code: 158 + message: tenant role is missing + missingGlobalRole: + code: 159 + message: Global role is missing \ No newline at end of file diff --git a/frontend/src/assets/i18n/de.json b/frontend/src/assets/i18n/de.json index 84eb131aa..3b179ede6 100644 --- a/frontend/src/assets/i18n/de.json +++ b/frontend/src/assets/i18n/de.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warnung!", diff --git a/frontend/src/assets/i18n/en.json b/frontend/src/assets/i18n/en.json index f7280c308..75da9f530 100644 --- a/frontend/src/assets/i18n/en.json +++ b/frontend/src/assets/i18n/en.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Warning!", diff --git a/frontend/src/assets/i18n/es.json b/frontend/src/assets/i18n/es.json index 589c6ee4f..2a0486135 100644 --- a/frontend/src/assets/i18n/es.json +++ b/frontend/src/assets/i18n/es.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atención!", diff --git a/frontend/src/assets/i18n/gr.json b/frontend/src/assets/i18n/gr.json index 99f838d33..ec3ebe0c7 100644 --- a/frontend/src/assets/i18n/gr.json +++ b/frontend/src/assets/i18n/gr.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Προσοχή!", diff --git a/frontend/src/assets/i18n/hr.json b/frontend/src/assets/i18n/hr.json index 63a3441d9..8cfbbdb7d 100644 --- a/frontend/src/assets/i18n/hr.json +++ b/frontend/src/assets/i18n/hr.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/frontend/src/assets/i18n/pl.json b/frontend/src/assets/i18n/pl.json index 4eea955a3..bcbd9decf 100644 --- a/frontend/src/assets/i18n/pl.json +++ b/frontend/src/assets/i18n/pl.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Ostrzeżenie!", diff --git a/frontend/src/assets/i18n/pt.json b/frontend/src/assets/i18n/pt.json index 7a5742ac3..9c6cc03f0 100644 --- a/frontend/src/assets/i18n/pt.json +++ b/frontend/src/assets/i18n/pt.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Atenção!", diff --git a/frontend/src/assets/i18n/sk.json b/frontend/src/assets/i18n/sk.json index 7aa618d01..48f4e10a4 100644 --- a/frontend/src/assets/i18n/sk.json +++ b/frontend/src/assets/i18n/sk.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Upozornenie!", diff --git a/frontend/src/assets/i18n/sr.json b/frontend/src/assets/i18n/sr.json index 526e1960a..7b7bc894c 100644 --- a/frontend/src/assets/i18n/sr.json +++ b/frontend/src/assets/i18n/sr.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Oprez!", diff --git a/frontend/src/assets/i18n/tr.json b/frontend/src/assets/i18n/tr.json index f4755a27e..af2f70249 100644 --- a/frontend/src/assets/i18n/tr.json +++ b/frontend/src/assets/i18n/tr.json @@ -92,7 +92,9 @@ "BLUEPRINT-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "PLAN-DESCRIPTION-TEMPLATE-IMPORT-DRAFT": "Description template with code '{{descriptionTemplateLabel}}' is not finalized yet.", "DESCRIPTION-TEMPLATE-TYPE-IMPORT-DRAFT": "Description template type with code '{{descriptionTemplateTypeCode}}' is not finalized yet.", - "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet." + "PLAN-BLUEPRINT-IMPORT-DRAFT": "Plan Blueprint with code '{{planBlueprintCode}}' is not finalized yet.", + "MISSING-TENANT-ROLE": "Υou must also select a tenant role", + "MISSING-GLOBAL-ROLE": "Υou must also select a global role" }, "FORM-VALIDATION-DISPLAY-DIALOG": { "WARNING": "Uyarı!",