Search in sources :

Example 96 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class GroupDAOTest method addRemoveGrant.

@Test
public void addRemoveGrant() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("addremove-1-");
    Group group = groupDao.createGroup();
    groupDao.addMembershipTwoWay(group, id, "addremove-1");
    groupDao.addMembershipTwoWay(group, id, "addremove-2");
    OLATResource resource = JunitTestHelper.createRandomResource();
    groupDao.addGrant(group, "addremove-1", "addremove-1-perm", resource);
    groupDao.addGrant(group, "addremove-2", "addremove-2-perm", resource);
    dbInstance.commitAndCloseSession();
    // setup check
    boolean hasPerm1 = groupDao.hasGrant(id, "addremove-1-perm", resource);
    Assert.assertTrue(hasPerm1);
    boolean hasPerm2 = groupDao.hasGrant(id, "addremove-2-perm", resource);
    Assert.assertTrue(hasPerm2);
    // remove perm 1
    groupDao.removeGrant(group, "addremove-1", "addremove-1-perm", resource);
    dbInstance.commitAndCloseSession();
    // check
    boolean hasStillPerm1 = groupDao.hasGrant(id, "addremove-1-perm", resource);
    Assert.assertFalse(hasStillPerm1);
    boolean hasStillPerm2 = groupDao.hasGrant(id, "addremove-2-perm", resource);
    Assert.assertTrue(hasStillPerm2);
}
Also used : Group(org.olat.basesecurity.Group) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 97 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class BusinessGroupRelationDAOTest method addRelation_v2.

@Test
public void addRelation_v2() {
    // create a relation
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("grp-v2-");
    BusinessGroup businessGroup = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false);
    dbInstance.commitAndCloseSession();
    Group group = ((BusinessGroupImpl) businessGroup).getBaseGroup();
    groupDao.addMembershipTwoWay(group, coach, "coach");
    dbInstance.commitAndCloseSession();
    List<String> roles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(roles);
    Assert.assertEquals(1, roles.size());
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.addRole(coach, businessGroup, "participant");
    dbInstance.commitAndCloseSession();
    List<String> multiRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(multiRoles);
    Assert.assertEquals(2, multiRoles.size());
    dbInstance.commitAndCloseSession();
    businessGroupRelationDao.removeRole(coach, businessGroup, "participant");
    List<String> reducedRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
    Assert.assertNotNull(reducedRoles);
    Assert.assertEquals(1, reducedRoles.size());
    Assert.assertEquals("coach", reducedRoles.get(0));
    dbInstance.commitAndCloseSession();
    int numOfCoaches = businessGroupRelationDao.countRoles(businessGroup, GroupRoles.coach.name());
    Assert.assertEquals(1, numOfCoaches);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) BusinessGroupImpl(org.olat.group.BusinessGroupImpl) Test(org.junit.Test)

Example 98 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class QTIResultManagerTest method selectResults_limitToSecurityGroup.

@Test
public void selectResults_limitToSecurityGroup() {
    RepositoryEntry re = createRepository();
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-result-mgr-16");
    repositoryEntryRelationDao.addRole(id1, re, GroupRoles.participant.name());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("qti-result-mgr-17");
    dbInstance.commit();
    long assessmentId = 841l;
    String resSubPath = "qtiResult37";
    String itemIdent1 = "NES:PS4:849235797";
    String itemIdent2 = "NES:PS4:849235798";
    QTIResultSet set1_1 = createSet(1.0f, assessmentId, id1, re, resSubPath, modDate(3, 8, 5), modDate(3, 8, 20));
    QTIResult result1_1 = createResult(itemIdent1, "Hello world", set1_1);
    QTIResultSet set2_1 = createSet(3.0f, assessmentId, id2, re, resSubPath, modDate(3, 14, 8), modDate(3, 14, 32));
    QTIResult result2_1 = createResult(itemIdent1, "Bonjour madame", set2_1);
    QTIResultSet set1_1b = createSet(5.0f, assessmentId, id1, re, resSubPath, modDate(3, 10, 35), modDate(3, 10, 55));
    QTIResult result1_1b = createResult(itemIdent1, "Tschuss", set1_1b);
    QTIResult result1_1c = createResult(itemIdent2, "Tschuss", set1_1b);
    dbInstance.commitAndCloseSession();
    List<Group> secGroups = Collections.singletonList(repositoryEntryRelationDao.getDefaultGroup(re));
    List<QTIResult> resultsType1 = qtiResultManager.selectResults(re.getOlatResource().getResourceableId(), resSubPath, re.getKey(), secGroups, 1);
    Assert.assertNotNull(resultsType1);
    Assert.assertEquals(3, resultsType1.size());
    Assert.assertTrue(resultsType1.contains(result1_1));
    Assert.assertTrue(resultsType1.contains(result1_1b));
    Assert.assertTrue(resultsType1.contains(result1_1c));
    // not a participant in the security group
    Assert.assertFalse(resultsType1.contains(result2_1));
}
Also used : Group(org.olat.basesecurity.Group) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 99 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class LectureBlockDAOTest method addGroup.

