Search in sources :

Example 6 with Group

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

the class InvitationDAOTest method loadOrCreateIdentityAndPersistInvitation.

@Test
public void loadOrCreateIdentityAndPersistInvitation() {
    Invitation invitation = invitationDao.createAndPersistInvitation();
    String uuid = UUID.randomUUID().toString().replace("-", "");
    invitation = invitationDao.update(invitation, "Flora", uuid, uuid + "@frentix.com");
    Group group = groupDao.createGroup();
    dbInstance.commit();
    // use the create part of the method
    Identity identity = invitationDao.loadOrCreateIdentityAndPersistInvitation(invitation, group, Locale.ENGLISH);
    Assert.assertNotNull(identity);
    Assert.assertNotNull(identity.getKey());
    dbInstance.commitAndCloseSession();
    // reload and check
    Identity reloadIdentity = securityManager.loadIdentityByKey(identity.getKey());
    Assert.assertNotNull(reloadIdentity);
    Assert.assertNotNull(reloadIdentity.getUser());
    Assert.assertEquals(identity.getKey(), reloadIdentity.getKey());
    Assert.assertEquals("Flora", reloadIdentity.getUser().getFirstName());
    Assert.assertEquals(uuid, reloadIdentity.getUser().getLastName());
    Assert.assertEquals(uuid + "@frentix.com", reloadIdentity.getUser().getEmail());
}
Also used : Group(org.olat.basesecurity.Group) Invitation(org.olat.basesecurity.Invitation) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 7 with Group

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

the class RepositoryEntryRelationDAOTest method getDefaultGroup.

@Test
public void getDefaultGroup() {
    RepositoryEntry re = repositoryService.create("Rei Ayanami", "rel", "rel", null, null);
    dbInstance.commitAndCloseSession();
    Group group = repositoryEntryRelationDao.getDefaultGroup(re);
    Assert.assertNotNull(group);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 8 with Group

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

the class RepositoryEntryRelationDAOTest method removeRelation_byGroup.

@Test
public void removeRelation_byGroup() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("re-member-lc-" + UUID.randomUUID().toString());
    RepositoryEntry re1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry re2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "remove relation by group", "tg", null, null, false, false, re1);
    businessGroupRelationDao.addRole(id, group, GroupRoles.coach.name());
    businessGroupService.addResourceTo(group, re2);
    dbInstance.commitAndCloseSession();
    int numOfRelations = repositoryEntryRelationDao.removeRelation(group.getBaseGroup());
    Assert.assertEquals(2, numOfRelations);
    dbInstance.commitAndCloseSession();
    List<Group> groups = Collections.singletonList(group.getBaseGroup());
    List<RepositoryEntryToGroupRelation> relations = repositoryEntryRelationDao.getRelations(groups);
    Assert.assertEquals(0, relations.size());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RepositoryEntryToGroupRelation(org.olat.repository.model.RepositoryEntryToGroupRelation) Test(org.junit.Test)

Example 9 with Group

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

the class GroupsAndRightsController method loadModel.

private void loadModel() {
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, courseEntry, 0, -1);
    List<Group> baseGroups = getAllBaseGroups(groups);
    List<BGRights> currentRights = rightManager.findBGRights(baseGroups, courseEntry.getOlatResource());
    Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
    Map<Group, BGRights> participantToRightsMap = new HashMap<>();
    for (BGRights right : currentRights) {
        if (right.getRole() == BGRightsRole.tutor) {
            tutorToRightsMap.put(right.getBaseGroup(), right);
        } else if (right.getRole() == BGRightsRole.participant) {
            participantToRightsMap.put(right.getBaseGroup(), right);
        }
    }
    List<BGRightsRow> options = new ArrayList<>();
    String courseName = courseEntry.getDisplayname();
    Group defGroup = repositoryService.getDefaultGroup(courseEntry);
    options.add(getRightsOption(defGroup, courseName, tutorToRightsMap.get(defGroup), BGRightsRole.tutor, BGRightsResourceType.repositoryEntry));
    options.add(getRightsOption(defGroup, courseName, participantToRightsMap.get(defGroup), BGRightsRole.participant, BGRightsResourceType.repositoryEntry));
    for (BusinessGroup group : groups) {
        String name = group.getName();
        Group bGroup = group.getBaseGroup();
        options.add(getRightsOption(bGroup, name, tutorToRightsMap.get(bGroup), BGRightsRole.tutor, BGRightsResourceType.businessGroup));
        options.add(getRightsOption(bGroup, name, participantToRightsMap.get(bGroup), BGRightsRole.participant, BGRightsResourceType.businessGroup));
    }
    tableDataModel.setObjects(options);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 10 with Group

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

the class GroupsAndRightsController method doSaveChanges.

private void doSaveChanges() {
    // collect group
    List<BGRightsRow> options = tableDataModel.getObjects();
    List<Group> groups = getAllBaseGroups();
    // collect current rights
    List<BGRights> currentRights = rightManager.findBGRights(groups, courseEntry.getOlatResource());
    Map<Group, BGRights> tutorToRightsMap = new HashMap<>();
    Map<Group, BGRights> participantToRightsMap = new HashMap<>();
    for (BGRights right : currentRights) {
        if (right.getRole() == BGRightsRole.tutor) {
            tutorToRightsMap.put(right.getBaseGroup(), right);
        } else if (right.getRole() == BGRightsRole.participant) {
            participantToRightsMap.put(right.getBaseGroup(), right);
        }
    }
    for (BGRightsRow option : options) {
        List<String> newPermissions = option.getSelectedPermissions();
        BGRights rights = null;
        if (option.getRole() == BGRightsRole.tutor) {
            rights = tutorToRightsMap.get(option.getBaseGroup());
        } else if (option.getRole() == BGRightsRole.participant) {
            rights = participantToRightsMap.get(option.getBaseGroup());
        }
        if (rights == null && newPermissions.isEmpty()) {
            // nothing to do
            continue;
        }
        List<String> currentPermissions = (rights == null ? Collections.<String>emptyList() : rights.getRights());
        if (newPermissions.containsAll(currentPermissions) && currentPermissions.containsAll(newPermissions)) {
            // nothing to do
            continue;
        }
        List<String> newPermissionsTmp = new ArrayList<>(newPermissions);
        newPermissionsTmp.removeAll(currentPermissions);
        for (String newPermission : newPermissionsTmp) {
            rightManager.addBGRight(newPermission, option.getBaseGroup(), courseEntry.getOlatResource(), option.getRole());
        }
        currentPermissions.removeAll(newPermissions);
        for (String currentPermission : currentPermissions) {
            rightManager.removeBGRight(currentPermission, option.getBaseGroup(), courseEntry.getOlatResource(), option.getRole());
        }
    }
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

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