Search in sources :

Example 1 with NotEnoughPermissionsException

use of nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException in project timbuctoo by HuygensING.

the class DataSetRepository method removeDataSet.

public void removeDataSet(String ownerId, String dataSetName, User user) throws IOException, NotEnoughPermissionsException, DataSetDoesNotExistException {
    try {
        DataSet dataSet = dataSetMap.get(ownerId).get(dataSetName);
        if (dataSet == null) {
            LOG.warn("DataSet '{}' of user with id '{}' does not exist (anymore).", dataSetName, ownerId);
            throw new DataSetDoesNotExistException(dataSetName, ownerId);
        }
        String combinedId = dataSet.getMetadata().getCombinedId();
        if (!permissionFetcher.getPermissions(user, dataSet.getMetadata()).contains(Permission.ADMIN)) {
            throw new NotEnoughPermissionsException(String.format("User '%s' is not allowed to remove dataset '%s'", user.getDisplayName(), combinedId));
        }
        dataSet.stop();
        dataSetMap.get(ownerId).remove(dataSetName);
        permissionFetcher.removeAuthorizations(combinedId);
    } catch (PermissionFetchingException e) {
        throw new IOException(e);
    }
    // remove folder
    dataStorage.getDataSetStorage(ownerId, dataSetName).clear();
}
Also used : PermissionFetchingException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) NotEnoughPermissionsException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException) IOException(java.io.IOException)

Example 2 with NotEnoughPermissionsException

use of nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException in project timbuctoo by HuygensING.

the class DeleteDataSetMutation method get.

@Override
public Object get(DataFetchingEnvironment environment) {
    String combinedId = environment.getArgument("dataSetId");
    Tuple<String, String> userAndDataSet = DataSetMetaData.splitCombinedId(combinedId);
    User user = MutationHelpers.getUser(environment);
    try {
        dataSetRepository.removeDataSet(userAndDataSet.getLeft(), userAndDataSet.getRight(), user);
        return new RemovedDataSet(combinedId);
    } catch (IOException e) {
        LOG.error("Data set deletion exception", e);
        throw new RuntimeException("Data set could not be deleted");
    } catch (NotEnoughPermissionsException e) {
        throw new RuntimeException("You do not have enough permissions");
    } catch (DataSetRepository.DataSetDoesNotExistException e) {
        throw new RuntimeException(e.getMessage());
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) NotEnoughPermissionsException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 NotEnoughPermissionsException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.NotEnoughPermissionsException)2 DataSetRepository (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1 PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)1