Search in sources :

Example 11 with RoleAssignee

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

the class PrivateUrlUtilTest method testGetDatasetFromRoleAssignmentNonDataset.

@Test
public void testGetDatasetFromRoleAssignmentNonDataset() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject nonDataset = new Dataverse();
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, nonDataset, 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) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 12 with RoleAssignee

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

the class PrivateUrlUtilTest method testGetUserFromRoleAssignmentSucess.

@Test
public void testGetUserFromRoleAssignmentSucess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    DvObject dataset = new Dataset();
    dataset.setId(123l);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrlUserOut = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(ra);
    assertNotNull(privateUrlUserOut);
}
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)

Example 13 with RoleAssignee

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

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee assignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNotNull(privateUrl);
}
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)

Example 14 with RoleAssignee

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

the class ManageFilePermissionsPage method grantAccess.

public void grantAccess(ActionEvent evt) {
    // Find the built in file downloader role (currently by alias)
    DataverseRole fileDownloaderRole = roleService.findBuiltinRoleByAlias(DataverseRole.FILE_DOWNLOADER);
    for (RoleAssignee roleAssignee : selectedRoleAssignees) {
        boolean sendNotification = false;
        for (DataFile file : selectedFiles) {
            if (assignRole(roleAssignee, file, fileDownloaderRole)) {
                if (file.isReleased()) {
                    sendNotification = true;
                }
                // remove request, if it exist
                if (file.getFileAccessRequesters().remove(roleAssignee)) {
                    datafileService.save(file);
                }
            }
        }
        if (sendNotification) {
            for (AuthenticatedUser au : roleAssigneeService.getExplicitUsers(roleAssignee)) {
                userNotificationService.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.GRANTFILEACCESS, dataset.getId());
            }
        }
    }
    initMaps();
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 15 with RoleAssignee

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

the class ManageGroupsPage method saveExplicitGroup.

public void saveExplicitGroup(ActionEvent ae) {
    ExplicitGroup eg = selectedGroup;
    if (getSelectedGroupAddRoleAssignees() != null) {
        try {
            for (RoleAssignee ra : getSelectedGroupAddRoleAssignees()) {
                eg.add(ra);
            }
        } catch (GroupException ge) {
            JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group edit failed.", ge.getMessage());
            return;
        }
    }
    try {
        eg = engineService.submit(new UpdateExplicitGroupCommand(dvRequestService.getDataverseRequest(), eg));
        JsfHelper.addSuccessMessage("Succesfully saved group " + eg.getDisplayName());
    } catch (CommandException ex) {
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Save failed.", ex.getMessage());
    } catch (Exception ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "The role was not able to be saved.");
        logger.log(Level.SEVERE, "Error saving role: " + ex.getMessage(), ex);
    }
    showAssignmentMessages();
}
Also used : UpdateExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateExplicitGroupCommand) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

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