diff --git a/library/src/androidTest/java/com/owncloud/android/GetCapabilitiesRemoteOperationIT.java b/library/src/androidTest/java/com/owncloud/android/GetCapabilitiesRemoteOperationIT.java index 422b7ee72..a603f0f57 100644 --- a/library/src/androidTest/java/com/owncloud/android/GetCapabilitiesRemoteOperationIT.java +++ b/library/src/androidTest/java/com/owncloud/android/GetCapabilitiesRemoteOperationIT.java @@ -26,6 +26,13 @@ */ package com.owncloud.android; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.status.CapabilityBooleanType; import com.owncloud.android.lib.resources.status.E2EVersion; @@ -36,13 +43,6 @@ import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - /** * Class to test GetRemoteCapabilitiesOperation */ @@ -123,6 +123,25 @@ public void testGetRemoteCapabilitiesOperationEtagWithNextcloudClient() { checkCapability(capability, nextcloudClient.getUserId()); } + @Test + public void testFilesSharing() { + // get capabilities + RemoteOperationResult result = new GetCapabilitiesRemoteOperation().execute(nextcloudClient); + assertTrue(result.isSuccess()); + assertTrue(result.getData() != null && result.getData().size() == 1); + + OCCapability capability = (OCCapability) result.getData().get(0); + + // share by mail + if (capability.getVersion().isNewerOrEqual(NextcloudVersion.nextcloud_23)) { + assertTrue(capability.getFilesSharingByMail().isTrue()); + assertTrue(capability.getFilesSharingByMailSendPasswordByMail().isTrue()); + } else { + assertTrue("Value is:" + capability.getFilesSharingByMail(), capability.getFilesSharingByMail().isTrue()); + assertTrue(capability.getFilesSharingByMailSendPasswordByMail().isUnknown()); + } + } + private void checkCapability(OCCapability capability, String userId) { assertTrue(capability.getActivity().isTrue()); assertTrue(capability.getFilesSharingApiEnabled().isTrue()); diff --git a/library/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java b/library/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java index 777daa630..45fa40df4 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java +++ b/library/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java @@ -74,6 +74,7 @@ public class GetCapabilitiesRemoteOperation extends RemoteOperation { private static final String NODE_CORE = "core"; private static final String NODE_FILES_SHARING = "files_sharing"; + private static final String NODE_SHARE_BY_MAIL = "sharebymail"; private static final String NODE_PUBLIC = "public"; private static final String NODE_PASSWORD = "password"; private static final String NODE_ASK_FOR_OPTIONAL_PASSWORD = "askForOptionalPassword"; @@ -89,6 +90,8 @@ public class GetCapabilitiesRemoteOperation extends RemoteOperation { private static final String PROPERTY_POLLINTERVAL = "pollinterval"; + private static final String PROPERTY_SEND_PASSWORD_BY_MAIL = "send_password_by_mail"; + private static final String PROPERTY_MAJOR = "major"; private static final String PROPERTY_MINOR = "minor"; private static final String PROPERTY_MICRO = "micro"; @@ -422,6 +425,23 @@ private OCCapability parseResponse(String response) throws JSONException { capability.setFilesSharingFederationIncoming(CapabilityBooleanType.fromBooleanValue( respFederation.getBoolean(PROPERTY_INCOMING))); } + + if (respFilesSharing.has(NODE_SHARE_BY_MAIL)) { + JSONObject respByMail = respFilesSharing.getJSONObject(NODE_SHARE_BY_MAIL); + capability.setFilesSharingByMail(CapabilityBooleanType.fromBooleanValue( + respByMail.getBoolean(PROPERTY_ENABLED))); + if (respByMail.has(PROPERTY_SEND_PASSWORD_BY_MAIL)) { + capability.setFilesSharingByMailSendPasswordByMail( + CapabilityBooleanType.fromBooleanValue( + respByMail.getBoolean(PROPERTY_SEND_PASSWORD_BY_MAIL))); + } else { + capability.setFilesSharingByMailSendPasswordByMail(CapabilityBooleanType.UNKNOWN); + } + } else { + capability.setFilesSharingByMail(CapabilityBooleanType.UNKNOWN); + capability.setFilesSharingByMailSendPasswordByMail(CapabilityBooleanType.UNKNOWN); + } + Log_OC.d(TAG, "*** Added " + NODE_FILES_SHARING); } diff --git a/library/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.kt b/library/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.kt index bcc5b7dac..7de7282d8 100644 --- a/library/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.kt +++ b/library/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.kt @@ -68,6 +68,8 @@ class OCCapability { var filesSharingResharing = CapabilityBooleanType.UNKNOWN var filesSharingFederationOutgoing = CapabilityBooleanType.UNKNOWN var filesSharingFederationIncoming = CapabilityBooleanType.UNKNOWN + var filesSharingByMail = CapabilityBooleanType.UNKNOWN + var filesSharingByMailSendPasswordByMail = CapabilityBooleanType.UNKNOWN // Files var filesBigFileChunking = CapabilityBooleanType.UNKNOWN