From 4dba9f704b8d6c6f1377f35ebe1cb6976a415fec Mon Sep 17 00:00:00 2001
From: aboeckle <alexander.boeckle@frentix.com>
Date: Wed, 15 Apr 2020 11:15:39 +0200
Subject: [PATCH] OO-4529 Added role check

---
 .../modules/coach/ui/StudentCoursesController.java     | 10 ++++++++--
 .../modules/coach/ui/_i18n/LocalStrings_de.properties  |  1 +
 .../modules/coach/ui/_i18n/LocalStrings_en.properties  |  1 +
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/olat/modules/coach/ui/StudentCoursesController.java b/src/main/java/org/olat/modules/coach/ui/StudentCoursesController.java
index 69e5358cd72..cb76c40c8c1 100644
--- a/src/main/java/org/olat/modules/coach/ui/StudentCoursesController.java
+++ b/src/main/java/org/olat/modules/coach/ui/StudentCoursesController.java
@@ -27,6 +27,7 @@ import java.util.stream.Collectors;
 
 import org.olat.NewControllerFactory;
 import org.olat.admin.user.UserChangePasswordController;
+import org.olat.basesecurity.BaseSecurityManager;
 import org.olat.basesecurity.BaseSecurityModule;
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.components.Component;
@@ -53,6 +54,7 @@ import org.olat.core.gui.control.generic.closablewrapper.CloseableModalControlle
 import org.olat.core.gui.control.generic.dtabs.Activateable2;
 import org.olat.core.id.Identity;
 import org.olat.core.id.OLATResourceable;
+import org.olat.core.id.Roles;
 import org.olat.core.id.context.BusinessControl;
 import org.olat.core.id.context.BusinessControlFactory;
 import org.olat.core.id.context.ContextEntry;
@@ -141,6 +143,8 @@ public class StudentCoursesController extends FormBasicController implements Act
 	private AssessmentService assessmentService;
 	@Autowired
 	private CoachingModule coachingModule;
+	@Autowired
+	private BaseSecurityManager securityManager;
 	
 	public StudentCoursesController(UserRequest ureq, WindowControl wControl, TooledStackedPanel stackPanel,
 			StudentStatEntry statEntry, Identity student, int index, int numOfStudents, boolean fullAccess) {
@@ -167,7 +171,8 @@ public class StudentCoursesController extends FormBasicController implements Act
 		homeLink.setIconLeftCSS("o_icon o_icon_home");
 		flc.getFormItemComponent().put("home", homeLink);
 		
-		if (coachingModule.isResetPasswordEnabled()) {
+		Roles roles = securityManager.getRoles(student);
+		if (coachingModule.isResetPasswordEnabled() && !(roles.isAuthor() || roles.isManager() || roles.isAdministrator() || roles.isSystemAdmin() || roles.isPrincipal())) {
 			resetLink = LinkFactory.createButton("reset.link", flc.getFormItemComponent(), this);
 			resetLink.setIconLeftCSS("o_icon o_icon_password");
 			flc.getFormItemComponent().put("reset", resetLink);
@@ -433,7 +438,8 @@ public class StudentCoursesController extends FormBasicController implements Act
 		
 		userChangePasswordController = new UserChangePasswordController(ureq, getWindowControl(), student);;
 		listenTo(userChangePasswordController);
-		cmc = new CloseableModalController(getWindowControl(), translate("close"), userChangePasswordController.getInitialComponent());
+		String name = student.getUser().getFirstName() + " " + student.getUser().getLastName();
+		cmc = new CloseableModalController(getWindowControl(), translate("close"), userChangePasswordController.getInitialComponent(), true, translate("reset.title", name));
 		cmc.activate();
 		listenTo(cmc);
 	}
diff --git a/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_de.properties
index 8c8d0a51ef8..22909a276f7 100644
--- a/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_de.properties
@@ -48,6 +48,7 @@ search=Suchen
 site.title.alt=Coaching
 site.title=Coaching
 reset.link=Passwort zur\u00FCcksetzen
+reset.title=Passwort zur\u00FCcksetzen f\u00FCr {0}
 results=Resultate
 student.name=Name
 students.details={0} {1}/{2}
diff --git a/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_en.properties
index a9298763e30..a977e0ec9c1 100644
--- a/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_en.properties
+++ b/src/main/java/org/olat/modules/coach/ui/_i18n/LocalStrings_en.properties
@@ -42,6 +42,7 @@ previous.group=$\:previous
 previous.student=$\:previous
 progress.of={0} of {1}
 reset.link=Reset password
+reset.title=Reset password for {0}
 results=Results
 search=Search
 search.form.login=User name
-- 
GitLab