use of org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters in project ovirt-engine by oVirt.
the class BackendRolesResource method add.
@Override
public Response add(Role role) {
validateParameters(role, "name", "permits.id");
validatePermitId(role);
return performCreate(ActionType.AddRoleWithActionGroups, new RoleWithActionGroupsParameters(map(role), mapPermits(role.getPermits().getPermits())), new QueryIdResolver<Guid>(QueryType.GetRoleById, IdQueryParameters.class));
}
use of org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters 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);
}
}
Aggregations