Adds backend validation so that only creator can edit one DMP.

This commit is contained in:
gkolokythas 2019-12-18 12:38:04 +02:00
parent e50bef555f
commit 9aed05d574
1 changed files with 5 additions and 5 deletions

View File

@ -69,9 +69,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -106,7 +104,6 @@ public class DataManagementPlanManager {
CompletableFuture itemsFuture; CompletableFuture itemsFuture;
if (fieldsGroup.equals("listing")) { if (fieldsGroup.equals("listing")) {
itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)) itemsFuture = pagedItems.withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class))
.selectAsync(item -> { .selectAsync(item -> {
item.setDataset( item.setDataset(
@ -127,7 +124,7 @@ public class DataManagementPlanManager {
} }
CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) -> CompletableFuture countFuture = authItems.countAsync().whenComplete((count, throwable) ->
dataTable.setTotalCount(count) dataTable.setTotalCount(count)
); );
CompletableFuture.allOf(itemsFuture, countFuture).join(); CompletableFuture.allOf(itemsFuture, countFuture).join();
return dataTable; return dataTable;
@ -479,10 +476,13 @@ public class DataManagementPlanManager {
if (dataManagementPlan.getId() != null) { if (dataManagementPlan.getId() != null) {
DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId()); DMP dmp1 = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(dataManagementPlan.getId());
if (!isUserOwnerOfDmp(dmp1, principal)) {
throw new Exception("User not being the creator is not authorized to edit this DMP.");
}
List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset()); List<Dataset> datasetList = new ArrayList<>(dmp1.getDataset());
for (Dataset dataset : datasetList) { for (Dataset dataset : datasetList) {
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null) if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null)
throw new Exception("Dataset Template for Dataest Description is missing from the DMP."); throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
} }
if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
throw new Exception("DMP is finalized, therefore cannot be edited."); throw new Exception("DMP is finalized, therefore cannot be edited.");