From 4dd2a983df4ff1a65d9d3d9d3e09cacae0719394 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Thu, 7 Jul 2016 17:09:07 +0200
Subject: [PATCH] OO-2091: participants are not allowed anymore to bulk e-mail
 or copy groups, beautify messages, warning if not all groups are "editable"

---
 .../AbstractBusinessGroupListController.java  | 44 ++++++++++++++++---
 .../ui/main/_i18n/LocalStrings_de.properties  |  2 +
 .../ui/main/_i18n/LocalStrings_en.properties  |  2 +
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/olat/group/ui/main/AbstractBusinessGroupListController.java b/src/main/java/org/olat/group/ui/main/AbstractBusinessGroupListController.java
index 19733928c78..c5a27dcb7e1 100644
--- a/src/main/java/org/olat/group/ui/main/AbstractBusinessGroupListController.java
+++ b/src/main/java/org/olat/group/ui/main/AbstractBusinessGroupListController.java
@@ -651,7 +651,15 @@ public abstract class AbstractBusinessGroupListController extends FormBasicContr
 			return;
 		}
 		
-		List<BusinessGroup> groups = toBusinessGroups(ureq, items, false);
+		List<BusinessGroup> groups = toBusinessGroups(ureq, items, true);
+		if(groups.isEmpty()) {
+			showWarning("msg.alleastone.editable.group");
+			return;
+		}
+		if(items.size() != groups.size()) {
+			showWarning("msg.only.editable.group");
+			return;
+		}
 		
 		boolean enableCoursesCopy = businessGroupService.hasResources(groups);
 		boolean enableAreasCopy = areaManager.countBGAreasOfBusinessGroups(groups) > 0;
@@ -717,7 +725,13 @@ public abstract class AbstractBusinessGroupListController extends FormBasicContr
 		if(groups.isEmpty()) {
 			showWarning("msg.alleastone.editable.group");
 			return;
-		} else if(CollaborationToolsFactory.getInstance().getAvailableTools() == null) {
+		}
+		if(selectedItems.size() != groups.size()) {
+			showWarning("msg.only.editable.group");
+			return;
+		}
+		
+		if(CollaborationToolsFactory.getInstance().getAvailableTools() == null) {
 			//init the available tools
 			CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(groups.get(0));
 		}
@@ -797,7 +811,15 @@ public abstract class AbstractBusinessGroupListController extends FormBasicContr
 			return;
 		}
 		
-		List<BusinessGroup> groups = toBusinessGroups(ureq, selectedItems, false);
+		List<BusinessGroup> groups = toBusinessGroups(ureq, selectedItems, true);
+		if(groups.isEmpty()) {
+			showWarning("msg.alleastone.editable.group");
+			return;
+		}
+		if(selectedItems.size() != groups.size()) {
+			showWarning("msg.only.editable.group");
+			return;
+		}
 
 		Step start = new BGEmailSelectReceiversStep(ureq, groups);
 		StepRunnerCallback finish = new StepRunnerCallback() {
@@ -831,6 +853,10 @@ public abstract class AbstractBusinessGroupListController extends FormBasicContr
 			showWarning("msg.alleastone.editable.group");
 			return;
 		}
+		if(selectedItems.size() != groups.size()) {
+			showWarning("msg.only.editable.group");
+			return;
+		}
 		
 		StringBuilder managedNames = new StringBuilder();
 		for(BusinessGroup group:groups) {
@@ -943,8 +969,12 @@ public abstract class AbstractBusinessGroupListController extends FormBasicContr
 		}
 
 		final List<BusinessGroup> groups = toBusinessGroups(ureq, selectedItems, true);
-		if(groups.isEmpty()) {
-			showWarning("msg.alleastone.editable.group");
+		if(groups.size() < 2) {
+			showWarning("msg.alleasttwo.editable.group");
+			return;
+		}
+		if(selectedItems.size() != groups.size()) {
+			showWarning("msg.only.editable.group");
 			return;
 		}
 		
@@ -990,6 +1020,10 @@ public abstract class AbstractBusinessGroupListController extends FormBasicContr
 			showWarning("msg.alleastone.editable.group");
 			return;
 		}
+		if(selectedItems.size() != groups.size()) {
+			showWarning("msg.only.editable.group");
+			return;
+		}
 		
 		StringBuilder names = new StringBuilder();
 		StringBuilder managedNames = new StringBuilder();
diff --git a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
index cf56f2dbbd5..67fda2ae721 100644
--- a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
@@ -44,6 +44,8 @@ open.groups=Ver\u00F6ffentlichte Gruppen
 open.groups.alt=Arbeitsgruppen in die \u00F6ffentlich sind und an denen ich teilnehmen kann.
 msg.atleastone=Es muss mindestens ein Betreuer in der Gruppe eingetragen sein.
 msg.alleastone.editable.group=Sie m\u00FCssen mindestens eine Gruppe w\u00E4hlen, die Sie besitzen.
+msg.alleasttwo.editable.group=Sie m\u00FCssen mindestens zwei Gruppe w\u00E4hlen, die Sie besitzen.
+msg.only.editable.group=Sie m\u00FCssen Gruppe w\u00E4hlen, die Sie besitzen.
 user.notfound=Folgende Benutzer wurden nicht gefunden: {0}
 
 open.header=\u00F6ffentliche Gruppen
diff --git a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_en.properties
index 8d5c09397ae..6b68a76efab 100644
--- a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_en.properties
+++ b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_en.properties
@@ -66,6 +66,8 @@ menu.index.alt=Work with your groups
 merge.group=Merge
 msg.alleastone.editable.group=You must select at least one group you own.
 msg.atleastone=There must be at least one coach in this group.
+msg.alleasttwo.editable.group=You must select at least two groups you own.
+msg.only.editable.group=You must select groups you own.
 my.groups=My groups
 my.groups.alt=Work with your groups
 nomembers=No members found that matches the given criteria.
-- 
GitLab