Search in sources :

Example 16 with DvObject

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

the class WorldMapPermissionHelper method doesSessionUserHavePermission.

private boolean doesSessionUserHavePermission(Permission permissionToCheck, FileMetadata fileMetadata) {
    if (permissionToCheck == null) {
        return false;
    }
    DvObject objectToCheck = null;
    if (permissionToCheck.equals(Permission.EditDataset)) {
        objectToCheck = fileMetadata.getDatasetVersion().getDataset();
    } else if (permissionToCheck.equals(Permission.DownloadFile)) {
        objectToCheck = fileMetadata.getDataFile();
    }
    if (objectToCheck == null) {
        return false;
    }
    if (this.session.getUser() == null) {
        return false;
    }
    if (this.permissionService == null) {
        return false;
    }
    String permName = permissionToCheck.getHumanName();
    // 
    if (this.datasetPermissionMap.containsKey(permName)) {
        // Yes, return previous answer
        return this.datasetPermissionMap.get(permName);
    }
    // Check the permission
    // 
    boolean hasPermission = this.permissionService.userOn(this.session.getUser(), objectToCheck).has(permissionToCheck);
    // Save the permission
    this.datasetPermissionMap.put(permName, hasPermission);
    // return true/false
    return hasPermission;
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject)

Example 17 with DvObject

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

the class AbstractCommand method describe.

@Override
public String describe() {
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, DvObject> ent : affectedDvObjects.entrySet()) {
        DvObject value = ent.getValue();
        sb.append(ent.getKey()).append(":");
        sb.append((value != null) ? value.accept(DvObject.NameIdPrinter) : "<null>");
        sb.append(" ");
    }
    return sb.toString();
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with DvObject

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

the class FinalizeDatasetPublicationCommand method notifyUsersFileDownload.

// These notification methods are fairly similar, but it was cleaner to create a few copies.
// If more notifications are needed in this command, they should probably be collapsed.
private void notifyUsersFileDownload(CommandContext ctxt, DvObject subject) {
    Timestamp timestamp = new Timestamp(new Date().getTime());
    ctxt.roles().directRoleAssignments(subject).stream().filter(ra -> ra.getRole().permissions().contains(Permission.DownloadFile)).flatMap(ra -> ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier())).stream()).distinct().forEach(au -> ctxt.notifications().sendNotification(au, timestamp, UserNotification.Type.GRANTFILEACCESS, theDataset.getId()));
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) DatasetFieldConstant(edu.harvard.iq.dataverse.DatasetFieldConstant) Date(java.util.Date) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) TriggerType(edu.harvard.iq.dataverse.workflow.WorkflowContext.TriggerType) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) CommandContext(edu.harvard.iq.dataverse.engine.command.CommandContext) Level(java.util.logging.Level) ExportException(edu.harvard.iq.dataverse.export.ExportException) Permission(edu.harvard.iq.dataverse.authorization.Permission) BundleUtil(edu.harvard.iq.dataverse.util.BundleUtil) DvObject(edu.harvard.iq.dataverse.DvObject) DatasetField(edu.harvard.iq.dataverse.DatasetField) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Dataverse(edu.harvard.iq.dataverse.Dataverse) RequiredPermissions(edu.harvard.iq.dataverse.engine.command.RequiredPermissions) ExportService(edu.harvard.iq.dataverse.export.ExportService) Timestamp(java.sql.Timestamp) Dataset(edu.harvard.iq.dataverse.Dataset) DataFile(edu.harvard.iq.dataverse.DataFile) IOException(java.io.IOException) Logger(java.util.logging.Logger) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) UserNotification(edu.harvard.iq.dataverse.UserNotification) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) IdServiceBean(edu.harvard.iq.dataverse.IdServiceBean) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 19 with DvObject

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

the class ListDataverseContentCommand method execute.

@Override
public List<DvObject> execute(CommandContext ctxt) throws CommandException {
    LinkedList<DvObject> result = new LinkedList<>();
    for (Dataset ds : ctxt.datasets().findByOwnerId(dvToList.getId())) {
        try {
            ds = ctxt.engine().submit(new GetDatasetCommand(getRequest(), ds));
            result.add(ds);
        } catch (PermissionException ex) {
        }
    }
    for (Dataverse dv : ctxt.dataverses().findByOwnerId(dvToList.getId())) {
        try {
            dv = ctxt.engine().submit(new GetDataverseCommand(getRequest(), dv));
            result.add(dv);
        } catch (PermissionException ex) {
        }
    }
    return result;
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) Dataverse(edu.harvard.iq.dataverse.Dataverse) LinkedList(java.util.LinkedList)

Example 20 with DvObject

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

the class Admin method findPermissonsOn.

@Path("permissions/{dvo}")
@GET
public Response findPermissonsOn(@PathParam("dvo") String dvo) {
    try {
        DvObject dvObj = findDvo(dvo);
        if (dvObj == null) {
            return notFound("DvObject " + dvo + " not found");
        }
        try {
            User aUser = findUserOrDie();
            JsonObjectBuilder bld = Json.createObjectBuilder();
            bld.add("user", aUser.getIdentifier());
            bld.add("permissions", json(permissionSvc.permissionsFor(createDataverseRequest(aUser), dvObj)));
            return ok(bld);
        } catch (WrappedResponse wr) {
            return wr.getResponse();
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Error while testing permissions", e);
        return error(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) BuiltinUser(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser) DvObject(edu.harvard.iq.dataverse.DvObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) AuthenticationProviderFactoryNotFoundException(edu.harvard.iq.dataverse.authorization.exceptions.AuthenticationProviderFactoryNotFoundException) AuthorizationSetupException(edu.harvard.iq.dataverse.authorization.exceptions.AuthorizationSetupException) ConfirmEmailException(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailException) ConstraintViolationException(javax.validation.ConstraintViolationException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

DvObject (edu.harvard.iq.dataverse.DvObject)32 Dataset (edu.harvard.iq.dataverse.Dataset)16 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)14 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)12 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)12 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IOException (java.io.IOException)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)5 DataFile (edu.harvard.iq.dataverse.DataFile)4 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)4 Permission (edu.harvard.iq.dataverse.authorization.Permission)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 Timestamp (java.sql.Timestamp)4 HashMap (java.util.HashMap)4 DatasetField (edu.harvard.iq.dataverse.DatasetField)3