Search in sources :

Example 1 with BGRights

use of org.olat.group.right.BGRights 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);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 2 with BGRights

use of org.olat.group.right.BGRights 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());
        }
    }
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with BGRights

use of org.olat.group.right.BGRights in project openolat by klemens.

the class BGRightManagerTest method findBGRights_wrapped.

@Test
public void findBGRights_wrapped() {
    // create
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource3 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource1);
    businessGroupService.addResourceTo(group1, resource2);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "findRights", null, -1, -1, false, false, resource3);
    rightManager.addBGRight("bgr.fr1", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr2", group1.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.participant);
    rightManager.addBGRight("bgr.fr3", group2.getBaseGroup(), resource1.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr4", group2.getBaseGroup(), resource2.getOlatResource(), BGRightsRole.tutor);
    rightManager.addBGRight("bgr.fr5", group2.getBaseGroup(), resource3.getOlatResource(), BGRightsRole.participant);
    dbInstance.commitAndCloseSession();
    // check
    List<BGRights> rights1_1 = rightManager.findBGRights(Collections.singletonList(group1.getBaseGroup()), resource1.getOlatResource());
    Assert.assertNotNull(rights1_1);
    Assert.assertEquals(2, rights1_1.size());
    List<BGRights> rights2_2 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource2.getOlatResource());
    Assert.assertNotNull(rights2_2);
    Assert.assertEquals(1, rights2_2.size());
    List<BGRights> rights2_3 = rightManager.findBGRights(Collections.singletonList(group2.getBaseGroup()), resource3.getOlatResource());
    Assert.assertNotNull(rights2_3);
    Assert.assertEquals(1, rights2_3.size());
    List<Group> groups = new ArrayList<>();
    groups.add(group1.getBaseGroup());
    groups.add(group2.getBaseGroup());
    List<BGRights> rightsAll_1 = rightManager.findBGRights(groups, resource1.getOlatResource());
    Assert.assertNotNull(rightsAll_1);
    Assert.assertEquals(3, rightsAll_1.size());
}
Also used : BGRights(org.olat.group.right.BGRights) Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 4 with BGRights

use of org.olat.group.right.BGRights 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);
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 5 with BGRights

use of org.olat.group.right.BGRights 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());
        }
    }
}
Also used : Group(org.olat.basesecurity.Group) BusinessGroup(org.olat.group.BusinessGroup) BGRights(org.olat.group.right.BGRights) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)6 Group (org.olat.basesecurity.Group)6 BusinessGroup (org.olat.group.BusinessGroup)6 BGRights (org.olat.group.right.BGRights)6 HashMap (java.util.HashMap)4 Test (org.junit.Test)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2