From 4fda1bb38399a9c9c3c04205c02c506aad24f655 Mon Sep 17 00:00:00 2001
From: Daniel Haag <daniel.haag@uibk.ac.at>
Date: Tue, 27 Aug 2019 14:05:52 +0200
Subject: [PATCH] openolat#63: changed migration logic for repository entries
 with ACC_OWNERS_AUTHORS access to not set them to published and if they are
 courses to referencable

---
 .../LiveStreamSecurityCallbackFactory.java     |  4 ++--
 .../org/olat/upgrade/OLATUpgrade_13_0_0.java   | 18 +++++++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/olat/course/nodes/livestream/LiveStreamSecurityCallbackFactory.java b/src/main/java/org/olat/course/nodes/livestream/LiveStreamSecurityCallbackFactory.java
index bd28d9ad7b9..45028bd4c12 100644
--- a/src/main/java/org/olat/course/nodes/livestream/LiveStreamSecurityCallbackFactory.java
+++ b/src/main/java/org/olat/course/nodes/livestream/LiveStreamSecurityCallbackFactory.java
@@ -35,8 +35,8 @@ public class LiveStreamSecurityCallbackFactory {
 			ModuleConfiguration config) {
 		boolean canViewStreams = true;
 		// UIBK: we currently only allow olat admins to change/add streams, remove the first condition here to revert:
-		boolean canEditStreams = userCourseEnv.getIdentityEnvironment().getRoles().isAdministrator() &&
-				userCourseEnv.isAdmin() 
+		boolean canEditStreams = (userCourseEnv.getIdentityEnvironment().getRoles().isAdministrator() &&
+				userCourseEnv.isAdmin())
 				|| (userCourseEnv.isCoach() && config.getBooleanSafe(LiveStreamCourseNode.CONFIG_COACH_CAN_EDIT));
 		return createSecurityCallback(canViewStreams, canEditStreams);
 	}
diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java
index 4a706d8f29c..6862e4783dd 100644
--- a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java
+++ b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java
@@ -324,7 +324,10 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade {
 				if(access == RepositoryEntryAccessUpgrade.ACC_OWNERS) {
 					status = RepositoryEntryStatusEnum.preparation;
 				} else if(access == RepositoryEntryAccessUpgrade.ACC_OWNERS_AUTHORS) {
-					status = RepositoryEntryStatusEnum.review;
+					// UIBK: as we do not have the review status for now, we set this to preparation here.
+					//       no entries should be in this "unpublished" status anyway...
+					log.info("Setting unpublished repository entry (" + entry.getOlatResource().getResourceableTypeName() + ") course with access ACC_OWNERS_AUTHORS to preparation status: " + entry.getDisplayname());
+					status = RepositoryEntryStatusEnum.preparation;
 				}	
 			} else if(access == RepositoryEntryAccessUpgrade.ACC_OWNERS) {
 				if(isMembersOnly) {
@@ -333,11 +336,20 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade {
 					status = RepositoryEntryStatusEnum.preparation;
 				}
 			} else if(access == RepositoryEntryAccessUpgrade.ACC_OWNERS_AUTHORS) {
-				status = RepositoryEntryStatusEnum.review;
+				// UIBK: as we do not have the review status for now, we set this to published here.
+				log.info("Setting repository entry (" + entry.getOlatResource().getResourceableTypeName() + ") course with access ACC_OWNERS_AUTHORS to published: " + entry.getDisplayname());
+				status = RepositoryEntryStatusEnum.published;
+				// UIBK: for courses we also set the flag reference, so other authors can see them.
+				//       we can ignore other learning resources as they are handled manually
+				if (entry.getOlatResource().getResourceableTypeName().equals("CourseModule")) {
+					log.info("Setting course with access ACC_OWNERS_AUTHORS to referencable: " + entry.getDisplayname());
+					entry.setCanReference(true);
+				}
+
 			} else if(access == RepositoryEntryAccessUpgrade.ACC_USERS || access == RepositoryEntryAccessUpgrade.ACC_USERS_GUESTS) {
 				status = RepositoryEntryStatusEnum.published;
 			}
-			
+
 			entry.setEntryStatus(status);
 			dbInstance.getCurrentEntityManager().merge(entry);
 			dbInstance.commit();
-- 
GitLab