diff --git a/src/main/java/org/olat/catalog/CatalogManager.java b/src/main/java/org/olat/catalog/CatalogManager.java index 185c69787d08199be054c6bf5ffc7b355990f795..b5361d0d55ccd515726e4ee40ff9b66ce85d3d4a 100644 --- a/src/main/java/org/olat/catalog/CatalogManager.java +++ b/src/main/java/org/olat/catalog/CatalogManager.java @@ -191,13 +191,11 @@ public class CatalogManager extends BasicManager implements UserDataDeletable, I * @param catalogEntries List of catalog entries to be filtered * @return List of catalog entries */ - public List filterOwnedLeafs(Identity identity, List catalogEntries) { - List ownedEntries = new ArrayList(); + public List<CatalogEntry> filterOwnedLeafs(Identity identity, List<CatalogEntry> catalogEntries) { + List<CatalogEntry> ownedEntries = new ArrayList<CatalogEntry>(); BaseSecurity securityManager = BaseSecurityManager.getInstance(); - Iterator iter = catalogEntries.iterator(); - while (iter.hasNext()) { - CatalogEntry cate = (CatalogEntry) iter.next(); + for(CatalogEntry cate:catalogEntries) { if (cate.getType() == CatalogEntry.TYPE_LEAF) { RepositoryEntry repe = cate.getRepositoryEntry(); SecurityGroup secGroup = repe.getOwnerGroup(); diff --git a/src/main/java/org/olat/catalog/ui/CatalogController.java b/src/main/java/org/olat/catalog/ui/CatalogController.java index 1fe1e4e0a96c811555b4729711d82af2465d8f73..ec52e678af55421e71ea83c0189416e7ee0352a9 100644 --- a/src/main/java/org/olat/catalog/ui/CatalogController.java +++ b/src/main/java/org/olat/catalog/ui/CatalogController.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Stack; @@ -87,6 +88,7 @@ import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryEntryIconRenderer; import org.olat.repository.RepositoryManager; import org.olat.repository.RepositoryTableModel; +import org.olat.repository.SearchRepositoryEntryParameters; import org.olat.repository.controllers.EntryChangedEvent; import org.olat.repository.controllers.RepositoryEditDescriptionController; import org.olat.repository.controllers.RepositorySearchController; @@ -146,16 +148,6 @@ import org.olat.resource.accesscontrol.ui.PriceFormat; * @author Felix Jost */ public class CatalogController extends BasicController implements Activateable, Activateable2 { - - // velocity form flags - - private static final String ENABLE_GROUPMNGMNT = "enableGroupMngmnt"; - private static final String ENABLE_EDIT_CATEGORY = "enableEditCategory"; - private static final String ENABLE_REPOSITORYSELECTION = "enableRepositorySelection"; - private static final String ENABLE_ADD_SUBCATEGORY = "enableAddSubcategory"; - private static final String ENABLE_EDIT_LINK = "enableLinkEdit"; - private static final String ENABLE_EDIT_CATALOG_LINK = "enableEditCatalogLink"; - private static final String ENABLE_REQUESTFORM = "enableRequestForm"; // catalog actions @@ -277,18 +269,6 @@ public class CatalogController extends BasicController implements Activateable, updateToolAccessRights(ureq, rootce, 0); myContent = createVelocityContainer("catalog"); - - if (isOLATAdmin) { - myContent.contextPut("RepoAccessVal", new Integer(RepositoryEntry.ACC_OWNERS)); - } else if (isAuthor) { - myContent.contextPut("RepoAccessVal", new Integer(RepositoryEntry.ACC_OWNERS_AUTHORS)); - } else if (isGuest) { - myContent.contextPut("RepoAccessVal", new Integer(RepositoryEntry.ACC_USERS_GUESTS)); - } else { - // a daily user - myContent.contextPut("RepoAccessVal", new Integer(RepositoryEntry.ACC_USERS)); - } - myContent.contextPut(CATENTRY_LEAF, new Integer(CatalogEntry.TYPE_LEAF)); myContent.contextPut(CATENTRY_NODE, new Integer(CatalogEntry.TYPE_NODE)); // access rights for use in the Velocity Container @@ -582,8 +562,8 @@ public class CatalogController extends BasicController implements Activateable, */ BaseSecurity mngr = BaseSecurityManager.getInstance(); ContactList caretaker = new ContactList(translate(NLS_CONTACT_TO_GROUPNAME_CARETAKER)); - final List emptyList = new ArrayList(); - List tmpIdent = new ArrayList(); + final List<Identity> emptyList = new ArrayList<Identity>(); + List<Identity> tmpIdent = new ArrayList<Identity>(); for (int i = historyStack.size() - 1; i >= 0 && tmpIdent.isEmpty(); i--) { // start at the selected category, the root category is asserted to // have the OLATAdministrator @@ -1002,19 +982,34 @@ public class CatalogController extends BasicController implements Activateable, return myCollator.compare(c1Title, c2Title); } }); - + myContent.contextPut("children", childCe); //fxdiff VCRP-1,2: access control of resources List<Long> resourceKeys = new ArrayList<Long>(); - for ( Object leaf : childCe ) { - CatalogEntry entry = (CatalogEntry)leaf; + List<Long> repositoryEntryKeys = new ArrayList<Long>(); + for ( CatalogEntry entry : childCe ) { if(entry.getRepositoryEntry() != null && entry.getRepositoryEntry().getOlatResource() != null) { resourceKeys.add(entry.getRepositoryEntry().getOlatResource().getKey()); + repositoryEntryKeys.add(entry.getRepositoryEntry().getKey()); } } + + if(!repositoryEntryKeys.isEmpty()) { + SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(); + params.setIdentity(getIdentity()); + params.setRoles(ureq.getUserSession().getRoles()); + params.setRepositoryEntryKeys(repositoryEntryKeys); + List<RepositoryEntry> allowedEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false); + for (Iterator<CatalogEntry> itEntry = childCe.iterator(); itEntry.hasNext(); ) { + CatalogEntry entry = itEntry.next(); + if(entry.getRepositoryEntry() != null && !allowedEntries.contains(entry.getRepositoryEntry())) { + itEntry.remove(); + } + } + } + List<OLATResourceAccess> resourcesWithOffer = acFrontendManager.getAccessMethodForResources(resourceKeys, true, new Date()); - for ( Object leaf : childCe ) { - CatalogEntry entry = (CatalogEntry)leaf; + for ( CatalogEntry entry : childCe ) { if(entry.getType() == CatalogEntry.TYPE_NODE) continue; //fxdiff VCRP-1,2: access control of resources if(entry.getRepositoryEntry() != null && entry.getRepositoryEntry().getOlatResource() != null) { @@ -1037,7 +1032,7 @@ public class CatalogController extends BasicController implements Activateable, } //fxdiff VCRP-1,2: access control of resources - String acName = "ac_" + childCe.indexOf(leaf); + String acName = "ac_" + childCe.indexOf(entry); if(!types.isEmpty()) { myContent.contextPut(acName, types); } else { @@ -1046,15 +1041,15 @@ public class CatalogController extends BasicController implements Activateable, } VFSLeaf image = repositoryManager.getImage(entry.getRepositoryEntry()); - String name = "image" + childCe.indexOf(leaf); + String name = "image" + childCe.indexOf(entry); if(image == null) { myContent.remove(myContent.getComponent(name)); - continue; + } else { + ImageComponent ic = new ImageComponent(name); + ic.setMediaResource(new VFSMediaResource(image)); + ic.setMaxWithAndHeightToFitWithin(200, 100); + myContent.put(name, ic); } - ImageComponent ic = new ImageComponent(name); - ic.setMediaResource(new VFSMediaResource(image)); - ic.setMaxWithAndHeightToFitWithin(200, 100); - myContent.put(name, ic); } myContent.contextPut(CATCMD_HISTORY, historyStack); @@ -1067,7 +1062,7 @@ public class CatalogController extends BasicController implements Activateable, // can also remove links. users who can remove all links do not need to be // checked if (canAddLinks && !canRemoveAllLinks) { - List ownedLinks = cm.filterOwnedLeafs(identity, childCe); + List<CatalogEntry> ownedLinks = cm.filterOwnedLeafs(identity, childCe); if (ownedLinks.size() > 0) { myContent.contextPut("hasOwnedLinks", Boolean.TRUE); myContent.contextPut("ownedLinks", ownedLinks); @@ -1095,10 +1090,10 @@ public class CatalogController extends BasicController implements Activateable, CatalogEntry oldRoot = (CatalogEntry) cm.getRootCatalogEntries().get(0); SecurityGroup rootOwners = oldRoot.getOwnerGroup(); BaseSecurity secMgr = BaseSecurityManager.getInstance(); - List olatAdminIdents = secMgr.getIdentitiesOfSecurityGroup(rootOwners); + List<Identity> olatAdminIdents = secMgr.getIdentitiesOfSecurityGroup(rootOwners); SecurityGroup catalogAdmins = secMgr.createAndPersistSecurityGroup(); for (int i = 0; i < olatAdminIdents.size(); i++) { - secMgr.addIdentityToSecurityGroup((Identity) olatAdminIdents.get(i), catalogAdmins); + secMgr.addIdentityToSecurityGroup(olatAdminIdents.get(i), catalogAdmins); } cm.deleteCatalogEntry(oldRoot); diff --git a/src/main/java/org/olat/catalog/ui/_content/catalog.html b/src/main/java/org/olat/catalog/ui/_content/catalog.html index e83e915b91fadcf1638b28625ef523b3565a68f1..ea674604408a59203aff80117bd51e17f58f1015 100644 --- a/src/main/java/org/olat/catalog/ui/_content/catalog.html +++ b/src/main/java/org/olat/catalog/ui/_content/catalog.html @@ -26,9 +26,7 @@ #set($hasSubcats = false) #foreach($child in $children) #if ($child.getType()==$leaf) - #if($RepoAccessVal.intValue() <= $child.getRepositoryEntry().getAccess()) - #set($hasChildren = true) - #end + #set($hasChildren = true) #else #set($hasSubcats = true) #end @@ -66,7 +64,7 @@ <table class="b_table b_full"> #foreach($child in $children) #if ($child.getType()==$leaf) - #if($RepoAccessVal.intValue() <= $child.getRepositoryEntry().getAccess()) + #if($i%2==0) <tr> #else @@ -127,7 +125,7 @@ new Ext.ToolTip({ </td> </tr> #set ($i = $i +1) - #end + #end #set ($ri = $ri +1) #end diff --git a/src/main/java/org/olat/repository/RepositoryManager.java b/src/main/java/org/olat/repository/RepositoryManager.java index d3bc98dff046cb78faf300091e94d70e1719910d..9da8b490bafcbe13756c3afbeb3bfbd3c3c7130f 100644 --- a/src/main/java/org/olat/repository/RepositoryManager.java +++ b/src/main/java/org/olat/repository/RepositoryManager.java @@ -1298,6 +1298,9 @@ public class RepositoryManager extends BasicManager { if (var_resourcetypes) { query.append(" and res.resName in (:resourcetypes)"); } + if(params.getRepositoryEntryKeys() != null && !params.getRepositoryEntryKeys().isEmpty()) { + query.append(" and v.key in (:entryKeys)"); + } if(!count && orderBy) { query.append(" order by v.displayname, v.key ASC"); @@ -1319,6 +1322,9 @@ public class RepositoryManager extends BasicManager { if (var_resourcetypes) { dbQuery.setParameterList("resourcetypes", resourceTypes, Hibernate.STRING); } + if(params.getRepositoryEntryKeys() != null && !params.getRepositoryEntryKeys().isEmpty()) { + dbQuery.setParameterList("entryKeys", params.getRepositoryEntryKeys()); + } if(setIdentity) { dbQuery.setEntity("identity", identity); diff --git a/src/main/java/org/olat/repository/SearchRepositoryEntryParameters.java b/src/main/java/org/olat/repository/SearchRepositoryEntryParameters.java index e72346230942146118fdec145025df7e3bd08739..4044ee513a439bd6978c9462a0cb4cecc5c8144b 100644 --- a/src/main/java/org/olat/repository/SearchRepositoryEntryParameters.java +++ b/src/main/java/org/olat/repository/SearchRepositoryEntryParameters.java @@ -43,6 +43,7 @@ public class SearchRepositoryEntryParameters { private Roles roles; private String institution; private boolean onlyExplicitMember; + private List<Long> repositoryEntryKeys; public SearchRepositoryEntryParameters() { // @@ -148,4 +149,12 @@ public class SearchRepositoryEntryParameters { public void setOnlyExplicitMember(boolean onlyExplicitMember) { this.onlyExplicitMember = onlyExplicitMember; } + + public List<Long> getRepositoryEntryKeys() { + return repositoryEntryKeys; + } + + public void setRepositoryEntryKeys(List<Long> repositoryEntryKeys) { + this.repositoryEntryKeys = repositoryEntryKeys; + } }