use of org.olat.basesecurity.Group in project openolat by klemens.
the class BusinessGroupDAOTest method loadBusinessGroup_fetch.
@Test
public void loadBusinessGroup_fetch() {
// create business group
BusinessGroup group = businessGroupDao.createAndPersist(null, "gd-fetch", "gd-fetch-desc", 0, 10, true, true, false, false, false);
dbInstance.commitAndCloseSession();
BusinessGroup reloadedGroup = businessGroupDao.load(group.getKey());
Assert.assertNotNull(reloadedGroup);
dbInstance.commitAndCloseSession();
// check lazy
Group baseGroup = reloadedGroup.getBaseGroup();
Assert.assertNotNull(baseGroup);
Assert.assertNotNull(baseGroup.getKey());
OLATResource resource = reloadedGroup.getResource();
Assert.assertNotNull(resource);
Assert.assertNotNull(resource.getKey());
}
use of org.olat.basesecurity.Group in project openolat by klemens.
the class BusinessGroupRelationDAOTest method addRelation_v2.
@Test
public void addRelation_v2() {
// create a relation
Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("grp-v2-");
BusinessGroup businessGroup = businessGroupDao.createAndPersist(null, "gdbo", "gdbo-desc", -1, -1, false, false, false, false, false);
dbInstance.commitAndCloseSession();
Group group = ((BusinessGroupImpl) businessGroup).getBaseGroup();
groupDao.addMembershipTwoWay(group, coach, "coach");
dbInstance.commitAndCloseSession();
List<String> roles = businessGroupRelationDao.getRoles(coach, businessGroup);
Assert.assertNotNull(roles);
Assert.assertEquals(1, roles.size());
dbInstance.commitAndCloseSession();
businessGroupRelationDao.addRole(coach, businessGroup, "participant");
dbInstance.commitAndCloseSession();
List<String> multiRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
Assert.assertNotNull(multiRoles);
Assert.assertEquals(2, multiRoles.size());
dbInstance.commitAndCloseSession();
businessGroupRelationDao.removeRole(coach, businessGroup, "participant");
List<String> reducedRoles = businessGroupRelationDao.getRoles(coach, businessGroup);
Assert.assertNotNull(reducedRoles);
Assert.assertEquals(1, reducedRoles.size());
Assert.assertEquals("coach", reducedRoles.get(0));
dbInstance.commitAndCloseSession();
int numOfCoaches = businessGroupRelationDao.countRoles(businessGroup, GroupRoles.coach.name());
Assert.assertEquals(1, numOfCoaches);
}
use of org.olat.basesecurity.Group in project openolat by klemens.
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 klemens.
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());
}
}
}
use of org.olat.basesecurity.Group in project OpenOLAT by OpenOLAT.
the class EPStructureManager method createPortfolioMapTemplate.
/**
* Create a map template, create an OLAT resource and a repository entry with a security group
* of type owner to the repository and add the identity has an owner.
* @param identity
* @param title
* @param description
* @return The structure element
*/
public PortfolioStructureMap createPortfolioMapTemplate(Identity identity, String title, String description) {
EPStructuredMapTemplate el = new EPStructuredMapTemplate();
fillStructureElement(el, title, description);
// create a repository entry with default security settings
RepositoryEntry re = createRepositoryEntry(identity, el.getOlatResource(), title);
dbInstance.commit();
Group ownerGroup = repositoryService.getDefaultGroup(re);
EPStructureElementToGroupRelation relation = createBaseRelation(el, ownerGroup);
Set<EPStructureElementToGroupRelation> relations = new HashSet<>();
relations.add(relation);
el.setGroups(relations);
return el;
}
Aggregations