Search in sources :

Example 26 with DbGroup

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

the class SystemPermissionListModel method onAttach.

private void onAttach() {
    AdElementListModel model = (AdElementListModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (model.getSelectedItems() == null) {
        cancel();
        return;
    }
    ArrayList<DbUser> items = new ArrayList<>();
    for (Object item : model.getItems()) {
        EntityModel entityModel = (EntityModel) item;
        if (entityModel.getIsSelected()) {
            items.add((DbUser) entityModel.getEntity());
        }
    }
    Role role = model.getRole().getSelectedItem();
    ArrayList<ActionParametersBase> list = new ArrayList<>();
    for (DbUser user : items) {
        Permission perm = new Permission(user.getId(), role.getId(), null, null);
        if (user.isGroup()) {
            DbGroup group = new DbGroup();
            group.setId(user.getId());
            group.setName(user.getFirstName());
            group.setDomain(user.getDomain());
            group.setExternalId(user.getExternalId());
            group.setNamespace(user.getNamespace());
            PermissionsOperationsParameters tempVar2 = new PermissionsOperationsParameters();
            tempVar2.setPermission(perm);
            tempVar2.setGroup(group);
            list.add(tempVar2);
        } else {
            PermissionsOperationsParameters tempVar3 = new PermissionsOperationsParameters();
            tempVar3.setPermission(perm);
            tempVar3.setUser(user);
            list.add(tempVar3);
        }
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.AddSystemPermission, list, result -> {
        AdElementListModel localModel = (AdElementListModel) result.getState();
        localModel.stopProgress();
        cancel();
    }, model);
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Permission(org.ovirt.engine.core.common.businessentities.Permission) AdElementListModel(org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 27 with DbGroup

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

the class BackendAssignedPermissionsResource method getPrincipal.

/**
 * Find the user or group that the permissions applies to.
 *
 * @param permission the incoming permission model
 * @return the user or group that the permission applies to
 */
private Object getPrincipal(Permission permission) {
    if (isUserSubCollection()) {
        DbUser dbUser = new DbUser();
        dbUser.setId(targetId);
        return dbUser;
    }
    if (isGroupSubCollection()) {
        DbGroup dbGroup = new DbGroup();
        dbGroup.setId(targetId);
        return dbGroup;
    }
    if (permission.isSetUser()) {
        User user = permission.getUser();
        DbUser dbUser = UserMapper.map(user, null);
        if (dbUser.getDomain() == null) {
            dbUser.setDomain(getCurrent().getUser().getDomain());
        }
        return dbUser;
    }
    if (permission.isSetGroup()) {
        Group group = permission.getGroup();
        DbGroup dbGroup = GroupMapper.map(group, null);
        if (dbGroup.getDomain() == null) {
            dbGroup.setDomain(getCurrent().getUser().getDomain());
        }
        return dbGroup;
    }
    return null;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) Group(org.ovirt.engine.api.model.Group) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) User(org.ovirt.engine.api.model.User) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 28 with DbGroup

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

the class BackendAssignedPermissionsResource method getParameters.

/**
 * Create the parameters for the permissions operation.
 *
 * @param model the incoming permission
 * @return the parameters for the operation
 */
private PermissionsOperationsParameters getParameters(Permission model) {
    org.ovirt.engine.core.common.businessentities.Permission entity = map(model, null);
    if (!isPrincipalSubCollection()) {
        entity.setObjectId(targetId);
        entity.setObjectType(objectType);
    }
    PermissionsOperationsParameters parameters = new PermissionsOperationsParameters();
    parameters.setPermission(entity);
    Object principal = getPrincipal(model);
    if (principal instanceof DbUser) {
        DbUser user = (DbUser) principal;
        entity.setAdElementId(user.getId());
        parameters.setUser(user);
    }
    if (principal instanceof DbGroup) {
        DbGroup group = (DbGroup) principal;
        entity.setAdElementId(group.getId());
        parameters.setGroup(group);
    }
    return parameters;
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 29 with DbGroup

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

the class QuotaUserListModel method onAdd.

public void onAdd() {
    AdElementListModel model = (AdElementListModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (model.getSelectedItems() == null && model.getSearchType() != AdSearchType.EVERYONE) {
        cancel();
        return;
    }
    ArrayList<DbUser> items = new ArrayList<>();
    if (model.getSearchType() == AdSearchType.EVERYONE) {
        DbUser tempVar = new DbUser();
        tempVar.setId(ApplicationGuids.everyone.asGuid());
        items.add(tempVar);
    } else {
        for (Object item : model.getItems()) {
            EntityModel entityModel = (EntityModel) item;
            if (entityModel.getIsSelected()) {
                items.add((DbUser) entityModel.getEntity());
            }
        }
    }
    model.startProgress();
    ArrayList<ActionParametersBase> list = new ArrayList<>();
    PermissionsOperationsParameters permissionParams;
    for (DbUser user : items) {
        Permission perm = new Permission(user.getId(), ApplicationGuids.quotaConsumer.asGuid(), getEntity().getId(), VdcObjectType.Quota);
        permissionParams = new PermissionsOperationsParameters();
        if (user.isGroup()) {
            DbGroup group = new DbGroup();
            group.setId(user.getId());
            group.setExternalId(user.getExternalId());
            group.setName(user.getFirstName());
            group.setDomain(user.getDomain());
            permissionParams.setGroup(group);
        } else {
            permissionParams.setUser(user);
        }
        permissionParams.setPermission(perm);
        list.add(permissionParams);
    }
    Frontend.getInstance().runMultipleAction(ActionType.AddPermission, list, result -> {
        QuotaUserListModel localModel = (QuotaUserListModel) result.getState();
        localModel.stopProgress();
        cancel();
    }, model);
    cancel();
}
Also used : DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Permission(org.ovirt.engine.core.common.businessentities.Permission) AdElementListModel(org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 30 with DbGroup

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

the class UserPermissionListModel method onAddRoleToUser.

private void onAddRoleToUser() {
    AdElementListModel model = (AdElementListModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    List<Role> roles = model.getRole().getSelectedItems();
    // adGroup/user
    DbUser user = getEntity();
    List<ActionParametersBase> permissionParamsList = new ArrayList<>();
    roles.forEach(role -> {
        PermissionsOperationsParameters permissionParams = new PermissionsOperationsParameters();
        Permission perm = new Permission(user.getId(), role.getId(), null, null);
        if (user.isGroup()) {
            DbGroup group = new DbGroup();
            group.setId(user.getId());
            group.setExternalId(user.getExternalId());
            group.setName(user.getFirstName());
            group.setDomain(user.getDomain());
            group.setNamespace(user.getNamespace());
            permissionParams.setPermission(perm);
            permissionParams.setGroup(group);
        } else {
            permissionParams.setPermission(perm);
            permissionParams.setUser(user);
        }
        permissionParamsList.add(permissionParams);
    });
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.AddSystemPermission, permissionParamsList, result -> {
        AdElementListModel localModel = (AdElementListModel) result.getState();
        localModel.stopProgress();
        cancel();
    }, model);
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) DbGroup(org.ovirt.engine.core.common.businessentities.aaa.DbGroup) PermissionsOperationsParameters(org.ovirt.engine.core.common.action.PermissionsOperationsParameters) ArrayList(java.util.ArrayList) Permission(org.ovirt.engine.core.common.businessentities.Permission) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Aggregations

DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)34 Test (org.junit.Test)13 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)10 Guid (org.ovirt.engine.core.compat.Guid)9 ArrayList (java.util.ArrayList)6 Group (org.ovirt.engine.api.model.Group)6 DirectoryGroup (org.ovirt.engine.core.aaa.DirectoryGroup)6 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)5 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)5 Permission (org.ovirt.engine.core.common.businessentities.Permission)5 Response (javax.ws.rs.core.Response)3 Domain (org.ovirt.engine.api.model.Domain)3 AbstractBackendCollectionResourceTest (org.ovirt.engine.api.restapi.resource.AbstractBackendCollectionResourceTest)3 Role (org.ovirt.engine.core.common.businessentities.Role)3 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)3 AdElementListModel (org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ExtMap (org.ovirt.engine.api.extensions.ExtMap)2