use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method hasRole.
@Test
public void hasRole() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-2-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-2b-");
Group group = groupDao.createGroup();
GroupMembership membership = groupDao.addMembershipTwoWay(group, id, "author");
dbInstance.commit();
Assert.assertNotNull(membership);
dbInstance.commitAndCloseSession();
boolean hasRole = groupDao.hasRole(group, id, "author");
Assert.assertTrue(hasRole);
// negative tests
boolean hasNotRole = groupDao.hasRole(group, id, "pilot");
Assert.assertFalse(hasNotRole);
boolean id2_hasNotRole = groupDao.hasRole(group, id2, "author");
Assert.assertFalse(id2_hasNotRole);
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method removeMemberships_groupAndRole.
@Test
public void removeMemberships_groupAndRole() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-12-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-13-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "copilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
// check
int numOfMembers = groupDao.countMembers(group);
Assert.assertEquals(2, numOfMembers);
// remove
int numOfDeletedRows = groupDao.removeMemberships(group, "pilot");
dbInstance.commitAndCloseSession();
Assert.assertEquals(1, numOfDeletedRows);
// check
List<GroupMembership> deletedMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertTrue(deletedMemberships.isEmpty());
List<GroupMembership> lastMemberships = groupDao.getMemberships(group, "copilot");
Assert.assertEquals(1, lastMemberships.size());
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method removeMembership.
@Test
public void removeMembership() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-7-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-8-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "pilot");
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> memberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(2, memberships.size());
// remove
groupDao.removeMembership(group, id1);
dbInstance.commitAndCloseSession();
// check
List<GroupMembership> deletedMemberships = groupDao.getMemberships(group, "pilot");
Assert.assertEquals(1, deletedMemberships.size());
Identity stayingMember = deletedMemberships.get(0).getIdentity();
Assert.assertNotNull(stayingMember);
Assert.assertEquals(id2, stayingMember);
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class GroupDAOTest method countMembers.
@Test
public void countMembers() {
Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-4-");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-5-");
Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("bgrp-6-");
Group group = groupDao.createGroup();
GroupMembership membership1 = groupDao.addMembershipTwoWay(group, id1, "pilot");
GroupMembership membership2 = groupDao.addMembershipTwoWay(group, id2, "pilot");
GroupMembership membership3 = groupDao.addMembershipTwoWay(group, id3, "copilot");
dbInstance.commit();
Assert.assertNotNull(membership1);
Assert.assertNotNull(membership2);
Assert.assertNotNull(membership3);
dbInstance.commitAndCloseSession();
int numOfMembers = groupDao.countMembers(group);
Assert.assertEquals(3, numOfMembers);
}
use of org.olat.basesecurity.GroupMembership in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_10_0_0 method processSecurityGroup.
private void processSecurityGroup(Group group, String role, SecurityGroup secGroup) {
if (secGroup == null)
return;
List<SecurityGroupMembershipImpl> oldMemberships = getMembershipsOfSecurityGroup(secGroup);
for (SecurityGroupMembershipImpl oldMembership : oldMemberships) {
GroupMembershipImpl membership = new GroupMembershipImpl();
membership.setCreationDate(oldMembership.getCreationDate());
membership.setLastModified(oldMembership.getLastModified());
membership.setGroup(group);
membership.setIdentity(oldMembership.getIdentity());
membership.setRole(role);
dbInstance.getCurrentEntityManager().persist(membership);
Set<GroupMembership> members = ((GroupImpl) group).getMembers();
if (members == null) {
members = new HashSet<>();
((GroupImpl) group).setMembers(members);
}
members.add(membership);
}
}
Aggregations