Search in sources :

Example 11 with Grant

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

the class BGRightManagerImpl method findBGRights.

/**
 * @see org.olat.group.right.BGRightManager#findBGRights(org.olat.group.BusinessGroup)
 */
@Override
public List<String> findBGRights(BusinessGroup group, BGRightsRole role) {
    GroupRoles groupRole = null;
    if (role == BGRightsRole.tutor) {
        groupRole = GroupRoles.coach;
    } else if (role == BGRightsRole.participant) {
        groupRole = GroupRoles.participant;
    } else {
        return Collections.emptyList();
    }
    List<Grant> grants = groupDao.getGrants(group.getBaseGroup(), groupRole.name());
    // filter all business group rights permissions. group right permissions
    // start with bgr.
    List<String> rights = new ArrayList<>();
    for (Grant grant : grants) {
        String right = grant.getPermission();
        if (right.indexOf(BG_RIGHT_PREFIX) == 0) {
            rights.add(right);
        }
    }
    return rights;
}
Also used : Grant(org.olat.basesecurity.Grant) GroupRoles(org.olat.basesecurity.GroupRoles) ArrayList(java.util.ArrayList)

Example 12 with Grant

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

the class GroupDAOTest method getGrants_withResource_withRole.

@Test
public void getGrants_withResource_withRole() {
    Group group = groupDao.createGroup();
    OLATResource resource = JunitTestHelper.createRandomResource();
    groupDao.addGrant(group, "getGrants-role-1", "getGrants-role-1-perm", resource);
    groupDao.addGrant(group, "getGrants-role-2", "getGrants-role-2-perm", resource);
    dbInstance.commitAndCloseSession();
    List<Grant> grants = groupDao.getGrants(group, "getGrants-role-2", 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-role-2", grant.getRole());
    Assert.assertEquals("getGrants-role-2-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 13 with Grant

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

the class GroupDAO method removeGrant.

public void removeGrant(Group group, String role, String permission, OLATResource resource) {
    StringBuilder sb = new StringBuilder();
    sb.append("select grant from bgrant as grant").append(" inner join fetch grant.group as baseGroup").append(" inner join fetch grant.resource as res").append(" where baseGroup=:group and res.key=:resourceKey and grant.permission=:permission and grant.role=:role");
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<Grant> grantToDelete = em.createQuery(sb.toString(), Grant.class).setParameter("group", group).setParameter("resourceKey", resource.getKey()).setParameter("role", role).setParameter("permission", permission).getResultList();
    for (Grant grant : grantToDelete) {
        em.remove(grant);
    }
}
Also used : Grant(org.olat.basesecurity.Grant) EntityManager(javax.persistence.EntityManager)

Example 14 with Grant

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

the class GroupDAO method removeGrants.

public void removeGrants(Group group, String role, OLATResource resource) {
    StringBuilder sb = new StringBuilder();
    sb.append("select grant from bgrant as grant").append(" inner join fetch grant.group as baseGroup").append(" inner join fetch grant.resource as res").append(" where baseGroup=:group and res.key=:resourceKey and grant.role=:role");
    EntityManager em = dbInstance.getCurrentEntityManager();
    List<Grant> grantToDelete = em.createQuery(sb.toString(), Grant.class).setParameter("group", group).setParameter("resourceKey", resource.getKey()).setParameter("role", role).getResultList();
    for (Grant grant : grantToDelete) {
        em.remove(grant);
    }
}
Also used : Grant(org.olat.basesecurity.Grant) EntityManager(javax.persistence.EntityManager)

Example 15 with Grant

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

the class BGRightManagerImpl method findBGRights.

/**
 * @see org.olat.group.right.BGRightManager#findBGRights(org.olat.group.BusinessGroup)
 */
@Override
public List<String> findBGRights(BusinessGroup group, BGRightsRole role) {
    GroupRoles groupRole = null;
    if (role == BGRightsRole.tutor) {
        groupRole = GroupRoles.coach;
    } else if (role == BGRightsRole.participant) {
        groupRole = GroupRoles.participant;
    } else {
        return Collections.emptyList();
    }
    List<Grant> grants = groupDao.getGrants(group.getBaseGroup(), groupRole.name());
    // filter all business group rights permissions. group right permissions
    // start with bgr.
    List<String> rights = new ArrayList<>();
    for (Grant grant : grants) {
        String right = grant.getPermission();
        if (right.indexOf(BG_RIGHT_PREFIX) == 0) {
            rights.add(right);
        }
    }
    return rights;
}
Also used : Grant(org.olat.basesecurity.Grant) GroupRoles(org.olat.basesecurity.GroupRoles) ArrayList(java.util.ArrayList)

Aggregations

Grant (org.olat.basesecurity.Grant)16 Group (org.olat.basesecurity.Group)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 BusinessGroup (org.olat.group.BusinessGroup)6 OLATResource (org.olat.resource.OLATResource)6 EntityManager (javax.persistence.EntityManager)4 GroupRoles (org.olat.basesecurity.GroupRoles)4 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 IdentityRef (org.olat.basesecurity.IdentityRef)2 GroupDAO (org.olat.basesecurity.manager.GroupDAO)2 DB (org.olat.core.commons.persistence.DB)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2