diff --git a/src/main/java/org/olat/basesecurity/BaseSecurity.java b/src/main/java/org/olat/basesecurity/BaseSecurity.java index 9345921f15feff147fbbb2aeefcd45d5f693b432..b4b2350d812828d331247c9ee8b4a70361528fb0 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurity.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurity.java @@ -430,6 +430,11 @@ public interface BaseSecurity { */ public void deletePolicy(SecurityGroup secGroup, String permission, OLATResource olatResourceable); + /** + * Delete all policies of a resource + */ + public void deletePolicies(OLATResource olatResourceable); + public boolean deletePolicies(Collection<SecurityGroup> secGroups, Collection<OLATResource> resources); // some queries mainly for the group/groupcontext management diff --git a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java index e8a91fe0455445c513ade7467de0a14d3c3b8dad..4a7148d17b9c4938b41b0de3913211b22d5cf65a 100644 --- a/src/main/java/org/olat/basesecurity/BaseSecurityManager.java +++ b/src/main/java/org/olat/basesecurity/BaseSecurityManager.java @@ -673,7 +673,22 @@ public class BaseSecurityManager extends BasicManager implements BaseSecurity { deletePolicy(p); } } - + + @Override + public void deletePolicies(OLATResource resource) { + StringBuilder sb = new StringBuilder(); + sb.append("delete from ").append(PolicyImpl.class.getName()).append(" as poi ") + .append(" where poi.olatResource.key=:resourceKey"); + + int rowDeleted = DBFactory.getInstance().getCurrentEntityManager() + .createQuery(sb.toString()) + .setParameter("resourceKey", resource.getKey()) + .executeUpdate(); + if(isLogDebugEnabled()) { + logDebug(rowDeleted + " policies deleted"); + } + } + /** * * @see org.olat.basesecurity.BaseSecurity#createAndPersistInvitation() diff --git a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java index 0eaf64aa2bd5ec19f643b97375ebc95b8b7eb42a..34b19facfa8fef004564390624d66a0b0dc48ccc 100644 --- a/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java +++ b/src/main/java/org/olat/course/groupsandrights/PersistingCourseGroupManager.java @@ -259,6 +259,12 @@ public class PersistingCourseGroupManager extends BasicManager implements Course public void deleteCourseGroupmanagement() { //delete permission group to course businessGroupService.removeResource(courseResource); + //delete areas + List<BGArea> areas = getAllAreas(); + for(BGArea area:areas) { + areaManager.deleteBGArea(area); + } + logAudit("Deleting course groupmanagement for " + courseResource.toString()); } diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java index a93466d4d1741491bfb5d7d93d7361cd13644908..ba51db1f2b891fd7613220ac3c52ca4e9a491a2f 100644 --- a/src/main/java/org/olat/repository/RepositoryManager.java +++ b/src/main/java/org/olat/repository/RepositoryManager.java @@ -75,6 +75,7 @@ import org.olat.core.util.vfs.VFSLeaf; import org.olat.core.util.vfs.VFSManager; import org.olat.course.assessment.manager.UserCourseInformationsManager; import org.olat.group.GroupLoggingAction; +import org.olat.group.context.BGContext2Resource; import org.olat.group.model.BGResourceRelation; import org.olat.repository.delete.service.RepositoryDeletionManager; import org.olat.repository.handlers.RepositoryHandler; @@ -192,15 +193,6 @@ public class RepositoryManager extends BasicManager { DBFactory.getInstance().saveObject(re); } - /** - * Update repo entry. - * @param re - */ - /*public void updateRepositoryEntry(RepositoryEntry re) { - re.setLastModified(new Date()); - DBFactory.getInstance().updateObject(re); - }*/ - /** * Delete repo entry. * @param re @@ -278,6 +270,8 @@ public class RepositoryManager extends BasicManager { */ public void deleteRepositoryEntryAndBasesecurity(RepositoryEntry entry) { entry = (RepositoryEntry) DBFactory.getInstance().loadObject(entry,true); + //delete all policies + BaseSecurityManager.getInstance().deletePolicies(entry.getOlatResource()); DBFactory.getInstance().deleteObject(entry); OLATResourceManager.getInstance().deleteOLATResourceable(entry); SecurityGroup ownerGroup = entry.getOwnerGroup(); @@ -387,6 +381,9 @@ public class RepositoryManager extends BasicManager { logDebug("deleteRepositoryEntry after load entry.getOwnerGroup()=" + entry.getOwnerGroup()); RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(entry); OLATResource ores = entry.getOlatResource(); + //delete old context + deleteBGcontext(ores); + if (!handler.readyToDelete(ores, ureq, wControl)) { return false; } @@ -402,16 +399,33 @@ public class RepositoryManager extends BasicManager { CatalogManager.getInstance().resourceableDeleted(entry); // delete the entry entry = (RepositoryEntry) DBFactory.getInstance().loadObject(entry,true); - logDebug("deleteRepositoryEntry after reload entry=" + entry); - deleteRepositoryEntryAndBasesecurity(entry); // inform handler to do any cleanup work... handler must delete the // referenced resourceable aswell. handler.cleanupOnDelete(entry.getOlatResource()); + + logDebug("deleteRepositoryEntry after reload entry=" + entry); + deleteRepositoryEntryAndBasesecurity(entry); + logDebug("deleteRepositoryEntry Done"); return true; } + private void deleteBGcontext(OLATResource resource) { + StringBuilder sb = new StringBuilder(); + sb.append("delete from ").append(BGContext2Resource.class.getName()) + .append(" as ctxt where ctxt.resource.key=:resourceKey"); + + int rowContextDeleted = dbInstance.getCurrentEntityManager() + .createQuery(sb.toString()) + .setParameter("resourceKey", resource.getKey()) + .executeUpdate(); + + if(log.isDebug()) { + log.debug("Context deleted: " + rowContextDeleted); + } + } + /** * Lookup repo entry by key. * @param the repository entry key (not the olatresourceable key)