mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-24 23:17:56 +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 hasPermissions(@Nullable User user, int mapId, CollaborationRole allowedRole);
|
||||||
|
|
||||||
|
boolean isMindmapPublic(int mapId);
|
||||||
|
|
||||||
void revertChange(@NotNull Mindmap map, int historyId) throws WiseMappingException, IOException;
|
void revertChange(@NotNull Mindmap map, int historyId) throws WiseMappingException, IOException;
|
||||||
|
|
||||||
MindMapHistory findMindmapHistory(int id, int hid) throws WiseMappingException;
|
MindMapHistory findMindmapHistory(int id, int hid) throws WiseMappingException;
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright [2015] [wisemapping]
|
* Copyright [2015] [wisemapping]
|
||||||
*
|
*
|
||||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||||
* "powered by wisemapping" text requirement on every single page;
|
* "powered by wisemapping" text requirement on every single page;
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the license at
|
* You may obtain a copy of the license at
|
||||||
*
|
*
|
||||||
* http://www.wisemapping.org/license
|
* http://www.wisemapping.org/license
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.wisemapping.service;
|
package com.wisemapping.service;
|
||||||
|
|
||||||
@ -62,6 +62,12 @@ public class MindmapServiceImpl
|
|||||||
return hasPermissions(user, map, grantedRole);
|
return hasPermissions(user, map, grantedRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMindmapPublic(int mapId) {
|
||||||
|
final Mindmap map = mindmapManager.getMindmapById(mapId);
|
||||||
|
return map != null && map.isPublic();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermissions(@Nullable User user, @Nullable Mindmap map, @NotNull CollaborationRole role) {
|
public boolean hasPermissions(@Nullable User user, @Nullable Mindmap map, @NotNull CollaborationRole role) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
@ -70,7 +76,7 @@ public class MindmapServiceImpl
|
|||||||
result = true;
|
result = true;
|
||||||
} else if (user != null) {
|
} else if (user != null) {
|
||||||
final Optional<Collaboration> collaboration = map.findCollaboration(user);
|
final Optional<Collaboration> collaboration = map.findCollaboration(user);
|
||||||
if (collaboration .isPresent()) {
|
if (collaboration.isPresent()) {
|
||||||
result = collaboration
|
result = collaboration
|
||||||
.get()
|
.get()
|
||||||
.hasPermissions(role);
|
.hasPermissions(role);
|
||||||
|
@ -20,6 +20,7 @@ package com.wisemapping.webmvc;
|
|||||||
|
|
||||||
|
|
||||||
import com.wisemapping.exceptions.MapCouldNotFoundException;
|
import com.wisemapping.exceptions.MapCouldNotFoundException;
|
||||||
|
import com.wisemapping.exceptions.MapNonPublicException;
|
||||||
import com.wisemapping.exceptions.WiseMappingException;
|
import com.wisemapping.exceptions.WiseMappingException;
|
||||||
import com.wisemapping.model.CollaborationRole;
|
import com.wisemapping.model.CollaborationRole;
|
||||||
import com.wisemapping.model.Mindmap;
|
import com.wisemapping.model.Mindmap;
|
||||||
@ -107,7 +108,8 @@ public class MindmapController {
|
|||||||
public String showMindmapViewerPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
public String showMindmapViewerPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
||||||
final String result = showPrintPage(id, model);
|
final String result = showPrintPage(id, model);
|
||||||
model.addAttribute("readOnlyMode", true);
|
model.addAttribute("readOnlyMode", true);
|
||||||
return result; }
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
|
@RequestMapping(value = "maps/{id}/try", method = RequestMethod.GET)
|
||||||
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
public String showMindmapTryPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
||||||
@ -127,10 +129,13 @@ public class MindmapController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "maps/{id}/embed")
|
@RequestMapping(value = "maps/{id}/embed")
|
||||||
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException {
|
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) throws MapCouldNotFoundException, MapNonPublicException {
|
||||||
ModelAndView view;
|
if (!mindmapService.isMindmapPublic(id)) {
|
||||||
|
throw new MapNonPublicException("Map " + id + " is not public.");
|
||||||
|
}
|
||||||
|
|
||||||
final MindMapBean mindmap = findMindmapBean(id);
|
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);
|
view.addObject("zoom", zoom == null ? 1 : zoom);
|
||||||
final Locale locale = LocaleContextHolder.getLocale();
|
final Locale locale = LocaleContextHolder.getLocale();
|
||||||
view.addObject("locale", locale.toString().toLowerCase());
|
view.addObject("locale", locale.toString().toLowerCase());
|
||||||
@ -139,6 +144,9 @@ public class MindmapController {
|
|||||||
|
|
||||||
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
|
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
|
||||||
public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
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);
|
return this.showPrintPage(id, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +164,7 @@ public class MindmapController {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Mindmap findMindmap(int mapId) throws MapCouldNotFoundException {
|
private Mindmap findMindmap(int mapId) throws MapCouldNotFoundException {
|
||||||
final Mindmap result = mindmapService.findMindmapById((int) mapId);
|
final Mindmap result = mindmapService.findMindmapById(mapId);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw new MapCouldNotFoundException("Map could not be found " + mapId);
|
throw new MapCouldNotFoundException("Map could not be found " + mapId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user