Simplify security model.
This commit is contained in:
@@ -207,8 +207,10 @@ public class MindmapController extends BaseController {
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void updateCollabs(@PathVariable int id, @NotNull @RequestBody RestCollaborationList restCollabs) throws CollaborationException {
|
||||
final MindMap mindMap = mindmapService.getMindmapById(id);
|
||||
|
||||
// Only owner can change collaborators...
|
||||
final User user = Utils.getUser();
|
||||
if (!mindMap.getOwner().equals(user)) {
|
||||
if (!mindMap.hasPermissions(user, CollaborationRole.OWNER)) {
|
||||
throw new IllegalArgumentException("No enough permissions");
|
||||
}
|
||||
|
||||
@@ -276,9 +278,9 @@ public class MindmapController extends BaseController {
|
||||
public void updatePublishState(@RequestBody String value, @PathVariable int id) throws WiseMappingException {
|
||||
|
||||
final MindMap mindMap = mindmapService.getMindmapById(id);
|
||||
final User user = Utils.getUser();
|
||||
|
||||
if (!mindMap.getOwner().equals(user)) {
|
||||
final User user = Utils.getUser();
|
||||
if (!!mindMap.hasPermissions(user, CollaborationRole.OWNER)) {
|
||||
throw new IllegalArgumentException("No enough to execute this operation");
|
||||
}
|
||||
|
||||
@@ -393,7 +395,7 @@ public class MindmapController extends BaseController {
|
||||
final MindMap clonedMap = mindMap.shallowClone();
|
||||
clonedMap.setTitle(restMindmap.getTitle());
|
||||
clonedMap.setDescription(restMindmap.getDescription());
|
||||
clonedMap.setOwner(user);
|
||||
clonedMap.setCreator(user);
|
||||
|
||||
// Add new mindmap ...
|
||||
mindmapService.addMindmap(clonedMap, user);
|
||||
|
@@ -36,7 +36,7 @@ public enum MindmapFilter {
|
||||
MY_MAPS("my_maps") {
|
||||
@Override
|
||||
boolean accept(@NotNull MindMap mindmap, @NotNull User user) {
|
||||
return mindmap.getOwner().equals(user);
|
||||
return mindmap.getCreator().equals(user);
|
||||
}
|
||||
},
|
||||
STARRED("starred") {
|
||||
|
@@ -5,7 +5,6 @@ import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import org.codehaus.jackson.annotate.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -75,7 +74,7 @@ public class RestMindmap {
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return mindmap.getCreator();
|
||||
return mindmap.getCreator().getEmail();
|
||||
}
|
||||
|
||||
public String getLastModifierUser() {
|
||||
@@ -132,7 +131,7 @@ public class RestMindmap {
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
final User owner = mindmap.getOwner();
|
||||
final User owner = mindmap.getCreator();
|
||||
return owner != null ? owner.getEmail() : null;
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
package com.wisemapping.rest.model;
|
||||
|
||||
|
||||
import com.wisemapping.model.Collaboration;
|
||||
import com.wisemapping.model.Collaborator;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import org.codehaus.jackson.annotate.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -69,16 +71,20 @@ public class RestMindmapInfo {
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return mindmap.getCreator();
|
||||
return mindmap.getCreator().getUsername();
|
||||
}
|
||||
|
||||
public String getOwnerEmail() {
|
||||
return mindmap.getOwner().getEmail();
|
||||
public void setCreator() {
|
||||
// Do nothing ...
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
final User owner = mindmap.getOwner();
|
||||
return owner.getUsername();
|
||||
public String getRole() {
|
||||
final Collaboration collaboration = mindmap.findCollaboration(Utils.getUser());
|
||||
return collaboration != null ? collaboration.getRole().getLabel() : "none";
|
||||
}
|
||||
|
||||
public void setRole() {
|
||||
// Do nothing ...
|
||||
}
|
||||
|
||||
public String getLastModifierUser() {
|
||||
@@ -117,7 +123,7 @@ public class RestMindmapInfo {
|
||||
mindmap.setDescription(description);
|
||||
}
|
||||
|
||||
public void setCreator(String creatorUser) {
|
||||
public void setCreator(String email) {
|
||||
|
||||
}
|
||||
|
||||
@@ -127,12 +133,6 @@ public class RestMindmapInfo {
|
||||
public void setLastModifierUser(String value) {
|
||||
}
|
||||
|
||||
public void setOwnerEmail(String value) {
|
||||
}
|
||||
|
||||
public void setOwner(String value) {
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public MindMap getDelegated() {
|
||||
return this.mindmap;
|
||||
|
@@ -78,7 +78,7 @@ public class RestUser {
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
public void setId(int id) {
|
||||
user.setId(id);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user