Search in sources :

Example 76 with DbUser

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

the class PermissionListModel method onAdd.

private void onAdd() {
    AdElementListModel model = (AdElementListModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    if (model.getSearchType() != AdSearchType.EVERYONE && model.getSelectedItems() == null) {
        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());
            }
        }
    }
    Role role = model.getRole().getSelectedItem();
    // adGroup/user
    ArrayList<ActionParametersBase> list = new ArrayList<>();
    for (DbUser user : items) {
        Permission perm = new Permission(user.getId(), role.getId(), getEntityGuid(), getObjectType());
        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());
            PermissionsOperationsParameters tempVar3 = new PermissionsOperationsParameters();
            tempVar3.setPermission(perm);
            tempVar3.setGroup(group);
            list.add(tempVar3);
        } else {
            PermissionsOperationsParameters tempVar4 = new PermissionsOperationsParameters();
            tempVar4.setPermission(perm);
            tempVar4.setUser(user);
            list.add(tempVar4);
        }
    }
    model.startProgress();
    Frontend.getInstance().runMultipleAction(ActionType.AddPermission, 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 77 with DbUser

use of org.ovirt.engine.core.common.businessentities.aaa.DbUser 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 78 with DbUser

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

the class CommandBaseTest method testConstructor.

/**
 * Testing the constructor, which adds the user id to the thread local container
 */
@Test
public void testConstructor() {
    DbUser user = mock(DbUser.class);
    when(user.getId()).thenReturn(Guid.EVERYONE);
    // Mock the session
    sessionDataContainer.setUser(session, user);
    // Create a command
    command.postConstruct();
    // Check the session
    assertEquals("wrong user id on command", user.getId(), command.getUserId());
}
Also used : DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) Test(org.junit.Test)

Example 79 with DbUser

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

the class CommandBaseTest method setupEnvironment.

@Before
public void setupEnvironment() {
    CorrelationIdTracker.clean();
    DbUser user = mock(DbUser.class);
    when(engineSessionDao.remove(anyLong())).thenReturn(1);
    sessionDataContainer.setUser(session, user);
}
Also used : DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) Before(org.junit.Before)

Example 80 with DbUser

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

the class BackendAssignedPermissionsResource method map.

/**
 * injects user/group base on permission owner type
 * @param entity the permission to map
 * @param user the permission owner
 * @return permission
 */
public Permission map(org.ovirt.engine.core.common.businessentities.Permission entity, DbUser user) {
    Permission template = new Permission();
    if (entity.getAdElementId() != null) {
        if (isUser(user)) {
            template.setUser(new User());
            template.getUser().setId(entity.getAdElementId().toString());
        } else {
            template.setGroup(new Group());
            template.getGroup().setId(entity.getAdElementId().toString());
        }
    }
    return map(entity, template);
}
Also used : 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) Permission(org.ovirt.engine.api.model.Permission)

Aggregations

DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)109 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)18 Guid (org.ovirt.engine.core.compat.Guid)18 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)13 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)10 HashSet (java.util.HashSet)9 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)9 HashMap (java.util.HashMap)8 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)8 Collection (java.util.Collection)7 Before (org.junit.Before)7 Permission (org.ovirt.engine.core.common.businessentities.Permission)7 List (java.util.List)5 Map (java.util.Map)5 AttachEntityToTagParameters (org.ovirt.engine.core.common.action.AttachEntityToTagParameters)5 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)5 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)5 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)5 TagListModel (org.ovirt.engine.ui.uicommonweb.models.tags.TagListModel)5