Simplify security model.
This commit is contained in:
@@ -38,7 +38,7 @@ public class Collaboration {
|
||||
|
||||
// Guarantee referential integrity
|
||||
mindmap.addCollaboration(this);
|
||||
collaborator.addMindmapUser(this);
|
||||
collaborator.addCollaboration(this);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
@@ -65,18 +65,6 @@ public class Collaboration {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public boolean isOwner() {
|
||||
return getRole() == CollaborationRole.OWNER;
|
||||
}
|
||||
|
||||
public boolean isEditor() {
|
||||
return getRole() == CollaborationRole.EDITOR;
|
||||
}
|
||||
|
||||
public boolean isViewer() {
|
||||
return getRole() == CollaborationRole.VIEWER;
|
||||
}
|
||||
|
||||
public MindMap getMindMap() {
|
||||
return mindMap;
|
||||
}
|
||||
@@ -101,4 +89,9 @@ public class Collaboration {
|
||||
public void setCollaborationProperties(@NotNull CollaborationProperties collaborationProperties) {
|
||||
this.collaborationProperties = collaborationProperties;
|
||||
}
|
||||
|
||||
public boolean hasPermissions(@NotNull CollaborationRole role) {
|
||||
return this.getRole().ordinal() <= role.ordinal();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
|
||||
package com.wisemapping.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CollaborationProperties {
|
||||
private long id;
|
||||
private int id;
|
||||
private boolean starred;
|
||||
|
||||
public CollaborationProperties(){
|
||||
@@ -36,11 +34,11 @@ public class CollaborationProperties {
|
||||
this.starred = starred;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,27 +19,9 @@
|
||||
package com.wisemapping.model;
|
||||
|
||||
public enum CollaborationRole {
|
||||
OWNER(true, true, true), EDITOR(true, true, false), VIEWER(false, true, false);
|
||||
OWNER, EDITOR, VIEWER;
|
||||
|
||||
private final boolean hasEditPermission;
|
||||
private final boolean hasViewPermission;
|
||||
private final boolean hasDeletePermission;
|
||||
|
||||
private CollaborationRole(boolean hasEditPermission, boolean hasViewPermission, boolean hasDeletePermission) {
|
||||
this.hasEditPermission = hasEditPermission;
|
||||
this.hasViewPermission = hasViewPermission;
|
||||
this.hasDeletePermission = hasDeletePermission;
|
||||
}
|
||||
|
||||
public boolean hasEditPermission() {
|
||||
return hasEditPermission;
|
||||
}
|
||||
|
||||
public boolean hasViewPermission() {
|
||||
return hasViewPermission;
|
||||
}
|
||||
|
||||
public boolean hasDeletePermission() {
|
||||
return hasDeletePermission;
|
||||
public String getLabel(){
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package com.wisemapping.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
@@ -40,9 +42,9 @@ public class Collaborator {
|
||||
this.collaborations = collaborations;
|
||||
}
|
||||
|
||||
public void addMindmapUser(Collaboration mindmaUser)
|
||||
public void addCollaboration(@NotNull Collaboration collaboration)
|
||||
{
|
||||
collaborations.add(mindmaUser);
|
||||
collaborations.add(collaboration);
|
||||
}
|
||||
|
||||
public Set<Collaboration> getCollaborations()
|
||||
|
||||
@@ -36,7 +36,6 @@ public class MindMap {
|
||||
//~ Instance fields ......................................................................................
|
||||
private int id;
|
||||
private Calendar creationTime;
|
||||
private String creator;
|
||||
private String description;
|
||||
|
||||
private boolean isPublic;
|
||||
@@ -45,7 +44,7 @@ public class MindMap {
|
||||
|
||||
private Set<Collaboration> collaborations = new HashSet<Collaboration>();
|
||||
|
||||
private User owner;
|
||||
private User creator;
|
||||
private String properties;
|
||||
private String tags;
|
||||
private String title;
|
||||
@@ -169,14 +168,6 @@ public class MindMap {
|
||||
this.lastModifierUser = lastModifierUser;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setCreator(String creatorUser) {
|
||||
this.creator = creatorUser;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -229,15 +220,15 @@ public class MindMap {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public void setOwner(@NotNull User owner) {
|
||||
if (owner == null) {
|
||||
public void setCreator(@NotNull User creator) {
|
||||
if (creator == null) {
|
||||
throw new IllegalArgumentException("Owner can not be null");
|
||||
}
|
||||
this.owner = owner;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
public User getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
private CollaborationProperties findUserProperty(@NotNull Collaborator collaborator) {
|
||||
@@ -251,7 +242,7 @@ public class MindMap {
|
||||
}
|
||||
|
||||
final Collaboration collaboration = this.findCollaboration(collaborator);
|
||||
if(collaboration==null){
|
||||
if (collaboration == null) {
|
||||
throw new WiseMappingException("User is not collaborator");
|
||||
}
|
||||
|
||||
@@ -286,4 +277,14 @@ public class MindMap {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean hasPermissions(@NotNull Collaborator collaborator, @NotNull CollaborationRole role) {
|
||||
final Collaboration collaboration = this.findCollaboration(collaborator);
|
||||
boolean result = false;
|
||||
if (collaboration != null) {
|
||||
result = collaboration.hasPermissions(role);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user