Search in sources :

Example 1 with AddUserParameters

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

the class BackendUsersResource method add.

@Override
public Response add(User user) {
    validateParameters(user, "userName");
    List<String> authzProvidersNames = getBackendCollection(String.class, QueryType.GetDomainList, new QueryParametersBase());
    if (AuthzUtils.getAuthzNameFromEntityName(user.getUserName(), authzProvidersNames) == null) {
        // user-name may contain the domain (e.g: oliel@xxx.yyy)
        validateParameters(user, "domain.id|name");
    }
    String domain = getAuthzProviderName(user, authzProvidersNames);
    DirectoryUser directoryUser = findDirectoryUser(domain, user);
    if (directoryUser == null) {
        return Response.status(Status.BAD_REQUEST).entity("No such user: " + user.getUserName() + " in domain " + domain).build();
    }
    AddUserParameters parameters = new AddUserParameters(new DbUser(directoryUser));
    QueryIdResolver<Guid> resolver = new QueryIdResolver<>(QueryType.GetDbUserByUserId, IdQueryParameters.class);
    return performCreate(ActionType.AddUser, parameters, resolver, BaseResource.class);
}
Also used : DirectoryUser(org.ovirt.engine.core.aaa.DirectoryUser) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Guid(org.ovirt.engine.core.compat.Guid) AddUserParameters(org.ovirt.engine.core.common.action.AddUserParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 2 with AddUserParameters

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

the class UserListModel method onAdd.

public void onAdd(final boolean closeWindow) {
    AdElementListModel model = (AdElementListModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (model.getSelectedItems() == null) {
        cancel();
        return;
    }
    List<EntityModel<DbUser>> selectedItems = new ArrayList<>();
    for (EntityModel<DbUser> dbUserEntity : model.getItems()) {
        if (dbUserEntity.getIsSelected()) {
            selectedItems.add(dbUserEntity);
        }
    }
    List<ActionType> actionsList = new ArrayList<>(selectedItems.size());
    List<ActionParametersBase> parametersList = new ArrayList<>(selectedItems.size());
    ActionParametersBase parameters = null;
    for (EntityModel<DbUser> item : selectedItems) {
        if (item.getEntity().isGroup()) {
            actionsList.add(ActionType.AddGroup);
            DbGroup grp = new DbGroup();
            grp.setExternalId(item.getEntity().getExternalId());
            grp.setName(item.getEntity().getFirstName());
            grp.setNamespace(item.getEntity().getNamespace());
            grp.setId(item.getEntity().getId());
            grp.setDomain(item.getEntity().getDomain());
            parameters = new AddGroupParameters(grp);
        } else {
            actionsList.add(ActionType.AddUser);
            parameters = new AddUserParameters(item.getEntity());
        }
        parametersList.add(parameters);
    }
    model.startProgress();
    IFrontendActionAsyncCallback lastCallback = result -> {
        AdElementListModel localModel = (AdElementListModel) result.getState();
        localModel.stopProgress();
        // Refresh user list.
        syncSearch();
        if (closeWindow) {
            cancel();
        }
    };
    Collection<EntityModel<DbUser>> currentItems = model.getItems();
    List<IFrontendActionAsyncCallback> callbacksList = new ArrayList<>(selectedItems.size());
    for (EntityModel<DbUser> user : selectedItems) {
        callbacksList.add(nopCallback);
        currentItems.remove(user);
    }
    callbacksList.remove(callbacksList.size() - 1);
    callbacksList.add(lastCallback);
    // Refresh display
    model.setItems(null);
    model.setItems(currentItems);
    Frontend.getInstance().runMultipleActions(actionsList, parametersList, callbacksList, lastCallback, model);
}
Also used : SearchType(org.ovirt.engine.core.common.interfaces.SearchType) TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) QueryType(org.ovirt.engine.core.common.queries.QueryType) AttachEntityToTagParameters(org.ovirt.engine.core.common.action.AttachEntityToTagParameters) AddGroupParameters(org.ovirt.engine.core.common.action.AddGroupParameters) SearchObjects(org.ovirt.engine.core.searchbackend.SearchObjects) Guid(org.ovirt.engine.core.compat.Guid) AdSearchType(org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel.AdSearchType) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) Inject(com.google.inject.Inject) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) TagListModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel) HashMap(java.util.HashMap) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) IFrontendMultipleActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) Map(java.util.Map) Tags(org.ovirt.engine.core.common.businessentities.Tags) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) HasEntity(org.ovirt.engine.ui.uicommonweb.models.HasEntity) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) ActionUtils(org.ovirt.engine.core.common.ActionUtils) UserOrGroup(org.ovirt.engine.core.searchbackend.VdcUserConditionFieldAutoCompleter.UserOrGroup) SearchStringMapping(org.ovirt.engine.ui.uicommonweb.models.SearchStringMapping) Collection(java.util.Collection) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Scheduler(com.google.gwt.core.client.Scheduler) List(java.util.List) ListWithSimpleDetailsModel(org.ovirt.engine.ui.uicommonweb.models.ListWithSimpleDetailsModel) AddUserParameters(org.ovirt.engine.core.common.action.AddUserParameters) TagAssigningModel(org.ovirt.engine.ui.uicommonweb.TagAssigningModel) WebAdminApplicationPlaces(org.ovirt.engine.ui.uicommonweb.place.WebAdminApplicationPlaces) IdParameters(org.ovirt.engine.core.common.action.IdParameters) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) ActionType(org.ovirt.engine.core.common.action.ActionType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) IFrontendActionAsyncCallback(org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback) AddGroupParameters(org.ovirt.engine.core.common.action.AddGroupParameters) AddUserParameters(org.ovirt.engine.core.common.action.AddUserParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 3 with AddUserParameters

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

the class AddPermissionCommand method addUser.

private DbUser addUser(DbUser dbUser) {
    // Try to add the user with the external id:
    if (dbUser.getDomain() != null && dbUser.getExternalId() != null) {
        AddUserParameters parameters = new AddUserParameters(dbUser);
        ActionReturnValue result = runInternalAction(ActionType.AddUser, parameters, cloneContextAndDetachFromParent());
        if (result.getSucceeded()) {
            Guid id = result.getActionReturnValue();
            if (id != null) {
                return dbUserDao.get(id);
            }
            return null;
        }
    }
    // There is no such user in the directory:
    return null;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) Guid(org.ovirt.engine.core.compat.Guid) AddUserParameters(org.ovirt.engine.core.common.action.AddUserParameters)

Aggregations

AddUserParameters (org.ovirt.engine.core.common.action.AddUserParameters)3 Guid (org.ovirt.engine.core.compat.Guid)3 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)2 Scheduler (com.google.gwt.core.client.Scheduler)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 DirectoryUser (org.ovirt.engine.core.aaa.DirectoryUser)1 ActionUtils (org.ovirt.engine.core.common.ActionUtils)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 AddGroupParameters (org.ovirt.engine.core.common.action.AddGroupParameters)1 AttachEntityToTagParameters (org.ovirt.engine.core.common.action.AttachEntityToTagParameters)1 IdParameters (org.ovirt.engine.core.common.action.IdParameters)1 Tags (org.ovirt.engine.core.common.businessentities.Tags)1 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)1