mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-12-22 19:33:48 +01:00
Improve error handling in not public maps.
This commit is contained in:
parent
820e268e3e
commit
0cd62f612b
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright [2015] [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 MapNonPublicException
|
||||
extends ClientException {
|
||||
public static final String MSG_KEY = "ACCESS_HAS_BEEN_REVOKED";
|
||||
|
||||
public MapNonPublicException(@NotNull String msg) {
|
||||
super(msg, Severity.FATAL);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getMsgBundleKey() {
|
||||
return MSG_KEY;
|
||||
}
|
||||
|
||||
}
|
@ -57,6 +57,8 @@ public interface MindmapService {
|
||||
|
||||
boolean hasPermissions(@Nullable User user, int mapId, CollaborationRole allowedRole);
|
||||
|
||||
boolean isMindmapPublic(int mapId);
|
||||
|
||||
void revertChange(@NotNull Mindmap map, int historyId) throws WiseMappingException, IOException;
|
||||
|
||||
MindMapHistory findMindmapHistory(int id, int hid) throws WiseMappingException;
|
||||
|
@ -1,20 +1,20 @@
|
||||
/*
|
||||
* Copyright [2015] [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.
|
||||
*/
|
||||
* Copyright [2015] [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.service;
|
||||
|
||||
@ -62,6 +62,12 @@ public class MindmapServiceImpl
|
||||
return hasPermissions(user, map, grantedRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMindmapPublic(int mapId) {
|
||||
final Mindmap map = mindmapManager.getMindmapById(mapId);
|
||||
return map != null && map.isPublic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissions(@Nullable User user, @Nullable Mindmap map, @NotNull CollaborationRole role) {
|
||||
boolean result = false;
|
||||
@ -70,7 +76,7 @@ public class MindmapServiceImpl
|
||||
result = true;
|
||||
} else if (user != null) {
|
||||
final Optional<Collaboration> collaboration = map.findCollaboration(user);
|
||||
if (collaboration .isPresent()) {
|
||||
if (collaboration.isPresent()) {
|
||||
result = collaboration
|
||||
.get()
|
||||
.hasPermissions(role);
|
||||
|
@ -20,6 +20,7 @@ package com.wisemapping.webmvc;
|
||||
|
||||
|
||||
import com.wisemapping.exceptions.MapCouldNotFoundException;
|
||||
import com.wisemapping.exceptions.MapNonPublicException;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.CollaborationRole;
|
||||
import com.wisemapping.model.Mindmap;
|
||||
@ -107,7 +108,8 @@ public class MindmapController {
|
||||
public String showMindmapViewerPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
||||
final String result = showPrintPage(id, model);
|
||||
model.addAttribute("readOnlyMode", true);
|
||||
return result; }
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
|
||||
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
||||
@ -127,10 +129,13 @@ public class MindmapController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/embed")
|
||||
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException {
|
||||
ModelAndView view;
|
||||
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException, MapNonPublicException {
|
||||
if (!mindmapService.isMindmapPublic(id)) {
|
||||
throw new MapNonPublicException("Map " + id + " is not public.");
|
||||
}
|
||||
|
||||
final MindMapBean mindmap = findMindmapBean(id);
|
||||
view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap);
|
||||
final ModelAndView view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap);
|
||||
view.addObject("zoom", zoom == null ? 1 : zoom);
|
||||
final Locale locale = LocaleContextHolder.getLocale();
|
||||
view.addObject("locale", locale.toString().toLowerCase());
|
||||
@ -139,6 +144,9 @@ public class MindmapController {
|
||||
|
||||
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
|
||||
public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
||||
if (!mindmapService.isMindmapPublic(id)) {
|
||||
throw new MapNonPublicException("Map " + id + " is not public.");
|
||||
}
|
||||
return this.showPrintPage(id, model);
|
||||
}
|
||||
|
||||
@ -156,7 +164,7 @@ public class MindmapController {
|
||||
|
||||
@NotNull
|
||||
private Mindmap findMindmap(int mapId) throws MapCouldNotFoundException {
|
||||
final Mindmap result = mindmapService.findMindmapById((int) mapId);
|
||||
final Mindmap result = mindmapService.findMindmapById(mapId);
|
||||
if (result == null) {
|
||||
throw new MapCouldNotFoundException("Map could not be found " + mapId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user