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);
}
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);
}
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;
}
Aggregations