Improve handling change of ownner exception.

This commit is contained in:
Paulo Gustavo Veiga
2022-04-14 16:37:18 -03:00
parent 1cabb59b2f
commit 51cfa961e6
8 changed files with 58 additions and 12 deletions

View File

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

View File

@@ -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());
}
}