Search in sources :

Example 1 with ActionGroupsToRoleParameter

use of org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter in project ovirt-engine by oVirt.

the class AttachActionGroupsToRoleCommandTest 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)

Example 2 with ActionGroupsToRoleParameter

use of org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter 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 3 with ActionGroupsToRoleParameter

use of org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter 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 4 with ActionGroupsToRoleParameter

use of org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter 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 5 with ActionGroupsToRoleParameter

use of org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter 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

ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)6 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)5 ArrayList (java.util.ArrayList)4 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 Guid (org.ovirt.engine.core.compat.Guid)2 HashMap (java.util.HashMap)1 RoleWithActionGroupsParameters (org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters)1 RolesOperationsParameters (org.ovirt.engine.core.common.action.RolesOperationsParameters)1 Role (org.ovirt.engine.core.common.businessentities.Role)1 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)1