mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-21 21:57:56 +01:00
Improve control when owner try to be changed.
This commit is contained in:
parent
51cfa961e6
commit
d831c9d81f
@ -324,42 +324,42 @@ public class MindmapController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Has any role changed ?. Just removed it.
|
// Has any role changed ?. Just removed it.
|
||||||
final Map<String, Collaboration> mapsByEmail = mindMap
|
final Map<String, Collaboration> collabByEmail = mindMap
|
||||||
.getCollaborations()
|
.getCollaborations()
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.toMap(collaboration -> collaboration.getCollaborator().getEmail(), collaboration -> collaboration));
|
.collect(Collectors.toMap(collaboration -> collaboration.getCollaborator().getEmail(), collaboration -> collaboration));
|
||||||
|
|
||||||
restCollabs
|
|
||||||
.getCollaborations()
|
|
||||||
.forEach(collab -> {
|
|
||||||
final String email = collab.getEmail();
|
|
||||||
if (mapsByEmail.containsKey(email)) {
|
|
||||||
try {
|
|
||||||
mindmapService.removeCollaboration(mindMap, mapsByEmail.get(email));
|
|
||||||
} catch (CollaborationException e) {
|
|
||||||
logger.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Great, let's add all the collabs again ...
|
// Great, let's add all the collabs again ...
|
||||||
for (RestCollaboration restCollab : restCollabs.getCollaborations()) {
|
for (RestCollaboration restCollab : restCollabs.getCollaborations()) {
|
||||||
// Validate role format ...
|
// Validate newRole format ...
|
||||||
String roleStr = restCollab.getRole();
|
final String roleStr = restCollab.getRole();
|
||||||
if (roleStr == null) {
|
if (roleStr == null) {
|
||||||
throw new IllegalArgumentException(roleStr + " is not a valid role");
|
throw new IllegalArgumentException(roleStr + " is not a valid newRole");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is owner ?
|
// Had the newRole changed ?. Otherwise, don't touch it.
|
||||||
final String email = restCollab.getEmail();
|
final CollaborationRole newRole = CollaborationRole.valueOf(roleStr.toUpperCase());
|
||||||
final Collaboration collaboration = mindMap.findCollaboration(email);
|
final String collabEmail = restCollab.getEmail();
|
||||||
if (collaboration != null && collaboration.getRole() == CollaborationRole.OWNER) {
|
final Collaboration currentCollab = collabByEmail.get(collabEmail);
|
||||||
throw new CollabChangeException(email);
|
if (currentCollab == null || currentCollab.getRole() != newRole) {
|
||||||
}
|
|
||||||
|
|
||||||
final CollaborationRole role = CollaborationRole.valueOf(roleStr.toUpperCase());
|
// Are we trying to change the owner ...
|
||||||
mindmapService.addCollaboration(mindMap, email, role, restCollabs.getMessage());
|
if (currentCollab != null && currentCollab.getRole() == CollaborationRole.OWNER) {
|
||||||
|
throw new CollabChangeException(collabEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Role can not be changed ...
|
||||||
|
if (newRole == CollaborationRole.OWNER) {
|
||||||
|
throw new CollabChangeException(collabEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is collaboration that with different newRole, try to change it ...
|
||||||
|
if (currentCollab != null) {
|
||||||
|
mindmapService.removeCollaboration(mindMap, currentCollab);
|
||||||
|
}
|
||||||
|
mindmapService.addCollaboration(mindMap, collabEmail, newRole, restCollabs.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user