Skip to content
Snippets Groups Projects
Commit 65e8ff34 authored by srosse's avatar srosse
Browse files

OO-948: rewrite the method to return without retrieving the owners

parent 3605ca2a
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,7 @@ import org.olat.core.gui.control.WindowControl;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.Roles;
import org.olat.core.id.UserConstants;
import org.olat.core.logging.AssertException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
......@@ -2211,22 +2212,30 @@ public class RepositoryManager extends BasicManager {
* @param Identity identity
*/
public boolean isInstitutionalRessourceManagerFor(RepositoryEntry repositoryEntry, Identity identity) {
if(repositoryEntry == null || repositoryEntry.getOwnerGroup() == null) return false;
BaseSecurity secMgr = BaseSecurityManager.getInstance();
// list of owners
List<Identity> listIdentities = secMgr.getIdentitiesOfSecurityGroup(repositoryEntry.getOwnerGroup());
String currentUserInstitutionalName = identity.getUser().getProperty("institutionalName", null);
boolean isInstitutionalResourceManager = BaseSecurityManager.getInstance().isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_INSTORESMANAGER);
if(repositoryEntry == null || repositoryEntry.getOwnerGroup() == null) {
return false;
}
String currentUserInstitutionalName = identity.getUser().getProperty(UserConstants.INSTITUTIONALNAME, null);
if(!StringHelper.containsNonWhitespace(currentUserInstitutionalName)) {
return false;
}
boolean isInstitutionalResourceManager = securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_INSTORESMANAGER);
if(!isInstitutionalResourceManager) {
return false;
}
boolean sameInstitutional = false;
String identInstitutionalName = "";
List<Identity> listIdentities = securityManager.getIdentitiesOfSecurityGroup(repositoryEntry.getOwnerGroup());
for (Identity ident : listIdentities) {
identInstitutionalName = ident.getUser().getProperty("institutionalName", null);
if ((identInstitutionalName != null) && (identInstitutionalName.equals(currentUserInstitutionalName))) {
String identInstitutionalName = ident.getUser().getProperty(UserConstants.INSTITUTIONALNAME, null);
if (identInstitutionalName != null && identInstitutionalName.equals(currentUserInstitutionalName)) {
sameInstitutional = true;
break;
}
}
return isInstitutionalResourceManager && sameInstitutional;
return sameInstitutional;
}
public int countLearningResourcesAsStudent(Identity identity) {
......
......@@ -42,6 +42,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.Constants;
import org.olat.basesecurity.SecurityGroup;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.DBFactory;
......@@ -49,6 +50,7 @@ import org.olat.core.commons.services.mark.MarkManager;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.Roles;
import org.olat.core.id.UserConstants;
import org.olat.core.logging.AssertException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
......@@ -64,6 +66,7 @@ import org.olat.resource.OLATResourceManager;
import org.olat.test.JMSCodePointServerJunitHelper;
import org.olat.test.JunitTestHelper;
import org.olat.test.OlatTestCase;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -79,6 +82,8 @@ public class RepositoryManagerTest extends OlatTestCase {
@Autowired
private DB dbInstance;
@Autowired
private UserManager userManager;
@Autowired
private BaseSecurity securityManager;
@Autowired
private OLATResourceManager resourceManager;
......@@ -707,6 +712,44 @@ public class RepositoryManagerTest extends OlatTestCase {
Assert.assertNotNull(membership2s);
Assert.assertTrue(membership2s.isEmpty());
}
/**
* How can be a resource manager if Constants.ORESOURCE_USERMANAGER is never used?
*/
@Test
public void isInstitutionalRessourceManagerFor() {
Identity owner1 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
Identity owner2 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
Identity part3 = JunitTestHelper.createAndPersistIdentityAsUser("instit-" + UUID.randomUUID().toString());
RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
securityManager.addIdentityToSecurityGroup(owner1, re.getOwnerGroup());
securityManager.addIdentityToSecurityGroup(owner2, re.getOwnerGroup());
securityManager.addIdentityToSecurityGroup(part3, re.getParticipantGroup());
dbInstance.commit();
//set the institutions
owner1.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
owner2.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
part3.getUser().setProperty(UserConstants.INSTITUTIONALNAME, "volks");
userManager.updateUserFromIdentity(owner1);
userManager.updateUserFromIdentity(owner2);
userManager.updateUserFromIdentity(part3);
dbInstance.commit();
//promote owner1 to institution resource manager
SecurityGroup institutionalResourceManagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
securityManager.addIdentityToSecurityGroup(owner1, institutionalResourceManagerGroup);
dbInstance.commitAndCloseSession();
//check
boolean institutionMgr1 = repositoryManager.isInstitutionalRessourceManagerFor(re, owner1);
boolean institutionMgr2 = repositoryManager.isInstitutionalRessourceManagerFor(re, owner2);
boolean institutionMgr3 = repositoryManager.isInstitutionalRessourceManagerFor(re, part3);
Assert.assertTrue(institutionMgr1);
Assert.assertFalse(institutionMgr2);
Assert.assertFalse(institutionMgr3);
}
@Test
public void testCountByTypeLimitAccess() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment