diff --git a/src/androidTest/java/com/owncloud/android/GetCapabilitiesIT.java b/src/androidTest/java/com/owncloud/android/GetCapabilitiesIT.java index aeaf7fba52..c6b09100b0 100644 --- a/src/androidTest/java/com/owncloud/android/GetCapabilitiesIT.java +++ b/src/androidTest/java/com/owncloud/android/GetCapabilitiesIT.java @@ -26,20 +26,21 @@ */ 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.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.GetCapabilitiesRemoteOperation; +import com.owncloud.android.lib.resources.status.NextcloudVersion; import com.owncloud.android.lib.resources.status.OCCapability; import com.owncloud.android.lib.resources.status.OwnCloudVersion; 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.assertSame; -import static org.junit.Assert.assertTrue; - /** * Class to test GetRemoteCapabilitiesOperation */ @@ -120,6 +121,25 @@ public void testGetRemoteCapabilitiesOperationEtagWithNextcloudClient() { checkCapability(capability); } + @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.Companion.getNextcloud_23())) { + assertTrue(capability.getFilesSharingByMail().isTrue()); + assertTrue(capability.getFilesSharingByMailSendPasswordByMail().isTrue()); + } else { + assertTrue(capability.getFilesSharingByMail().isUnknown()); + assertTrue(capability.getFilesSharingByMailSendPasswordByMail().isUnknown()); + } + } + private void checkCapability(OCCapability capability) { assertTrue(capability.getActivity().isTrue()); assertTrue(capability.getFilesSharingApiEnabled().isTrue()); diff --git a/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java b/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java index 1633561e95..8087f09660 100644 --- a/src/main/java/com/owncloud/android/lib/resources/status/GetCapabilitiesRemoteOperation.java +++ b/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"; @@ -406,6 +409,19 @@ 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))); + capability.setFilesSharingByMailSendPasswordByMail( + CapabilityBooleanType.fromBooleanValue( + respByMail.getBoolean(PROPERTY_SEND_PASSWORD_BY_MAIL))); + } else { + capability.setFilesSharingByMail(CapabilityBooleanType.UNKNOWN); + capability.setFilesSharingByMailSendPasswordByMail(CapabilityBooleanType.UNKNOWN); + } + Log_OC.d(TAG, "*** Added " + NODE_FILES_SHARING); } diff --git a/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.java b/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.java index 720451e7a4..e18605bfcd 100644 --- a/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.java +++ b/src/main/java/com/owncloud/android/lib/resources/status/OCCapability.java @@ -78,6 +78,8 @@ public class OCCapability { private CapabilityBooleanType filesSharingResharing; private CapabilityBooleanType filesSharingFederationOutgoing; private CapabilityBooleanType filesSharingFederationIncoming; + private CapabilityBooleanType filesSharingByMail; + private CapabilityBooleanType filesSharingByMailSendPasswordByMail; // Files private CapabilityBooleanType filesBigFileChunking;