From ecc3415e3e3c13fa8f73fdd51a88c1ab7087b199 Mon Sep 17 00:00:00 2001 From: masensio Date: Mon, 14 Sep 2015 13:21:00 +0200 Subject: [PATCH] Fix bug: Sharing an already shared file generates the old link --- .../GetRemoteSharesForFileOperation.java | 15 ++++++----- .../lib/resources/shares/ShareUtils.java | 17 ++++++++++-- .../lib/resources/shares/ShareXMLParser.java | 26 ++++++++++++++----- .../lib/resources/status/OwnCloudVersion.java | 10 ++++++- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java index 45e27769..37241844 100644 --- a/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java +++ b/src/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.java @@ -37,6 +37,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; /** * Provide a list shares for a specific file. @@ -90,11 +91,11 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); // Add Parameters to Get Method - get.setQueryString(new NameValuePair[] { - new NameValuePair(PARAM_PATH, mRemoteFilePath), - new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), - new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) - }); + get.setQueryString(new NameValuePair[]{ + new NameValuePair(PARAM_PATH, mRemoteFilePath), + new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), + new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) + }); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); @@ -118,7 +119,9 @@ public class GetRemoteSharesForFileOperation extends RemoteOperation { // Build the link if (( share.getShareLink() == null) && (share.getToken().length() > 0)) { - share.setShareLink(client.getBaseUri() + ShareUtils.SHARING_LINK_TOKEN + + String linkToken = ShareUtils.getSharingToken( + client.getOwnCloudVersion()); + share.setShareLink(client.getBaseUri() + linkToken + share.getToken()); } sharesObjects.add(share); diff --git a/src/com/owncloud/android/lib/resources/shares/ShareUtils.java b/src/com/owncloud/android/lib/resources/shares/ShareUtils.java index d829acc8..8ab9b118 100644 --- a/src/com/owncloud/android/lib/resources/shares/ShareUtils.java +++ b/src/com/owncloud/android/lib/resources/shares/ShareUtils.java @@ -24,6 +24,8 @@ package com.owncloud.android.lib.resources.shares; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; + /** * Contains Constants for Share Operation * @@ -36,7 +38,18 @@ public class ShareUtils { // OCS Route public static final String SHARING_API_PATH ="/ocs/v1.php/apps/files_sharing/api/v1/shares"; - // String to build the link with the token of a share: server address + "/public.php?service=files&t=" + token - public static final String SHARING_LINK_TOKEN = "/public.php?service=files&t="; + // String to build the link with the token of a share: + // server address + "/public.php?service=files&t=" + token + public static final String SHARING_LINK_TOKEN_BEFORE_VERSION_8 = "/public.php?service=files&t="; + public static final String SHARING_LINK_TOKEN_AFTER_VERSION_8= "/index.php/s/"; + + public static String getSharingToken(OwnCloudVersion version){ + if (version!= null && version.isAfter8Version()){ + return SHARING_LINK_TOKEN_AFTER_VERSION_8; + } else { + return SHARING_LINK_TOKEN_BEFORE_VERSION_8; + } + + } } diff --git a/src/com/owncloud/android/lib/resources/shares/ShareXMLParser.java b/src/com/owncloud/android/lib/resources/shares/ShareXMLParser.java index 26f4df07..b19d5772 100644 --- a/src/com/owncloud/android/lib/resources/shares/ShareXMLParser.java +++ b/src/com/owncloud/android/lib/resources/shares/ShareXMLParser.java @@ -126,7 +126,8 @@ public class ShareXMLParser { * @throws XmlPullParserException * @throws IOException */ - public ArrayList parseXMLResponse(InputStream is) throws XmlPullParserException, IOException { + public ArrayList parseXMLResponse(InputStream is) throws XmlPullParserException, + IOException { try { // XMLPullParser @@ -151,7 +152,8 @@ public class ShareXMLParser { * @throws XmlPullParserException * @throws IOException */ - private ArrayList readOCS (XmlPullParser parser) throws XmlPullParserException, IOException { + private ArrayList readOCS (XmlPullParser parser) throws XmlPullParserException, + IOException { ArrayList shares = new ArrayList(); parser.require(XmlPullParser.START_TAG, ns , NODE_OCS); while (parser.next() != XmlPullParser.END_TAG) { @@ -209,7 +211,8 @@ public class ShareXMLParser { * @throws XmlPullParserException * @throws IOException */ - private ArrayList readData(XmlPullParser parser) throws XmlPullParserException, IOException { + private ArrayList readData(XmlPullParser parser) throws XmlPullParserException, + IOException { ArrayList shares = new ArrayList(); OCShare share = null; @@ -259,7 +262,8 @@ public class ShareXMLParser { * @throws XmlPullParserException * @throws IOException */ - private void readElement(XmlPullParser parser, ArrayList shares) throws XmlPullParserException, IOException { + private void readElement(XmlPullParser parser, ArrayList shares) + throws XmlPullParserException, IOException { parser.require(XmlPullParser.START_TAG, ns, NODE_ELEMENT); OCShare share = new OCShare(); @@ -273,7 +277,8 @@ public class ShareXMLParser { String name = parser.getName(); if (name.equalsIgnoreCase(NODE_ELEMENT)) { - // patch to work around servers responding with extra surrounding all the shares on the same file before + // patch to work around servers responding with extra surrounding all + // the shares on the same file before // https://github.com/owncloud/core/issues/6992 was fixed readElement(parser, shares); @@ -327,6 +332,11 @@ public class ShareXMLParser { } else if (name.equalsIgnoreCase(NODE_SHARE_WITH_DISPLAY_NAME)) { share.setSharedWithDisplayName(readNode(parser, NODE_SHARE_WITH_DISPLAY_NAME)); + } else if (name.equalsIgnoreCase(NODE_URL)) { + share.setShareType(ShareType.PUBLIC_LINK); + String value = readNode(parser, NODE_URL); + share.setShareLink(value); + } else { skip(parser); } @@ -344,7 +354,8 @@ public class ShareXMLParser { } private void fixPathForFolder(OCShare share) { - if (share.isFolder() && share.getPath() != null && share.getPath().length() > 0 && !share.getPath().endsWith(FileUtils.PATH_SEPARATOR)) { + if (share.isFolder() && share.getPath() != null && share.getPath().length() > 0 && + !share.getPath().endsWith(FileUtils.PATH_SEPARATOR)) { share.setPath(share.getPath() + FileUtils.PATH_SEPARATOR); } } @@ -357,7 +368,8 @@ public class ShareXMLParser { * @throws XmlPullParserException * @throws IOException */ - private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, IOException{ + private String readNode (XmlPullParser parser, String node) throws XmlPullParserException, + IOException{ parser.require(XmlPullParser.START_TAG, ns, node); String value = readText(parser); //Log_OC.d(TAG, "node= " + node + ", value= " + value); diff --git a/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java b/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java index 9c5a4a82..f3da9f47 100644 --- a/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java +++ b/src/com/owncloud/android/lib/resources/status/OwnCloudVersion.java @@ -42,6 +42,8 @@ public class OwnCloudVersion implements Comparable { public static final int MINIMUM_VERSION_WITH_FORBIDDEN_CHARS = 0x08010000; // 8.1 public static final int MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS = 0x07080000; // 7.8.0 + + public static final int VERSION_8 = 0x08000000; // 8.0 private static final int MAX_DOTS = 3; @@ -129,7 +131,13 @@ public class OwnCloudVersion implements Comparable { return (mVersion >= MINIMUM_VERSION_WITH_FORBIDDEN_CHARS); } - public boolean supportsRemoteThumbnails() { return (mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS); } + public boolean supportsRemoteThumbnails() { + return (mVersion >= MINIMUM_SERVER_VERSION_FOR_REMOTE_THUMBNAILS); + } + + public boolean isAfter8Version(){ + return (mVersion >= VERSION_8); + } }