From 51cfa961e6be48dc9a8b24306ca7b54401c0b9a0 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 14 Apr 2022 16:37:18 -0300 Subject: [PATCH] Improve handling change of ownner exception. --- .../exceptions/CollabChangeException.java | 39 +++++++++++++++++++ .../wisemapping/rest/MindmapController.java | 13 ++++--- .../src/main/resources/messages_de.properties | 3 +- .../src/main/resources/messages_en.properties | 3 +- .../src/main/resources/messages_es.properties | 3 +- .../src/main/resources/messages_fr.properties | 3 +- .../src/main/resources/messages_ru.properties | 3 +- .../src/main/resources/messages_zh.properties | 3 +- 8 files changed, 58 insertions(+), 12 deletions(-) create mode 100755 wise-webapp/src/main/java/com/wisemapping/exceptions/CollabChangeException.java diff --git a/wise-webapp/src/main/java/com/wisemapping/exceptions/CollabChangeException.java b/wise-webapp/src/main/java/com/wisemapping/exceptions/CollabChangeException.java new file mode 100755 index 00000000..ee792603 --- /dev/null +++ b/wise-webapp/src/main/java/com/wisemapping/exceptions/CollabChangeException.java @@ -0,0 +1,39 @@ +/* +* Copyright [2022] [wisemapping] +* +* Licensed under WiseMapping Public License, Version 1.0 (the "License"). +* It is basically the Apache License, Version 2.0 (the "License") plus the +* "powered by wisemapping" text requirement on every single page; +* you may not use this file except in compliance with the License. +* You may obtain a copy of the license at +* +* http://www.wisemapping.org/license +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.wisemapping.exceptions; + +import org.jetbrains.annotations.NotNull; + +public class CollabChangeException + extends ClientException +{ + + private static final String MSG_KEY = "OWNER_ROLE_CAN_NOT_BE_CHANGED"; + + public CollabChangeException(@NotNull String email) + { + super("Collab email can not be change. " + email + " is the the owner.",Severity.WARNING); + } + + @NotNull + @Override + protected String getMsgBundleKey() { + return MSG_KEY; + } +} diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index 6103a51d..79f911cb 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -299,7 +299,7 @@ public class MindmapController extends BaseController { @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs/", consumes = {"application/json"}, produces = {"application/json"}) @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void addCollab(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException, MapCouldNotFoundException, AccessDeniedSecurityException, InvalidEmailException, TooManyInactiveAccountsExceptions { + public void addCollab(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException, MapCouldNotFoundException, AccessDeniedSecurityException, InvalidEmailException, TooManyInactiveAccountsExceptions, CollabChangeException { final Mindmap mindMap = findMindmapById(id); // Only owner can change collaborators... @@ -345,7 +345,6 @@ public class MindmapController extends BaseController { // Great, let's add all the collabs again ... for (RestCollaboration restCollab : restCollabs.getCollaborations()) { - final Collaboration collaboration = mindMap.findCollaboration(restCollab.getEmail()); // Validate role format ... String roleStr = restCollab.getRole(); if (roleStr == null) { @@ -353,12 +352,14 @@ public class MindmapController extends BaseController { } // Is owner ? - final CollaborationRole role = CollaborationRole.valueOf(roleStr.toUpperCase()); - if (role == CollaborationRole.OWNER) { - throw new IllegalArgumentException("Owner can not be added as part of the collaboration list."); + final String email = restCollab.getEmail(); + final Collaboration collaboration = mindMap.findCollaboration(email); + if (collaboration != null && collaboration.getRole() == CollaborationRole.OWNER) { + throw new CollabChangeException(email); } - mindmapService.addCollaboration(mindMap, restCollab.getEmail(), role, restCollabs.getMessage()); + final CollaborationRole role = CollaborationRole.valueOf(roleStr.toUpperCase()); + mindmapService.addCollaboration(mindMap, email, role, restCollabs.getMessage()); } } diff --git a/wise-webapp/src/main/resources/messages_de.properties b/wise-webapp/src/main/resources/messages_de.properties index 1e9cd4f8..5ab06621 100644 --- a/wise-webapp/src/main/resources/messages_de.properties +++ b/wise-webapp/src/main/resources/messages_de.properties @@ -67,4 +67,5 @@ INVALID_MINDMAP_FORMAT=Ungültiges Mindmap-Format. TOO_BIG_MINDMAP=Sie haben das Limit von 5000 Themen in einer Mindmap erreicht. SHARE_MAP.EMAIL_SUBJECT={0} hat eine Mindmap mit Ihnen geteilt EMAIL.DO_NOT_REPLAY=Wichtig: Antworten Sie nicht auf diese E-Mail. Wenn Sie weitere Hilfe benötigen oder Bedenken bezüglich Ihres Kontos haben, kontaktieren Sie uns hier. -EMAIL.GREETINGS=Hallo \ No newline at end of file +EMAIL.GREETINGS=Hallo +OWNER_ROLE_CAN_NOT_BE_CHANGED=Owner role can not be change. Please, remove owner from the change list. \ No newline at end of file diff --git a/wise-webapp/src/main/resources/messages_en.properties b/wise-webapp/src/main/resources/messages_en.properties index 36de1159..ef67f540 100644 --- a/wise-webapp/src/main/resources/messages_en.properties +++ b/wise-webapp/src/main/resources/messages_en.properties @@ -69,4 +69,5 @@ PASSWORD_CHANGED.EMAIL_BODY=

This is only an notification that your password h SHARE_MAP.EMAIL_SUBJECT={0} has shared a mind map with you EMAIL.DO_NOT_REPLAY=Important: Do not reply this email. If you need further help or have any concerns regarding your account, contact us to here. EMAIL.GREETINGS=Hi -TOO_MANY_INACTIVE_ACCOUNTS=You have shared your mindmaps to more than 20 user that have not registered yet. Please, remove inactive accounts or ask them to register. \ No newline at end of file +TOO_MANY_INACTIVE_ACCOUNTS=You have shared your mindmaps to more than 20 user that have not registered yet. Please, remove inactive accounts or ask them to register. +OWNER_ROLE_CAN_NOT_BE_CHANGED=Owner role can not be change. Please, remove owner from the change list. \ No newline at end of file diff --git a/wise-webapp/src/main/resources/messages_es.properties b/wise-webapp/src/main/resources/messages_es.properties index 2bf83288..16512ea4 100644 --- a/wise-webapp/src/main/resources/messages_es.properties +++ b/wise-webapp/src/main/resources/messages_es.properties @@ -67,4 +67,5 @@ PASSWORD_CHANGED.EMAIL_TITLE=Su contraseña ha sido cambiada con éxito PASSWORD_CHANGED.EMAIL_BODY=

Esto es solo una notificación de que su contraseña ha sido cambiada. No se requiere ninguna otra acción.

SHARE_MAP.EMAIL_SUBJECT={0} te ha compartido un mapa mental EMAIL.DO_NOT_REPLAY=Importante: No responda este correo electrónico. Si necesita más ayuda o tiene alguna inquietud con respecto a su cuenta, comuníquese con nosotros a aquí. -EMAIL.GREETINGS=Hola \ No newline at end of file +EMAIL.GREETINGS=Hola +OWNER_ROLE_CAN_NOT_BE_CHANGED=Owner role can not be change. Please, remove owner from the change list. \ No newline at end of file diff --git a/wise-webapp/src/main/resources/messages_fr.properties b/wise-webapp/src/main/resources/messages_fr.properties index a4c4be8c..3411d942 100644 --- a/wise-webapp/src/main/resources/messages_fr.properties +++ b/wise-webapp/src/main/resources/messages_fr.properties @@ -67,4 +67,5 @@ INVALID_MINDMAP_FORMAT=Format de carte mentale non valide. TOO_BIG_MINDMAP=Vous avez atteint la limite de 5000 sujets dans une carte mentale. SHARE_MAP.EMAIL_SUBJECT={0} a partagé une carte mentale avec vous EMAIL.DO_NOT_REPLAY=Important : Ne répondez pas à cet e-mail. Si vous avez besoin d'aide supplémentaire ou si vous avez des inquiétudes concernant votre compte, contactez-nous ici. -EMAIL.GREETINGS=Salut \ No newline at end of file +EMAIL.GREETINGS=Salut +OWNER_ROLE_CAN_NOT_BE_CHANGED=Owner role can not be change. Please, remove owner from the change list. \ No newline at end of file diff --git a/wise-webapp/src/main/resources/messages_ru.properties b/wise-webapp/src/main/resources/messages_ru.properties index 1cb6340a..5bd75a47 100644 --- a/wise-webapp/src/main/resources/messages_ru.properties +++ b/wise-webapp/src/main/resources/messages_ru.properties @@ -61,4 +61,5 @@ REGISTRATION.EMAIL_TITLE=Ваша учетная запись успешно с REGISTRATION.EMAIL_BODY=

Благодарим вас за интерес к WiseMapping. Нажмите здесь, чтобы начать создавать и публиковать новые интеллект-карты. Если у вас есть какие-либо отзывы или идеи, отправьте нам электронное письмо по адресу feedback@wisemapping.com. Мы будем рады услышать от вас.

SHARE_MAP.EMAIL_SUBJECT={0} has shared a mindmap with you EMAIL.DO_NOT_REPLAY=Important: Do not reply this email. If you need further help or have any concerns regarding your account, contact us to here. -EMAIL.GREETINGS=Hi \ No newline at end of file +EMAIL.GREETINGS=Hi +OWNER_ROLE_CAN_NOT_BE_CHANGED=Owner role can not be change. Please, remove owner from the change list. \ No newline at end of file diff --git a/wise-webapp/src/main/resources/messages_zh.properties b/wise-webapp/src/main/resources/messages_zh.properties index c89b447c..c3b44d80 100644 --- a/wise-webapp/src/main/resources/messages_zh.properties +++ b/wise-webapp/src/main/resources/messages_zh.properties @@ -67,4 +67,5 @@ PASSWORD_CHANGED.EMAIL_TITLE=你已经成功更改密码 PASSWORD_CHANGED.EMAIL_BODY=

这只是您的密码已更改的通知。无需进一步操作。

SHARE_MAP.EMAIL_SUBJECT={0} 与您分享了一张思维导图 EMAIL.DO_NOT_REPLAY=Important: Do not reply this email. If you need further help or have any concerns regarding your account, contact us to here. -EMAIL.GREETINGS=Hi \ No newline at end of file +EMAIL.GREETINGS=Hi +OWNER_ROLE_CAN_NOT_BE_CHANGED=Owner role can not be change. Please, remove owner from the change list. \ No newline at end of file