use of org.ovirt.engine.core.common.businessentities.Role in project ovirt-engine by oVirt.
the class AbstractRolesCommandTestBase method setUp.
@Before
public void setUp() {
role = new Role();
role.setId(params.getRoleId());
when(roleDaoMock.get(params.getRoleId())).thenReturn(role);
}
use of org.ovirt.engine.core.common.businessentities.Role in project ovirt-engine by oVirt.
the class AddRoleWithActionGroupsCommand method prepareRoleForCommand.
/**
*/
protected void prepareRoleForCommand() {
// Note that the role is take from the parameters
Role role = getRole();
role.setId(Guid.newGuid());
role.setAllowsViewingChildren(false);
// Set the application mode as 255 - AllModes by default
getRole().setAppMode(ApplicationMode.AllModes);
for (ActionGroup group : getParameters().getActionGroups()) {
if (group.allowsViewingChildren()) {
role.setAllowsViewingChildren(true);
break;
}
}
}
use of org.ovirt.engine.core.common.businessentities.Role 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.Role in project ovirt-engine by oVirt.
the class AttachActionGroupsToRoleCommand method checkIfGroupsCanBeAttached.
protected boolean checkIfGroupsCanBeAttached(List<String> validationMessages) {
List<ActionGroup> attachGroups = getParameters().getActionGroups();
Guid roleId = getParameters().getRoleId();
Role role = getRole();
// Get all groups by ID and check if they already exist
List<ActionGroup> allGroups = getActionGroupsByRoleId(roleId);
for (ActionGroup group : attachGroups) {
if (allGroups.contains(group)) {
// group already exist
validationMessages.add(EngineMessage.ERROR_CANNOT_ATTACH_ACTION_GROUP_TO_ROLE_ATTACHED.toString());
return true;
} else if (role.getType() != RoleType.ADMIN && group.getRoleType() == RoleType.ADMIN) {
validationMessages.add(EngineMessage.CANNOT_ADD_ACTION_GROUPS_TO_ROLE_TYPE.toString());
return true;
}
}
return false;
}
use of org.ovirt.engine.core.common.businessentities.Role in project ovirt-engine by oVirt.
the class DetachActionGroupsFromRoleCommand method executeCommand.
@Override
protected void executeCommand() {
List<ActionGroup> groupsToDetach = getParameters().getActionGroups();
for (ActionGroup group : groupsToDetach) {
roleGroupMapDao.remove(group, getParameters().getRoleId());
appendCustomCommaSeparatedValue("ActionGroup", group.toString());
}
// If the role didn't allow viewing children in the first place, removing action groups won't change that
Role role = getRole();
if (role.allowsViewingChildren()) {
boolean shouldAllowViewingChildren = false;
// Go over all the REMAINING action groups
List<ActionGroup> groups = getActionGroupsByRoleId(role.getId());
for (ActionGroup group : groups) {
if (group.allowsViewingChildren()) {
shouldAllowViewingChildren = true;
break;
}
}
if (!shouldAllowViewingChildren) {
role.setAllowsViewingChildren(false);
roleDao.update(role);
}
}
setSucceeded(true);
}
Aggregations