Search in sources :

Example 6 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class Index method searchPermsDebug.

/**
 * This method is for integration tests of search.
 */
@GET
@Path("permsDebug")
public Response searchPermsDebug(@QueryParam("key") String apiToken, @QueryParam("id") Long dvObjectId) {
    User user = findUserByApiToken(apiToken);
    if (user == null) {
        return error(Response.Status.UNAUTHORIZED, "Invalid apikey '" + apiToken + "'");
    }
    DvObject dvObjectToLookUp = dvObjectService.findDvObject(dvObjectId);
    if (dvObjectToLookUp == null) {
        return error(Status.BAD_REQUEST, "Could not find DvObject based on id " + dvObjectId);
    }
    List<DvObjectSolrDoc> solrDocs = SolrIndexService.determineSolrDocs(dvObjectToLookUp);
    JsonObjectBuilder data = Json.createObjectBuilder();
    JsonArrayBuilder permissionsData = Json.createArrayBuilder();
    for (DvObjectSolrDoc solrDoc : solrDocs) {
        JsonObjectBuilder dataDoc = Json.createObjectBuilder();
        dataDoc.add(SearchFields.ID, solrDoc.getSolrId());
        dataDoc.add(SearchFields.NAME_SORT, solrDoc.getNameOrTitle());
        JsonArrayBuilder perms = Json.createArrayBuilder();
        for (String perm : solrDoc.getPermissions()) {
            perms.add(perm);
        }
        dataDoc.add(SearchFields.DISCOVERABLE_BY, perms);
        permissionsData.add(dataDoc);
    }
    data.add("perms", permissionsData);
    DvObject dvObject = dvObjectService.findDvObject(dvObjectId);
    NullSafeJsonBuilder timestamps = jsonObjectBuilder();
    timestamps.add(contentChanged, SearchUtil.getTimestampOrNull(dvObject.getModificationTime()));
    timestamps.add(contentIndexed, SearchUtil.getTimestampOrNull(dvObject.getIndexTime()));
    timestamps.add(permsChanged, SearchUtil.getTimestampOrNull(dvObject.getPermissionModificationTime()));
    timestamps.add(permsIndexed, SearchUtil.getTimestampOrNull(dvObject.getPermissionIndexTime()));
    Set<RoleAssignment> roleAssignments = rolesSvc.rolesAssignments(dvObject);
    JsonArrayBuilder roleAssignmentsData = Json.createArrayBuilder();
    for (RoleAssignment roleAssignment : roleAssignments) {
        roleAssignmentsData.add(roleAssignment.getRole() + " has been granted to " + roleAssignment.getAssigneeIdentifier() + " on " + roleAssignment.getDefinitionPoint());
    }
    data.add("timestamps", timestamps);
    data.add("roleAssignments", roleAssignmentsData);
    return ok(data);
}
Also used : DvObjectSolrDoc(edu.harvard.iq.dataverse.search.DvObjectSolrDoc) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) GuestUser(edu.harvard.iq.dataverse.authorization.users.GuestUser) DvObject(edu.harvard.iq.dataverse.DvObject) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonArrayBuilder(javax.json.JsonArrayBuilder) NullSafeJsonBuilder(edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class JsonPrinterTest method testJson_PrivateUrl.

@Test
public void testJson_PrivateUrl() {
    DataverseRole aRole = new DataverseRole();
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    Dataset dataset = new Dataset();
    String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    String dataverseSiteUrl = "https://dataverse.example.edu";
    PrivateUrl privateUrl = new PrivateUrl(ra, dataset, dataverseSiteUrl);
    JsonObjectBuilder job = JsonPrinter.json(privateUrl);
    assertNotNull(job);
    JsonObject jsonObject = job.build();
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("token"));
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("link"));
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getJsonObject("roleAssignment").getString("privateUrlToken"));
    assertEquals("#42", jsonObject.getJsonObject("roleAssignment").getString("assignee"));
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 8 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser() {
    DataverseRole aRole = null;
    RoleAssignee assignee = GuestUser.get();
    DvObject dataset = new Dataset();
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 9 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentNullDataset.

@Test
public void testGetDraftDatasetVersionFromRoleAssignmentNullDataset() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject dataset = null;
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    DatasetVersion datasetVersion = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
    assertNull(datasetVersion);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) 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 10 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentSuccess.

@Test
public void testGetPrivateUrlFromRoleAssignmentSuccess() {
    String dataverseSiteUrl = "https://dataverse.example.edu";
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
    assertNotNull(privateUrl);
    assertEquals(new Long(42), privateUrl.getDataset().getId());
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=cd71e9d7-73a7-4ec8-b890-3d00499e8693", privateUrl.getLink());
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) 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

RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)38 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)23 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)22 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)14 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 ArrayList (java.util.ArrayList)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)6 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)5 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)4 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)4 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)4 Before (org.junit.Before)4 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)3