mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 22:27:55 +01:00
Fix collaboration equal issue.
This commit is contained in:
parent
2861a7b5f9
commit
16e59a0879
@ -19,11 +19,12 @@
|
|||||||
package com.wisemapping.model;
|
package com.wisemapping.model;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class Collaborator implements Serializable {
|
public class Collaborator implements Serializable {
|
||||||
@ -32,24 +33,22 @@ public class Collaborator implements Serializable {
|
|||||||
private Calendar creationDate;
|
private Calendar creationDate;
|
||||||
private Set<Collaboration> collaborations = new HashSet<Collaboration>();
|
private Set<Collaboration> collaborations = new HashSet<Collaboration>();
|
||||||
|
|
||||||
public Collaborator() {}
|
public Collaborator() {
|
||||||
|
}
|
||||||
|
|
||||||
public Collaborator(Set<Collaboration> collaborations) {
|
public Collaborator(Set<Collaboration> collaborations) {
|
||||||
this.collaborations = collaborations;
|
this.collaborations = collaborations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCollaborations(Set<Collaboration> collaborations)
|
public void setCollaborations(Set<Collaboration> collaborations) {
|
||||||
{
|
|
||||||
this.collaborations = collaborations;
|
this.collaborations = collaborations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCollaboration(@NotNull Collaboration collaboration)
|
public void addCollaboration(@NotNull Collaboration collaboration) {
|
||||||
{
|
|
||||||
collaborations.add(collaboration);
|
collaborations.add(collaboration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Collaboration> getCollaborations()
|
public Set<Collaboration> getCollaborations() {
|
||||||
{
|
|
||||||
return collaborations;
|
return collaborations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,4 +95,17 @@ public class Collaborator implements Serializable {
|
|||||||
result = 31 * result + (email != null ? email.hashCode() : 0);
|
result = 31 * result + (email != null ? email.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean equalCollab(@Nullable Collaborator that) {
|
||||||
|
if (this == that) return true;
|
||||||
|
if (that == null) return false;
|
||||||
|
|
||||||
|
if (id != that.id) return false;
|
||||||
|
if (email != null ? !email.equals(that.email) : that.email != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -111,7 +110,14 @@ public class Mindmap {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Collaboration findCollaboration(@NotNull Collaborator collaborator) {
|
public Collaboration findCollaboration(@NotNull Collaborator collaborator) {
|
||||||
return this.findCollaboration(collaborator.getEmail());
|
Collaboration result = null;
|
||||||
|
for (Collaboration collaboration : collaborations) {
|
||||||
|
if (collaboration.getCollaborator().equalCollab(collaborator)) {
|
||||||
|
result = collaboration;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -183,7 +183,7 @@ public class MindmapController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final LockInfo lockInfo = lockManager.getLockInfo(mindmap);
|
final LockInfo lockInfo = lockManager.getLockInfo(mindmap);
|
||||||
if (lockInfo.getUser().equals(user)) {
|
if (lockInfo.getUser().equalCollab(user)) {
|
||||||
final boolean outdated = mindmap.getLastModificationTime().getTimeInMillis() > timestamp;
|
final boolean outdated = mindmap.getLastModificationTime().getTimeInMillis() > timestamp;
|
||||||
if (lockInfo.getSession() == session) {
|
if (lockInfo.getSession() == session) {
|
||||||
// Timestamp might not be returned to the client. This try to cover this case, ignoring the client timestamp check.
|
// Timestamp might not be returned to the client. This try to cover this case, ignoring the client timestamp check.
|
||||||
|
@ -23,7 +23,6 @@ import com.wisemapping.model.User;
|
|||||||
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
import org.codehaus.jackson.annotate.JsonAutoDetect;
|
||||||
import org.codehaus.jackson.annotate.JsonIgnore;
|
import org.codehaus.jackson.annotate.JsonIgnore;
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
||||||
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
@ -125,7 +124,7 @@ public class RestUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RestUser restUser = (RestUser) o;
|
RestUser restUser = (RestUser) o;
|
||||||
return this.getDelegated().equals(restUser.getDelegated());
|
return this.getDelegated().equalCollab(restUser.getDelegated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,7 +41,7 @@ public abstract class BaseSecurityAdvice {
|
|||||||
isAllowed = isAllowed(user, ((Integer) argument));
|
isAllowed = isAllowed(user, ((Integer) argument));
|
||||||
} else if (argument instanceof Collaborator) {
|
} else if (argument instanceof Collaborator) {
|
||||||
// Read operation find on the user are allowed ...
|
// Read operation find on the user are allowed ...
|
||||||
isAllowed = user.equals(argument);
|
isAllowed = user.equalCollab((Collaborator) argument);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Argument " + argument);
|
throw new IllegalArgumentException("Argument " + argument);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ class LockManagerImpl implements LockManager {
|
|||||||
public boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator) {
|
public boolean isLockedBy(@NotNull Mindmap mindmap, @NotNull User collaborator) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
final LockInfo lockInfo = this.getLockInfo(mindmap);
|
final LockInfo lockInfo = this.getLockInfo(mindmap);
|
||||||
if (lockInfo != null && lockInfo.getUser().equals(collaborator)) {
|
if (lockInfo != null && lockInfo.getUser().equalCollab(collaborator)) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -114,7 +114,8 @@ public class MindmapServiceImpl
|
|||||||
final Mindmap mindMap = collaboration.getMindMap();
|
final Mindmap mindMap = collaboration.getMindMap();
|
||||||
final Set<Collaboration> collaborations = mindMap.getCollaborations();
|
final Set<Collaboration> collaborations = mindMap.getCollaborations();
|
||||||
|
|
||||||
if (mindMap.getCreator().getEmail().equals(collaboration.getCollaborator().getEmail())) {
|
final User creator = mindMap.getCreator();
|
||||||
|
if (creator.equalCollab(collaboration.getCollaborator())) {
|
||||||
throw new CollaborationException("User is the creator and must have ownership permissions.Creator Email:" + mindMap.getCreator().getEmail() + ",Collaborator:" + collaboration.getCollaborator().getEmail());
|
throw new CollaborationException("User is the creator and must have ownership permissions.Creator Email:" + mindMap.getCreator().getEmail() + ",Collaborator:" + collaboration.getCollaborator().getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ public class MindmapServiceImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeMindmap(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException {
|
public void removeMindmap(@NotNull Mindmap mindmap, @NotNull User user) throws WiseMappingException {
|
||||||
if (mindmap.getCreator().equals(user)) {
|
if (mindmap.getCreator().equalCollab(user)) {
|
||||||
mindmapManager.removeMindmap(mindmap);
|
mindmapManager.removeMindmap(mindmap);
|
||||||
} else {
|
} else {
|
||||||
final Collaboration collaboration = mindmap.findCollaboration(user);
|
final Collaboration collaboration = mindmap.findCollaboration(user);
|
||||||
@ -264,7 +265,7 @@ public class MindmapServiceImpl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCollaboration(@NotNull Collaborator collaborator, @NotNull Collaboration collaboration) throws WiseMappingException {
|
public void updateCollaboration(@NotNull Collaborator collaborator, @NotNull Collaboration collaboration) throws WiseMappingException {
|
||||||
if (collaborator.equals(collaboration.getCollaborator())) {
|
if (collaborator.equalCollab(collaboration.getCollaborator())) {
|
||||||
throw new WiseMappingException("No enough permissions for this operation.");
|
throw new WiseMappingException("No enough permissions for this operation.");
|
||||||
}
|
}
|
||||||
mindmapManager.updateCollaboration(collaboration);
|
mindmapManager.updateCollaboration(collaboration);
|
||||||
@ -276,7 +277,7 @@ public class MindmapServiceImpl
|
|||||||
return this.lockManager;
|
return this.lockManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collaboration getCollaborationBy(String email, Set<Collaboration> collaborations) {
|
private Collaboration getCollaborationBy(@NotNull final String email, @NotNull final Set<Collaboration> collaborations) {
|
||||||
Collaboration collaboration = null;
|
Collaboration collaboration = null;
|
||||||
|
|
||||||
for (Collaboration user : collaborations) {
|
for (Collaboration user : collaborations) {
|
||||||
|
Loading…
Reference in New Issue
Block a user