Skip to content

Commit

Permalink
Expose share by mail
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Nov 3, 2021
1 parent d9e5f55 commit 1ebf304
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/androidTest/java/com/owncloud/android/GetCapabilitiesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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("Value is:" + capability.getFilesSharingByMail(), capability.getFilesSharingByMail().isTrue());
assertTrue(capability.getFilesSharingByMailSendPasswordByMail().isUnknown());
}
}

private void checkCapability(OCCapability capability) {
assertTrue(capability.getActivity().isTrue());
assertTrue(capability.getFilesSharingApiEnabled().isTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -406,6 +409,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ebf304

Please sign in to comment.