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;
}
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();
}
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()));
}
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;
}
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());
}
}
Aggregations