Search in sources :

Example 11 with ActionGroup

use of org.ovirt.engine.core.common.businessentities.ActionGroup 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)

Example 12 with ActionGroup

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

the class BackendPermitResource method remove.

@Override
public Response remove() {
    get();
    ActionGroup entity = parent.lookupId(id);
    if (entity == null) {
        notFound();
        return null;
    }
    return performAction(ActionType.DetachActionGroupsFromRole, new ActionGroupsToRoleParameter(parent.roleId, asList(entity)));
}
Also used : ActionGroupsToRoleParameter(org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup)

Example 13 with ActionGroup

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

the class BackendPermitsResource method add.

@Override
public Response add(Permit permit) {
    validateParameters(permit, "name|id");
    ArrayList<ActionGroup> actionGroups = new ArrayList<>();
    addIfNotExists(actionGroups, map(permit));
    return performCreate(ActionType.AttachActionGroupsToRole, new ActionGroupsToRoleParameter(roleId, actionGroups), new PermitIdResolver(actionGroups.get(0)));
}
Also used : ActionGroupsToRoleParameter(org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ArrayList(java.util.ArrayList)

Example 14 with ActionGroup

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

the class RoleListModel method onSave.

public void onSave() {
    RoleModel model = (RoleModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    role = commandType != CommandType.Edit ? new Role() : getSelectedItem();
    role.setType(model.getIsAdminRole().getEntity() ? RoleType.ADMIN : RoleType.USER);
    if (!model.validate()) {
        return;
    }
    role.setName(model.getName().getEntity());
    role.setDescription(model.getDescription().getEntity());
    ArrayList<ActionGroup> actions = new ArrayList<>();
    HashMap<ActionGroup, ActionGroup> actionDistinctSet = new HashMap<>();
    for (SelectionTreeNodeModel sm : model.getPermissionGroupModels()) {
        for (SelectionTreeNodeModel smChild : sm.getChildren()) {
            if (smChild.getIsSelectedNullable() == null || smChild.getIsSelectedNullable()) {
                for (SelectionTreeNodeModel smGrandChild : smChild.getChildren()) {
                    if (smGrandChild.getIsSelectedNullable()) {
                        ActionGroup actionGroup = ActionGroup.valueOf(smGrandChild.getTitle());
                        if (actionDistinctSet.containsKey(actionGroup)) {
                            continue;
                        }
                        actionDistinctSet.put(actionGroup, actionGroup);
                        actions.add(actionGroup);
                    }
                }
            }
        }
    }
    ActionReturnValue returnValue;
    model.startProgress();
    if (commandType != CommandType.Edit) {
        // Add a new role.
        RoleWithActionGroupsParameters tempVar = new RoleWithActionGroupsParameters();
        tempVar.setRole(role);
        tempVar.setActionGroups(actions);
        Frontend.getInstance().runAction(ActionType.AddRoleWithActionGroups, tempVar, result -> {
            RoleListModel localModel = (RoleListModel) result.getState();
            localModel.postOnSaveNew(result.getReturnValue());
        }, this);
    } else {
        detachActionGroup = new ArrayList<>(publicAttachedActions);
        detachActionGroup.removeAll(actions);
        attachActionGroup = actions;
        attachActionGroup.removeAll(publicAttachedActions);
        Frontend.getInstance().runAction(ActionType.UpdateRole, new RolesOperationsParameters(role), result -> {
            RoleListModel roleListModel = (RoleListModel) result.getState();
            ActionReturnValue retVal = result.getReturnValue();
            if (retVal != null && retVal.getSucceeded()) {
                if (roleListModel.detachActionGroup.size() > 0) {
                    ActionGroupsToRoleParameter tempVar2 = new ActionGroupsToRoleParameter();
                    tempVar2.setActionGroups(roleListModel.detachActionGroup);
                    tempVar2.setRoleId(roleListModel.role.getId());
                    Frontend.getInstance().runAction(ActionType.DetachActionGroupsFromRole, tempVar2);
                }
                if (roleListModel.attachActionGroup.size() > 0) {
                    ActionGroupsToRoleParameter tempVar3 = new ActionGroupsToRoleParameter();
                    tempVar3.setActionGroups(roleListModel.attachActionGroup);
                    tempVar3.setRoleId(roleListModel.role.getId());
                    Frontend.getInstance().runAction(ActionType.AttachActionGroupsToRole, tempVar3);
                }
                roleListModel.getWindow().stopProgress();
                roleListModel.cancel();
            } else {
                roleListModel.getWindow().stopProgress();
            }
        }, this);
    }
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) ActionGroupsToRoleParameter(org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) RoleWithActionGroupsParameters(org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters) RolesOperationsParameters(org.ovirt.engine.core.common.action.RolesOperationsParameters)

Example 15 with ActionGroup

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

the class DetachActionGroupsFromRoleCommandTest method generateParameters.

@Override
protected ActionGroupsToRoleParameter generateParameters() {
    Guid roleId = Guid.newGuid();
    ArrayList<ActionGroup> groups = new ArrayList<>(Arrays.asList(ActionGroup.DELETE_HOST, ActionGroup.CONFIGURE_ENGINE));
    return new ActionGroupsToRoleParameter(roleId, groups);
}
Also used : ActionGroupsToRoleParameter(org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)24 ArrayList (java.util.ArrayList)9 Guid (org.ovirt.engine.core.compat.Guid)8 ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)6 Role (org.ovirt.engine.core.common.businessentities.Role)6 HashMap (java.util.HashMap)3 List (java.util.List)3 RoleGroupMap (org.ovirt.engine.core.common.businessentities.RoleGroupMap)3 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Test (org.junit.Test)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 NameableComparator (org.ovirt.engine.core.common.businessentities.comparators.NameableComparator)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2