Search in sources :

Example 26 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class SearchPermissionsServiceBean method getRoleAssignee.

private RoleAssignee getRoleAssignee(String idtf) {
    RoleAssignee ra = roleAssigneeCache.get(idtf);
    if (ra != null) {
        return ra;
    }
    ra = roleAssigneeService.getRoleAssignee(idtf);
    roleAssigneeCache.put(idtf, ra);
    if (roleAssigneeCache.size() > MAX_CACHE_SIZE) {
        roleAssigneeCache.remove(roleAssigneeCache.keySet().iterator().next());
    }
    return ra;
}
Also used : RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 27 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class SearchPermissionsServiceBean method findWhoHasDirectAssignments.

@Deprecated
private List<RoleAssignee> findWhoHasDirectAssignments(DvObject dvObject) {
    List<RoleAssignee> emptyList = new ArrayList<>();
    List<RoleAssignee> peopleWhoCanSearch = emptyList;
    resetRoleAssigneeCache();
    List<RoleAssignment> assignmentsOn = permissionService.assignmentsOn(dvObject);
    for (RoleAssignment roleAssignment : assignmentsOn) {
        if (roleAssignment.getRole().permissions().contains(getRequiredSearchPermission(dvObject))) {
            RoleAssignee userOrGroup = getRoleAssignee(roleAssignment.getAssigneeIdentifier());
            if (userOrGroup != null) {
                peopleWhoCanSearch.add(userOrGroup);
            }
        }
    }
    resetRoleAssigneeCache();
    return peopleWhoCanSearch;
}
Also used : RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 28 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentSuccess.

@Test
public void testGetDraftDatasetVersionFromRoleAssignmentSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    List<DatasetVersion> versions = new ArrayList<>();
    DatasetVersion datasetVersionIn = new DatasetVersion();
    datasetVersionIn.setVersionState(DatasetVersion.VersionState.DRAFT);
    versions.add(datasetVersionIn);
    dataset.setVersions(versions);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    DatasetVersion datasetVersionOut = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
    assertNotNull(datasetVersionOut);
    assertEquals("#42", ra.getAssigneeIdentifier());
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 29 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentLastestIsNotDraft.

@Test
public void testGetDraftDatasetVersionFromRoleAssignmentLastestIsNotDraft() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    List<DatasetVersion> versions = new ArrayList<>();
    DatasetVersion datasetVersionIn = new DatasetVersion();
    datasetVersionIn.setVersionState(DatasetVersion.VersionState.RELEASED);
    versions.add(datasetVersionIn);
    dataset.setVersions(versions);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    DatasetVersion datasetVersionOut = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
    assertNull(datasetVersionOut);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 30 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDatasetFromRoleAssignmentNullDefinitionPoint.

@Test
public void testGetDatasetFromRoleAssignmentNullDefinitionPoint() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject nullDefinitionPoint = null;
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, nullDefinitionPoint, privateUrlToken);
    assertNull(PrivateUrlUtil.getDatasetFromRoleAssignment(ra));
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Aggregations

RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)35 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)19 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Test (org.junit.Test)17 Dataset (edu.harvard.iq.dataverse.Dataset)13 DvObject (edu.harvard.iq.dataverse.DvObject)11 ArrayList (java.util.ArrayList)6 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 GroupException (edu.harvard.iq.dataverse.authorization.groups.GroupException)3 ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 AssignRoleCommand (edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand)2 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)2 LinkedList (java.util.LinkedList)2 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 POST (javax.ws.rs.POST)2