Search in sources :

Example 1 with RoleGroupMap

use of org.ovirt.engine.core.common.businessentities.RoleGroupMap in project ovirt-engine by oVirt.

the class AttachActionGroupsToRoleCommandTest method testCheckGroupsCanBeAttachedSuccess.

@Test
public void testCheckGroupsCanBeAttachedSuccess() {
    getRole().setType(RoleType.ADMIN);
    RoleGroupMap map = new RoleGroupMap(ActionGroup.DELETE_STORAGE_POOL, getParams().getRoleId());
    mockGetAllForRole(Collections.singletonList(map));
    List<String> messages = new ArrayList<>();
    assertFalse("validate should succeed", getCommand().checkIfGroupsCanBeAttached(messages));
    assertTrue("no messages sould have been added", messages.isEmpty());
}
Also used : RoleGroupMap(org.ovirt.engine.core.common.businessentities.RoleGroupMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with RoleGroupMap

use of org.ovirt.engine.core.common.businessentities.RoleGroupMap in project ovirt-engine by oVirt.

the class AttachActionGroupsToRoleCommandTest method testCheckGroupsCanBeAttachedAdminIssues.

@Test
public void testCheckGroupsCanBeAttachedAdminIssues() {
    getRole().setType(RoleType.USER);
    RoleGroupMap map = new RoleGroupMap(ActionGroup.DELETE_STORAGE_POOL, getParams().getRoleId());
    mockGetAllForRole(Collections.singletonList(map));
    List<String> messages = new ArrayList<>(1);
    assertTrue("validate should fail", getCommand().checkIfGroupsCanBeAttached(messages));
    assertEquals("wrong messages", EngineMessage.CANNOT_ADD_ACTION_GROUPS_TO_ROLE_TYPE.toString(), messages.get(0));
}
Also used : RoleGroupMap(org.ovirt.engine.core.common.businessentities.RoleGroupMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with RoleGroupMap

use of org.ovirt.engine.core.common.businessentities.RoleGroupMap in project ovirt-engine by oVirt.

the class DetachActionGroupsFromRoleCommandTest method mockRoleGroups.

/**
 * Mock the action groups remaining on the role AFTER some were detached
 */
private void mockRoleGroups(ActionGroup... groups) {
    List<RoleGroupMap> maps = new ArrayList<>();
    for (ActionGroup group : groups) {
        maps.add(new RoleGroupMap(group, getParams().getRoleId()));
    }
    when(getRoleGroupMapDaoMock().getAllForRole(getParams().getRoleId())).thenReturn(maps);
}
Also used : ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) RoleGroupMap(org.ovirt.engine.core.common.businessentities.RoleGroupMap) ArrayList(java.util.ArrayList)

Example 4 with RoleGroupMap

use of org.ovirt.engine.core.common.businessentities.RoleGroupMap in project ovirt-engine by oVirt.

the class AttachActionGroupsToRoleCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean addedGroupThatAllowsViewingChildren = false;
    List<ActionGroup> groups = getParameters().getActionGroups();
    for (ActionGroup group : groups) {
        addedGroupThatAllowsViewingChildren |= group.allowsViewingChildren();
        roleGroupMapDao.save(new RoleGroupMap(group, getParameters().getRoleId()));
        appendCustomCommaSeparatedValue("ActionGroup", group.toString());
    }
    // Only adding groups that allow viewing children could make a role allow viewing its children
    if (addedGroupThatAllowsViewingChildren) {
        Role role = getRole();
        // The role should be updated only if it didn't allow viewing children in the first place
        if (!role.allowsViewingChildren()) {
            role.setAllowsViewingChildren(true);
            roleDao.update(role);
        }
    }
    setSucceeded(true);
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) RoleGroupMap(org.ovirt.engine.core.common.businessentities.RoleGroupMap)

Example 5 with RoleGroupMap

use of org.ovirt.engine.core.common.businessentities.RoleGroupMap in project ovirt-engine by oVirt.

the class RoleGroupMapDaoTest method testSaveRoleGroupMap.

/**
 * Ensures saving such a mapping works as expected.
 */
@Test
public void testSaveRoleGroupMap() {
    dao.save(newRoleGroupMap);
    List<RoleGroupMap> result = dao.getAllForRole(newRoleGroupMap.getRoleId());
    boolean worked = false;
    for (RoleGroupMap map : result) {
        worked |= newRoleGroupMap.equals(map);
    }
    assertTrue(worked);
}
Also used : RoleGroupMap(org.ovirt.engine.core.common.businessentities.RoleGroupMap) Test(org.junit.Test)

Aggregations

RoleGroupMap (org.ovirt.engine.core.common.businessentities.RoleGroupMap)11 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)3 Role (org.ovirt.engine.core.common.businessentities.Role)1