Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecc3415e authored by masensio's avatar masensio
Browse files

Fix bug: Sharing an already shared file generates the old link

parent 30df7c33
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -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.  
@@ -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);
+15 −2
Original line number Diff line number Diff line
@@ -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;
        }

    }
    
}
+19 −7
Original line number Diff line number Diff line
@@ -126,7 +126,8 @@ public class ShareXMLParser {
	 * @throws XmlPullParserException
	 * @throws IOException
	 */
	public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException, IOException {
	public ArrayList<OCShare> parseXMLResponse(InputStream is) throws XmlPullParserException,
			IOException {

		try {
			// XMLPullParser
@@ -151,7 +152,8 @@ public class ShareXMLParser {
	 * @throws XmlPullParserException
	 * @throws IOException
	 */
	private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException, IOException {
	private ArrayList<OCShare> readOCS (XmlPullParser parser) throws XmlPullParserException,
			IOException {
		ArrayList<OCShare> shares = new ArrayList<OCShare>();
		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<OCShare> readData(XmlPullParser parser) throws XmlPullParserException, IOException {
	private ArrayList<OCShare> readData(XmlPullParser parser) throws XmlPullParserException,
			IOException {
		ArrayList<OCShare> shares = new ArrayList<OCShare>();
		OCShare share = null;

@@ -259,7 +262,8 @@ public class ShareXMLParser {
	 * @throws XmlPullParserException
	 * @throws IOException
	 */
	private void readElement(XmlPullParser parser, ArrayList<OCShare> shares) throws XmlPullParserException, IOException {
	private void readElement(XmlPullParser parser, ArrayList<OCShare> 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 <element> surrounding all the shares on the same file before
				// patch to work around servers responding with extra <element> 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);
+9 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {

    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;
    
    // format is in version
@@ -129,7 +131,13 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {
        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);
    }
    
    
}