@Test
public void addGroup() {
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    LectureBlock lectureBlock = lectureBlockDao.createLectureBlock(entry);
    lectureBlock.setStartDate(new Date());
    lectureBlock.setEndDate(new Date());
    lectureBlock.setTitle("Hello lecturers");
    lectureBlock = lectureBlockDao.update(lectureBlock);
    dbInstance.commitAndCloseSession();
    Group defGroup = repositoryEntryRelationDao.getDefaultGroup(entry);
    lectureBlockDao.addGroupToLectureBlock(lectureBlock, defGroup);
    dbInstance.commitAndCloseSession();
    LectureBlockImpl reloadedLectureBlock = (LectureBlockImpl) lectureBlockDao.loadByKey(lectureBlock.getKey());
    Set<LectureBlockToGroup> blockToGroupSet = reloadedLectureBlock.getGroups();
    Assert.assertNotNull(blockToGroupSet);
    Assert.assertEquals(1, blockToGroupSet.size());
    LectureBlockToGroupImpl defBlockToGroup = (LectureBlockToGroupImpl) blockToGroupSet.iterator().next();
    Assert.assertEquals(defGroup, defBlockToGroup.getGroup());
    Assert.assertEquals(lectureBlock, defBlockToGroup.getLectureBlock());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) Group(org.olat.basesecurity.Group) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) BusinessGroup(org.olat.group.BusinessGroup) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) LectureBlockToGroupImpl(org.olat.modules.lecture.model.LectureBlockToGroupImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) Date(java.util.Date) Test(org.junit.Test)

Example 100 with Group

use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.

the class BGRightManagerTest method findBGRights_wrapped.

@Test
public void findBGRights_wrapped() {
    // create
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource3 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource1);
    businessGroupService.addResourceTo(group1, resource2);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource3);
    rightManager.addBGRight("bgr.fr1", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr2", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.participant);
    rightManager.addBGRight("bgr.fr3", group2.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr4", group2.getBaseGroup(), resource2.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr5", group2.getBaseGroup(), resource3.getOlatResource(), BGRightsRole.participant);
    dbInstance.commitAndCloseSession();
    // check
    List<BGRights> rights1_1 = rightManager.findBGRights(Collections.singletonList(group1.getBaseGroup()), resource1.getOlatResource());
    Assert.assertNotNull(rights1_1);
    Assert.assertEquals(2, rights1_1.size());
    List<BGRights> rights2_2 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource2.getOlatResource());
    Assert.assertNotNull(rights2_2);
    Assert.assertEquals(1, rights2_2.size());
    List<BGRights> rights2_3 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource3.getOlatResource());
    Assert.assertNotNull(rights2_3);
    Assert.assertEquals(1, rights2_3.size());
    List<Group> groups = new ArrayList<>();
    groups.add(group1.getBaseGroup());
    groups.add(group2.getBaseGroup());
    List<BGRights> rightsAll_1 = rightManager.findBGRights(groups, resource1.getOlatResource());
    Assert.assertNotNull(rightsAll_1);
    Assert.assertEquals(3, rightsAll_1.size());
}
Also used : BGRights(org.olat.group.right.BGRights) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

Group (org.olat.basesecurity.Group)170 Test (org.junit.Test)92 Identity (org.olat.core.id.Identity)80 BusinessGroup (org.olat.group.BusinessGroup)72 RepositoryEntry (org.olat.repository.RepositoryEntry)46 ArrayList (java.util.ArrayList)28 GroupMembership (org.olat.basesecurity.GroupMembership)26 LectureBlock (org.olat.modules.lecture.LectureBlock)26 OLATResource (org.olat.resource.OLATResource)26 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)20 Date (java.util.Date)16 SecurityGroup (org.olat.basesecurity.SecurityGroup)16 EPStructureElementToGroupRelation (org.olat.portfolio.model.structel.EPStructureElementToGroupRelation)14 HashSet (java.util.HashSet)12 RepositoryEntryToGroupRelation (org.olat.repository.model.RepositoryEntryToGroupRelation)11 HashMap (java.util.HashMap)8 Grant (org.olat.basesecurity.Grant)8 Calendar (java.util.Calendar)6 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)6 BGRights (org.olat.group.right.BGRights)5