Add embedded and public view compatibility.
Remove Utils method
This commit is contained in:
@@ -38,8 +38,8 @@ public class ChangePasswordController
|
||||
BindException errors)
|
||||
throws ServletException {
|
||||
final ChangePasswordBean bean = (ChangePasswordBean) command;
|
||||
// Reload user only in case of beeing necessary...
|
||||
final User model = Utils.getUser(request);
|
||||
// Reload user only in case of being necessary...
|
||||
final User model = Utils.getUser();
|
||||
|
||||
final UserService userService = this.getUserService();
|
||||
final User user = userService.reloadUser(model);
|
||||
|
@@ -34,7 +34,7 @@ public class EditProfileController extends BaseSimpleFormController {
|
||||
|
||||
|
||||
protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {
|
||||
final User model = Utils.getUser(httpServletRequest);
|
||||
final User model = Utils.getUser();
|
||||
return new UserBean(model);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class EditProfileController extends BaseSimpleFormController {
|
||||
final UserService userService = this.getUserService();
|
||||
|
||||
// Reload user only in case of beeing necessary...
|
||||
final User model = Utils.getUser(request);
|
||||
final User model = Utils.getUser();
|
||||
final User user = userService.reloadUser(model);
|
||||
|
||||
user.setFirstname(bean.getFirstname());
|
||||
|
@@ -38,7 +38,7 @@ public class TagsController
|
||||
protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {
|
||||
|
||||
final MindMap mindmap = null;
|
||||
final User user = Utils.getUser(httpServletRequest);
|
||||
final User user = Utils.getUser();
|
||||
final User dbUser = getUserService().getUserBy(user.getId());
|
||||
|
||||
final TagBean tagBean = new TagBean();
|
||||
|
@@ -62,7 +62,6 @@ final public class NotificationService {
|
||||
model.put("message", message);
|
||||
model.put("supportEmail", mailer.getSupportEmail());
|
||||
|
||||
|
||||
mailer.sendEmail(formMail, collabEmail, subject, model, "newCollaboration.vm");
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
|
@@ -21,7 +21,7 @@ package com.wisemapping.model;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CollaborationProperties {
|
||||
private static final String DEFAULT_JSON_PROPERTIES = "{zoom:0.8}";
|
||||
public static final String DEFAULT_JSON_PROPERTIES = "{zoom:0.8}";
|
||||
private int id;
|
||||
private boolean starred;
|
||||
private String mindmapProperties;
|
||||
|
@@ -35,8 +35,8 @@ public class LoginController {
|
||||
private String driver;
|
||||
|
||||
@RequestMapping(value = "login", method = RequestMethod.GET)
|
||||
protected ModelAndView showLoginPage(HttpServletRequest request) {
|
||||
final User user = Utils.getUser(request);
|
||||
protected ModelAndView showLoginPage() {
|
||||
final User user = Utils.getUser(false);
|
||||
ModelAndView result;
|
||||
if (user != null) {
|
||||
result = new ModelAndView("forward:/c/maps/");
|
||||
|
@@ -29,6 +29,7 @@ import com.wisemapping.view.MindMapBean;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -40,10 +41,15 @@ import java.util.List;
|
||||
@Controller
|
||||
public class MindmapController {
|
||||
|
||||
|
||||
@Qualifier("mindmapService")
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
|
||||
@Value("${site.baseurl}")
|
||||
String siteBaseUrl;
|
||||
|
||||
|
||||
@RequestMapping(value = "maps/import")
|
||||
public String showImportPage() {
|
||||
return "mindmapImport";
|
||||
@@ -58,7 +64,7 @@ public class MindmapController {
|
||||
|
||||
@RequestMapping(value = "maps/{id}/print")
|
||||
public String showPrintPage(@PathVariable int id, @NotNull Model model) {
|
||||
final MindMap mindmap = findMindmap(id);
|
||||
final MindMapBean mindmap = findMindmapBean(id);
|
||||
model.addAttribute("mindmap", mindmap);
|
||||
return "mindmapPrint";
|
||||
}
|
||||
@@ -93,6 +99,7 @@ public class MindmapController {
|
||||
public String showPublishPage(@PathVariable int id, @NotNull Model model) {
|
||||
final MindMap mindmap = findMindmap(id);
|
||||
model.addAttribute("mindmap", mindmap);
|
||||
model.addAttribute("baseUrl", siteBaseUrl);
|
||||
return "mindmapPublish";
|
||||
}
|
||||
|
||||
@@ -155,15 +162,30 @@ public class MindmapController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/embed")
|
||||
public ModelAndView embeddedView(@PathVariable int id, @RequestParam(required = false) Float zoom) {
|
||||
public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) {
|
||||
ModelAndView view;
|
||||
final MindMap mindmap = mindmapService.findMindmapById(id);
|
||||
final MindMapBean mindmap = findMindmapBean(id);
|
||||
view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap);
|
||||
view.addObject("user", Utils.getUser());
|
||||
view.addObject("zoom", zoom == null ? 1 : zoom);
|
||||
return view;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET)
|
||||
public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException {
|
||||
return this.showPrintPage(id, model);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@RequestMapping(value = "publicView", method = RequestMethod.GET)
|
||||
public String showPublicViewPageLegacy(@RequestParam(required = true) int mapId, @NotNull Model model) throws WiseMappingException {
|
||||
return "redirect:maps/" + mapId + "/public";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@RequestMapping(value = "embeddedView", method = RequestMethod.GET)
|
||||
public String showPublicViewLegacyPage(@RequestParam(required = true) int mapId, @RequestParam(required = false) int zoom, @NotNull Model model) throws WiseMappingException {
|
||||
return "redirect:maps/" + mapId + "/embed?zoom=" + zoom;
|
||||
}
|
||||
|
||||
private MindMap findMindmap(long mapId) {
|
||||
final MindMap mindmap = mindmapService.findMindmapById((int) mapId);
|
||||
|
@@ -293,7 +293,7 @@ public class MindmapController extends BaseController {
|
||||
final MindMap mindMap = mindmapService.findMindmapById(id);
|
||||
|
||||
final User user = Utils.getUser();
|
||||
if (!!mindMap.hasPermissions(user, CollaborationRole.OWNER)) {
|
||||
if (!mindMap.hasPermissions(user, CollaborationRole.OWNER)) {
|
||||
throw new IllegalArgumentException("No enough to execute this operation");
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,7 @@ package com.wisemapping.security;
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@@ -30,19 +31,14 @@ final public class Utils {
|
||||
private Utils() {
|
||||
}
|
||||
|
||||
public static User getUser(@NotNull final HttpServletRequest request) {
|
||||
|
||||
final AbstractAuthenticationToken token = (AbstractAuthenticationToken) request.getUserPrincipal();
|
||||
User result = null;
|
||||
if (token != null) {
|
||||
final UserDetails userDetails = (UserDetails) token.getPrincipal();
|
||||
result = userDetails.getUser();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"ConstantConditions"})
|
||||
@NotNull
|
||||
public static User getUser() {
|
||||
return getUser(false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static User getUser(boolean forceCheck) {
|
||||
User result = null;
|
||||
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.getDetails() != null)
|
||||
@@ -53,7 +49,7 @@ final public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
if(result==null){
|
||||
if(result==null && forceCheck){
|
||||
throw new IllegalStateException("User could not be retrieved");
|
||||
}
|
||||
return result;
|
||||
|
@@ -24,6 +24,7 @@ import com.wisemapping.model.CollaborationRole;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ViewBaseSecurityAdvise
|
||||
extends BaseSecurityAdvice
|
||||
@@ -34,11 +35,11 @@ public class ViewBaseSecurityAdvise
|
||||
return methodInvocation.proceed();
|
||||
}
|
||||
|
||||
protected boolean isAllowed(@NotNull User user, MindMap map) {
|
||||
protected boolean isAllowed(@Nullable User user, MindMap map) {
|
||||
return getMindmapService().hasPermissions(user, map, CollaborationRole.VIEWER);
|
||||
}
|
||||
|
||||
protected boolean isAllowed(@NotNull User user, int mapId) {
|
||||
protected boolean isAllowed(@Nullable User user, int mapId) {
|
||||
return getMindmapService().hasPermissions(user, mapId, CollaborationRole.VIEWER);
|
||||
}
|
||||
}
|
||||
|
@@ -125,8 +125,15 @@ public class MindMapBean {
|
||||
}
|
||||
|
||||
public String getProperties() throws WiseMappingException {
|
||||
final CollaborationProperties collaboration = this.mindmap.findCollaborationProperties(collaborator);
|
||||
return collaboration.getMindmapProperties();
|
||||
String result;
|
||||
if (collaborator != null) {
|
||||
final CollaborationProperties properties = this.mindmap.findCollaborationProperties(collaborator);
|
||||
result = properties.getMindmapProperties();
|
||||
} else {
|
||||
// It must be public view ...
|
||||
result = CollaborationProperties.DEFAULT_JSON_PROPERTIES;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public User getCreator() {
|
||||
|
Reference in New Issue
Block a user