Search in sources :

Example 11 with Role

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);
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) Before(org.junit.Before)

Example 12 with 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;
        }
    }
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup)

Example 13 with Role

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);
}
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 14 with Role

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;
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Guid(org.ovirt.engine.core.compat.Guid)

Example 15 with Role

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);
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup)

Aggregations

Role (org.ovirt.engine.core.common.businessentities.Role)28 ArrayList (java.util.ArrayList)8 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)7 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Permission (org.ovirt.engine.core.common.businessentities.Permission)4 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)4 ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)3 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)3 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)3 RoleWithActionGroupsParameters (org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters)3 RolesOperationsParameters (org.ovirt.engine.core.common.action.RolesOperationsParameters)3 RolesParameterBase (org.ovirt.engine.core.common.action.RolesParameterBase)3 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)3 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)3 NameableComparator (org.ovirt.engine.core.common.businessentities.comparators.NameableComparator)3 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)3 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)3 Inject (com.google.inject.Inject)2