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;
}
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());
}
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);
}
}
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);
}
}
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;
}
Aggregations