Search in sources :

Example 31 with DataverseRole

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

the class JsonPrinterTest method testJson_RoleAssignment.

@Test
public void testJson_RoleAssignment() {
    DataverseRole aRole = new DataverseRole();
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    Dataset dataset = new Dataset();
    dataset.setId(123l);
    String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    JsonObjectBuilder job = JsonPrinter.json(ra);
    assertNotNull(job);
    JsonObject jsonObject = job.build();
    assertEquals("#42", jsonObject.getString("assignee"));
    assertEquals(123, jsonObject.getInt("definitionPointId"));
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("privateUrlToken"));
}
Also used : 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 32 with DataverseRole

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

the class ManagePermissionsPage method createNewRole.

public void createNewRole(ActionEvent e) {
    setRole(new DataverseRole());
    role.setOwner(dvObject);
}
Also used : DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 33 with DataverseRole

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

the class PermissionServiceBean method getRolesClause.

/*
    Method takes in a user and optional list of roles and dvobject type
    queries the role assigment table filtering by optional roles and dv
    returns dvobject ids
    */
private String getRolesClause(List<DataverseRole> roles) {
    StringBuilder roleStringBld = new StringBuilder();
    if (roles != null && !roles.isEmpty()) {
        roleStringBld.append(" and role_id in (");
        boolean first = true;
        for (DataverseRole role : roles) {
            if (!first) {
                roleStringBld.append(",");
            }
            roleStringBld.append(role.getId());
            first = false;
        }
        roleStringBld.append(")");
    }
    return roleStringBld.toString();
}
Also used : DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 34 with DataverseRole

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

the class RolePermissionFragment method cloneRole.

public void cloneRole(String roleId) {
    DataverseRole clonedRole = new DataverseRole();
    clonedRole.setOwner(dvObject);
    DataverseRole originalRole = roleService.find(Long.parseLong(roleId));
    clonedRole.addPermissions(originalRole.permissions());
    setRole(clonedRole);
}
Also used : DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 35 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole 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)

Aggregations

DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)44 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)23 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)6 ArrayList (java.util.ArrayList)5 User (edu.harvard.iq.dataverse.authorization.users.User)4 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)3 Permission (edu.harvard.iq.dataverse.authorization.Permission)3 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)3 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)3 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)3 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)3 Timestamp (java.sql.Timestamp)3