Search in sources :

Example 46 with Permission

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

the class PermissionDaoTest method assertGetAllForEntityResult.

/**
 * Ensures a call to {@link PermissionDao#getAllForEntity(Guid)} works properly
 */
private static void assertGetAllForEntityResult(List<Permission> result) {
    assertNotNull(result);
    assertFalse(result.isEmpty());
    for (Permission permission : result) {
        assertEquals(VM_ENTITY_ID, permission.getObjectId());
    }
}
Also used : Permission(org.ovirt.engine.core.common.businessentities.Permission)

Example 47 with Permission

use of org.ovirt.engine.core.common.businessentities.Permission 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)

Example 48 with Permission

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

the class GetPermissionsByAdElementIdQueryTest method testQueryExecution.

@Test
public void testQueryExecution() {
    // Prepare the query parameters
    Guid adElementGuid = Guid.newGuid();
    when(getQueryParameters().getId()).thenReturn(adElementGuid);
    // Create expected result
    Permission expected = new Permission();
    expected.setAdElementId(adElementGuid);
    // Mock the Daos
    when(permissionDaoMock.getAllForAdElement(adElementGuid, getQuery().getEngineSessionSeqId(), getQueryParameters().isFiltered())).thenReturn(Collections.singletonList(expected));
    getQuery().executeQueryCommand();
    // Assert the query's results
    @SuppressWarnings("unchecked") List<Permission> actual = getQuery().getQueryReturnValue().getReturnValue();
    assertEquals("Wrong number of returned permissions", 1, actual.size());
    assertEquals("Wrong returned permissions", expected, actual.get(0));
}
Also used : Permission(org.ovirt.engine.core.common.businessentities.Permission) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 49 with Permission

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

the class GetPermissionsToConsumeQuotaByQuotaIdQueryTest method mockDaoForQuery.

/**
 * Initialize Dao to be used in query.
 */
private void mockDaoForQuery() {
    returnedPermissions = new ArrayList<>();
    Permission permissions = new Permission();
    returnedPermissions.add(permissions);
    when(getQueryParameters().getId()).thenReturn(quotaId);
    when(permissionDao.getConsumedPermissionsForQuotaId(quotaId)).thenReturn(returnedPermissions);
}
Also used : Permission(org.ovirt.engine.core.common.businessentities.Permission)

Example 50 with Permission

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

the class GetPermissionsForObjectQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Guid objectId = getParameters().getObjectId();
    List<Permission> perms;
    if (getParameters().getDirectOnly()) {
        perms = dao.getAllForEntity(objectId, getEngineSessionSeqId(), getParameters().isFiltered(), getParameters().getAllUsersWithPermission());
    } else {
        perms = dao.getTreeForEntity(objectId, getParameters().getVdcObjectType(), getEngineSessionSeqId(), getParameters().isFiltered());
    }
    getQueryReturnValue().setReturnValue(perms);
}
Also used : Permission(org.ovirt.engine.core.common.businessentities.Permission) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

Permission (org.ovirt.engine.core.common.businessentities.Permission)59 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)12 Guid (org.ovirt.engine.core.compat.Guid)12 PermissionsOperationsParameters (org.ovirt.engine.core.common.action.PermissionsOperationsParameters)9 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)6 DbGroup (org.ovirt.engine.core.common.businessentities.aaa.DbGroup)6 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)5 AdElementListModel (org.ovirt.engine.ui.uicommonweb.models.users.AdElementListModel)5 Role (org.ovirt.engine.core.common.businessentities.Role)4 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)3 QueryType (org.ovirt.engine.core.common.queries.QueryType)3 AbstractTextColumn (org.ovirt.engine.ui.common.widget.table.column.AbstractTextColumn)3 PermissionTypeColumn (org.ovirt.engine.ui.common.widget.table.column.PermissionTypeColumn)3 Frontend (org.ovirt.engine.ui.frontend.Frontend)3 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)3 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)3 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)3 Inject (com.google.inject.Inject)2