瀏覽代碼

Merge pull request #1013 from owncloud/keep_permanent_redirections

Keep permanent redirections
masensio 9 年之前
父節點
當前提交
0b567b9713

+ 0 - 2
.travis.yml

@@ -1,8 +1,6 @@
 language: android
 android:
   components:
-    - platform-tools
-    - tools
     - build-tools-20.0.0
     - android-19
 before_install:

+ 1 - 1
owncloud-android-library

@@ -1 +1 @@
-Subproject commit e48aa9c30447d67b0f8ee2054e1fc826108fc5ec
+Subproject commit 639cb7eacdae0b4b6dddbd8f446d8d42eb2617b5

+ 17 - 0
src/com/owncloud/android/authentication/AccountUtils.java

@@ -250,4 +250,21 @@ public class AccountUtils {
     }
 
 
+    public static String trimWebdavSuffix(String url) {
+        while(url.endsWith("/")) {
+            url = url.substring(0, url.length() - 1);
+        }
+        int pos = url.lastIndexOf(WEBDAV_PATH_4_0_AND_LATER);
+        if (pos >= 0) {
+            url = url.substring(0, pos);
+
+        } else {
+            pos = url.lastIndexOf(ODAV_PATH);
+            if (pos >= 0) {
+                url = url.substring(0, pos);
+            }
+        }
+        return url;
+    }
+
 }

+ 12 - 6
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -785,8 +785,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             Intent getServerInfoIntent = new Intent();
             getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);
             getServerInfoIntent.putExtra(
-                OperationsService.EXTRA_SERVER_URL, 
-                normalizeUrlSuffix(uri)
+                    OperationsService.EXTRA_SERVER_URL,
+                    normalizeUrlSuffix(uri)
             );
             if (mOperationsServiceBinder != null) {
                 mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getServerInfoIntent);
@@ -999,7 +999,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 
             if ( mAction == ACTION_CREATE) {
                 mUsernameInput.setText(username);
-                success = createAccount();
+                success = createAccount(result);
             } else {
 
                 if (!mUsernameInput.getText().toString().equals(username)) {
@@ -1351,8 +1351,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             Log_OC.d(TAG, "Successful access - time to save the account");
 
             boolean success = false;
+
             if (mAction == ACTION_CREATE) {
-                success = createAccount();
+                success = createAccount(result);
 
             } else {
                 try {
@@ -1449,13 +1450,18 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * 
      * TODO Decide how to name the OAuth accounts
      */
-    private boolean createAccount() {
+    private boolean createAccount(RemoteOperationResult authResult) {
         /// create and save new ownCloud account
         boolean isOAuth = AccountTypeUtils.
                 getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);
         boolean isSaml =  AccountTypeUtils.
                 getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);
 
+        String lastPermanentLocation = authResult.getLastPermanentLocation();
+        if (lastPermanentLocation != null) {
+            mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation);
+        }
+
         Uri uri = Uri.parse(mServerInfo.mBaseUrl);
         String username = mUsernameInput.getText().toString().trim();
         if (isOAuth) {
@@ -1513,7 +1519,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             /// add user data to the new account; TODO probably can be done in the last parameter 
             //      addAccountExplicitly, or in KEY_USERDATA
             mAccountMgr.setUserData(
-                    mAccount, Constants.KEY_OC_VERSION,    mServerInfo.mVersion.getVersion()
+                    mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()
             );
             mAccountMgr.setUserData(
                     mAccount, Constants.KEY_OC_BASE_URL,   mServerInfo.mBaseUrl

+ 7 - 2
src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java

@@ -24,10 +24,10 @@ import android.content.Context;
 import android.net.Uri;
 import android.os.AsyncTask;
 
-import com.owncloud.android.MainApp;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientFactory;
 import com.owncloud.android.lib.common.OwnCloudCredentials;
+import com.owncloud.android.lib.common.network.RedirectionPath;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 
@@ -62,7 +62,6 @@ public class AuthenticatorAsyncTask  extends AsyncTask<Object, Void, RemoteOpera
             // Client
             Uri uri = Uri.parse(url);
             OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, true);
-
             client.setCredentials(credentials);
 
             // Operation
@@ -73,6 +72,12 @@ public class AuthenticatorAsyncTask  extends AsyncTask<Object, Void, RemoteOpera
             );
             result = operation.execute(client);
 
+            if (operation.wasRedirected()) {
+                RedirectionPath redirectionPath = operation.getRedirectionPath();
+                String permanentLocation = redirectionPath.getLastPermanentLocation();
+                result.setLastPermanentLocation(permanentLocation);
+            }
+
         } else {
             result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
         }