Search in sources :

Example 56 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

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 57 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class GroupDAOTest method getGrants_withResource.

@Test
public void getGrants_withResource() {
    Group group = groupDao.createGroup();
    OLATResource resource = JunitTestHelper.createRandomResource();
    groupDao.addGrant(group, "getGrants-res", "getGrants-res-perm", resource);
    dbInstance.commitAndCloseSession();
    List<Group> groups = Collections.singletonList(group);
    List<Grant> grants = groupDao.getGrants(groups, resource);
    Assert.assertNotNull(grants);
    Assert.assertEquals(1, grants.size());
    Grant grant = grants.get(0);
    Assert.assertNotNull(grant);
    Assert.assertEquals(group, grant.getGroup());
    Assert.assertEquals(resource, grant.getResource());
    Assert.assertEquals("getGrants-res", grant.getRole());
    Assert.assertEquals("getGrants-res-perm", grant.getPermission());
}
Also used : Group(org.olat.basesecurity.Group) Grant(org.olat.basesecurity.Grant) OLATResource(org.olat.resource.OLATResource) Test(org.junit.Test)

Example 58 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class RepositoryEntryRelationDAO method addRole.

public void addRole(Identity identity, RepositoryEntryRef re, String role) {
    Group group = getDefaultGroup(re);
    groupDao.addMembershipOneWay(group, identity, role);
}
Also used : Group(org.olat.basesecurity.Group)

Example 59 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class RepositoryServiceImpl method deleteRepositoryEntryAndBaseGroups.

/**
 * @param entry
 */
@Override
public void deleteRepositoryEntryAndBaseGroups(RepositoryEntry entry) {
    RepositoryEntry reloadedEntry = dbInstance.getCurrentEntityManager().getReference(RepositoryEntry.class, entry.getKey());
    Long resourceKey = reloadedEntry.getOlatResource().getKey();
    Group defaultGroup = reToGroupDao.getDefaultGroup(reloadedEntry);
    if (defaultGroup != null) {
        groupDao.removeMemberships(defaultGroup);
    }
    reToGroupDao.removeRelations(reloadedEntry);
    dbInstance.commit();
    dbInstance.getCurrentEntityManager().remove(reloadedEntry);
    if (defaultGroup != null) {
        groupDao.removeGroup(defaultGroup);
    }
    dbInstance.commit();
    OLATResource reloadedResource = resourceManager.findResourceById(resourceKey);
    if (reloadedResource != null) {
        dbInstance.getCurrentEntityManager().remove(reloadedResource);
    }
    dbInstance.commit();
}
Also used : Group(org.olat.basesecurity.Group) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 60 with Group

use of org.olat.basesecurity.Group in project openolat by klemens.

the class OLATUpgrade_10_0_0 method processRepositoryEntry.

private void processRepositoryEntry(RepositoryEntryUpgrade repoEntry) {
    if (isDefaultGroupOk(repoEntry))
        return;
    Group group = groupDao.createGroup();
    // update owners
    processSecurityGroup(group, GroupRoles.owner.name(), repoEntry.getOwnerGroup());
    // update tutors
    processSecurityGroup(group, GroupRoles.coach.name(), repoEntry.getTutorGroup());
    // update participants
    processSecurityGroup(group, GroupRoles.participant.name(), repoEntry.getParticipantGroup());
    dbInstance.commit();
    RepositoryEntryUpgradeToGroupRelation relation = create(repoEntry, group, true);
    Set<RepositoryEntryUpgradeToGroupRelation> relations = new HashSet<>(2);
    relations.add(relation);
    repoEntry.setGroups(relations);
    dbInstance.commit();
}
Also used : Group(org.olat.basesecurity.Group) SecurityGroup(org.olat.basesecurity.SecurityGroup) RepositoryEntryUpgradeToGroupRelation(org.olat.upgrade.model.RepositoryEntryUpgradeToGroupRelation) HashSet(java.util.HashSet)

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