From 42e3cb1efbf98915729402360d88fb91a59dc4d1 Mon Sep 17 00:00:00 2001 From: "Yi (Alan) Wang" Date: Tue, 13 Mar 2018 16:06:29 -0700 Subject: [PATCH] Add default values for Acl API (#1032) --- .../src/main/java/wherehows/dao/table/AclDao.java | 5 ----- .../app/controllers/api/v2/Dataset.java | 13 ++++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/wherehows-dao/src/main/java/wherehows/dao/table/AclDao.java b/wherehows-dao/src/main/java/wherehows/dao/table/AclDao.java index f09e655f8d..23a5aa2d0d 100644 --- a/wherehows-dao/src/main/java/wherehows/dao/table/AclDao.java +++ b/wherehows-dao/src/main/java/wherehows/dao/table/AclDao.java @@ -28,11 +28,6 @@ public class AclDao { throw new UnsupportedOperationException("Not implemented yet"); } - public void addUserToDatasetAcl(@Nonnull String datasetUrn, @Nonnull String user, @Nonnull String justification) - throws Exception { - throw new UnsupportedOperationException("Not implemented yet"); - } - public void addUserToDatasetAcl(@Nonnull String datasetUrn, @Nonnull String user, @Nullable String accessType, @Nonnull String justification, @Nullable Long expiresAt) throws Exception { throw new UnsupportedOperationException("Not implemented yet"); diff --git a/wherehows-frontend/app/controllers/api/v2/Dataset.java b/wherehows-frontend/app/controllers/api/v2/Dataset.java index 734d7ec2fe..1bb393e306 100644 --- a/wherehows-frontend/app/controllers/api/v2/Dataset.java +++ b/wherehows-frontend/app/controllers/api/v2/Dataset.java @@ -65,6 +65,8 @@ public class Dataset extends Controller { private static final int _DEFAULT_PAGE_SIZE = 20; + private static final long _DEFAULT_JIT_ACL_PERIOD = 48 * 3600; // 48 hour in seconds + private static final JsonNode _EMPTY_RESPONSE = Json.newObject(); private Dataset() { @@ -353,19 +355,16 @@ public class Dataset extends Controller { JsonNode record = request().body().asJson(); - String accessType = record.hasNonNull("accessType") ? record.get("accessType").asText() : null; - Long expiresAt = record.hasNonNull("expiresAt") ? record.get("expiresAt").asLong() : null; + String accessType = record.hasNonNull("accessType") ? record.get("accessType").asText() : "r"; // default read + Long expiresAt = record.hasNonNull("expiresAt") ? record.get("expiresAt").asLong() + : System.currentTimeMillis() / 1000 + _DEFAULT_JIT_ACL_PERIOD; // default now + 48h, in seconds if (!record.hasNonNull("businessJustification")) { return Promise.promise(() -> badRequest(errorResponse("Missing business justification"))); } String businessJustification = record.get("businessJustification").asText(); try { - if (accessType == null) { - ACL_DAO.addUserToDatasetAcl(datasetUrn, username, businessJustification); - } else { - ACL_DAO.addUserToDatasetAcl(datasetUrn, username, accessType, businessJustification, expiresAt); - } + ACL_DAO.addUserToDatasetAcl(datasetUrn, username, accessType, businessJustification, expiresAt); } catch (Exception e) { Logger.error("Add user to ACL error", e); return Promise.promise(() -> internalServerError(errorResponse(e)));