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