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