From e5edd7c3bbee00fd582ffc36305b769a706394a1 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Mon, 20 Jan 2020 16:48:37 +0100
Subject: [PATCH] OO-4484: reduce list of dispense to the profiled identity in
 profile

---
 .../coach/AbsenceNoticesListController.java   |  9 ++++--
 .../lecture/ui/coach/AbsencesController.java  |  2 +-
 .../ui/coach/DailyAbsencesController.java     |  2 +-
 .../ui/coach/DispensationsController.java     | 31 ++++++++++++++++++-
 .../ui/profile/IdentityProfileController.java |  2 +-
 5 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java b/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java
index c1882aea0fd..c0019d8d82c 100644
--- a/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java
+++ b/src/main/java/org/olat/modules/lecture/ui/coach/AbsenceNoticesListController.java
@@ -110,6 +110,7 @@ public class AbsenceNoticesListController extends FormBasicController {
 	 * Show per default the start / end date as whole date
 	 */
 	private final boolean wholeDateDefault;
+	private final boolean withUserProperties;
 	private final boolean isAdministrativeUser;
 	private final List<UserPropertyHandler> userPropertyHandlers;
 	private final LecturesSecurityCallback secCallback;
@@ -134,7 +135,8 @@ public class AbsenceNoticesListController extends FormBasicController {
 	private BaseSecurityModule securityModule;
 	
 	public AbsenceNoticesListController(UserRequest ureq, WindowControl wControl, Date currentDate,
-			boolean authorizedEnabled, LecturesSecurityCallback secCallback, String tableId) {
+			boolean authorizedEnabled, LecturesSecurityCallback secCallback, boolean withUserProperties,
+			String tableId) {
 		super(ureq, wControl, "absences_list", Util.createPackageTranslator(LectureRepositoryAdminController.class, ureq.getLocale()));
 		setTranslator(userManager.getPropertyHandlerTranslator(getTranslator()));
 		this.tableId = tableId;
@@ -142,6 +144,7 @@ public class AbsenceNoticesListController extends FormBasicController {
 		this.currentDate = currentDate;
 		wholeDateDefault = (currentDate == null);
 		this.authorizedEnabled = authorizedEnabled;
+		this.withUserProperties = withUserProperties;
 
 		isAdministrativeUser = securityModule.isUserAllowedAdminProps(ureq.getUserSession().getRoles());
 		userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_USAGE_IDENTIFIER, isAdministrativeUser);
@@ -167,7 +170,9 @@ public class AbsenceNoticesListController extends FormBasicController {
 		FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
 		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, NoticeCols.id));
 
-		initUserColumns(columnsModel);
+		if(withUserProperties) {
+			initUserColumns(columnsModel);
+		}
 		initColumns(columnsModel);
 		
 		tableModel = new AbsenceNoticesListTableModel(columnsModel, userManager, userPropertyHandlers, getLocale());
diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/AbsencesController.java b/src/main/java/org/olat/modules/lecture/ui/coach/AbsencesController.java
index bed5c19d5f7..b3c4f5a57ae 100644
--- a/src/main/java/org/olat/modules/lecture/ui/coach/AbsencesController.java
+++ b/src/main/java/org/olat/modules/lecture/ui/coach/AbsencesController.java
@@ -85,7 +85,7 @@ public class AbsencesController extends BasicController {
 		searchCtrl = new AbsenceNoticeSearchController(ureq, getWindowControl(), currentDate);
 		listenTo(searchCtrl);
 		noticesListCtlr = new AbsenceNoticesListController(ureq, getWindowControl(),
-				null, true, secCallback, "absences");
+				null, true, secCallback, true, "absences");
 		listenTo(noticesListCtlr);
 		
 		mainVC = createVelocityContainer("absences");
diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/DailyAbsencesController.java b/src/main/java/org/olat/modules/lecture/ui/coach/DailyAbsencesController.java
index 4c8a4c8d790..ef9f343ae30 100644
--- a/src/main/java/org/olat/modules/lecture/ui/coach/DailyAbsencesController.java
+++ b/src/main/java/org/olat/modules/lecture/ui/coach/DailyAbsencesController.java
@@ -67,7 +67,7 @@ public class DailyAbsencesController extends BasicController {
 			searchParams.setParticipant(profiledIdentity);
 		}
 		noticesListCtlr = new AbsenceNoticesListController(ureq, getWindowControl(),
-				currentDate, true, secCallback, "daily");
+				currentDate, true, secCallback, true, "daily");
 		listenTo(noticesListCtlr);
 		
 		mainVC = createVelocityContainer("daily_absences");
diff --git a/src/main/java/org/olat/modules/lecture/ui/coach/DispensationsController.java b/src/main/java/org/olat/modules/lecture/ui/coach/DispensationsController.java
index bece847b09f..7276fa8e5fa 100644
--- a/src/main/java/org/olat/modules/lecture/ui/coach/DispensationsController.java
+++ b/src/main/java/org/olat/modules/lecture/ui/coach/DispensationsController.java
@@ -33,6 +33,7 @@ import org.olat.core.gui.control.WindowControl;
 import org.olat.core.gui.control.controller.BasicController;
 import org.olat.core.gui.control.generic.wizard.StepRunnerCallback;
 import org.olat.core.gui.control.generic.wizard.StepsMainRunController;
+import org.olat.core.id.Identity;
 import org.olat.core.util.Util;
 import org.olat.modules.lecture.AbsenceNoticeSearchParameters;
 import org.olat.modules.lecture.AbsenceNoticeType;
@@ -64,8 +65,34 @@ public class DispensationsController extends BasicController {
 	private AbsenceNoticeSearchController searchCtrl;
 	private AbsenceNoticesListController noticesListCtlr;
 	
+	/**
+	 * Show a list of dispense (type notified or dispensation).
+	 * 
+	 * @param ureq The user request
+	 * @param wControl The window control
+	 * @param currentDate The date to restrict the list
+	 * @param secCallback The security callback
+	 * @param withSearch With search
+	 * @param withAddAbsence With button the add absence (if allowed by security callback)
+	 */
 	public DispensationsController(UserRequest ureq, WindowControl wControl, Date currentDate,
 			LecturesSecurityCallback secCallback, boolean withSearch, boolean withAddAbsence) {
+		this(ureq, wControl, currentDate, secCallback, null, withSearch, withAddAbsence);
+	}
+	
+	/**
+	 * Show a list of dispense (type notified or dispensation).
+	 * 
+	 * @param ureq The user request
+	 * @param wControl The window control
+	 * @param currentDate The date to restrict the list
+	 * @param secCallback The security callback
+	 * @param profiledIdentity Limit to a single identity (can be null)
+	 * @param withSearch With search
+	 * @param withAddAbsence With button the add absence (if allowed by security callback)
+	 */
+	public DispensationsController(UserRequest ureq, WindowControl wControl, Date currentDate,
+			LecturesSecurityCallback secCallback, Identity profiledIdentity, boolean withSearch, boolean withAddAbsence) {
 		super(ureq, wControl, Util.createPackageTranslator(LectureRepositoryAdminController.class, ureq.getLocale()));
 		
 		this.secCallback = secCallback;
@@ -76,11 +103,13 @@ public class DispensationsController extends BasicController {
 		searchParams.setLinkedToRollCall(false);
 		searchParams.setStartDate(CalendarUtils.startOfDay(currentDate));
 		searchParams.setEndDate(CalendarUtils.endOfDay(currentDate));
+		searchParams.setParticipant(profiledIdentity);
 	
 		searchCtrl = new AbsenceNoticeSearchController(ureq, getWindowControl(), currentDate);
 		listenTo(searchCtrl);
+		boolean showUserProperties = profiledIdentity == null;
 		noticesListCtlr = new AbsenceNoticesListController(ureq, getWindowControl(),
-				null, false, secCallback, "notices");
+				null, false, secCallback, showUserProperties, "notices");
 		listenTo(noticesListCtlr);
 		
 		mainVC = createVelocityContainer("dispensations");
diff --git a/src/main/java/org/olat/modules/lecture/ui/profile/IdentityProfileController.java b/src/main/java/org/olat/modules/lecture/ui/profile/IdentityProfileController.java
index 4cfa8cc66b0..e3e1ea960c5 100644
--- a/src/main/java/org/olat/modules/lecture/ui/profile/IdentityProfileController.java
+++ b/src/main/java/org/olat/modules/lecture/ui/profile/IdentityProfileController.java
@@ -159,7 +159,7 @@ public class IdentityProfileController extends BasicController implements Activa
 		// dispensation
 		if(lectureModule.isAbsenceNoticeEnabled()) {
 			dispensationsTab = tabPane.addTab(translate("user.overview.dispensation"), uureq -> {
-				dispensationsCtrl = new DispensationsController(uureq, getWindowControl(), null, secCallback, false, false);
+				dispensationsCtrl = new DispensationsController(uureq, getWindowControl(), null, secCallback, profiledIdentity, false, false);
 				listenTo(dispensationsCtrl);
 				return dispensationsCtrl.getInitialComponent();
 			});
-- 
GitLab