Add default values for Acl API (#1032)

This commit is contained in:
Yi (Alan) Wang 2018-03-13 16:06:29 -07:00 committed by GitHub
parent 701824cc2a
commit 42e3cb1efb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 12 deletions

View File

@ -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");

View File

@ -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)));