فهرست منبع

Update ErrorMessageAdapter class to generate appropiate error messages for operations failed due to lack of permissions (ResultCode.FORBIDDEN)

jabarros 11 سال پیش
والد
کامیت
a28fa921c9
3فایلهای تغییر یافته به همراه38 افزوده شده و 6 حذف شده
  1. 1 1
      owncloud-android-library
  2. 7 0
      res/values/strings.xml
  3. 30 5
      src/com/owncloud/android/utils/ErrorMessageAdapter.java

+ 1 - 1
owncloud-android-library

@@ -1 +1 @@
-Subproject commit 5ebf81e26ed0827359aa468fb813353656b7cf27
+Subproject commit 7636d9e0373bafd63dfd79c032ef927d87d0872e

+ 7 - 0
res/values/strings.xml

@@ -270,4 +270,11 @@
 	<string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
 	<string name="network_host_not_available">The operation couldn\'t be completed, server is unavailable</string>
 	
+	<string name="forbidden_permissions">You do not have permissions %s</string>
+	<string name="forbidden_permissions_rename">to rename this file</string>
+	<string name="forbidden_permissions_delete">to delete this file</string>
+	<string name="share_link_forbidden_permissions">to share this file</string>
+	<string name="unshare_link_forbidden_permissions">to unshare this file</string>
+	<string name="forbidden_permissions_create">to create the file</string>
+
 </resources>

+ 30 - 5
src/com/owncloud/android/utils/ErrorMessageAdapter.java

@@ -20,7 +20,9 @@ package com.owncloud.android.utils;
 
 import java.io.File;
 import java.net.SocketTimeoutException;
+
 import org.apache.commons.httpclient.ConnectTimeoutException;
+
 import android.content.res.Resources;
 
 import com.owncloud.android.R;
@@ -91,7 +93,11 @@ public class ErrorMessageAdapter {
                 message = res.getString(R.string.remove_success_msg);
                 
             } else {
-                if (isNetworkError(result.getCode())) {
+                if (result.getCode().equals(ResultCode.FORBIDDEN)) {
+                    // Error --> No permissions
+                    message = String.format(res.getString(R.string.forbidden_permissions),
+                            res.getString(R.string.forbidden_permissions_delete));
+                } else if (isNetworkError(result.getCode())) {
                     message = getErrorMessage(result, res);
                     
                 } else {
@@ -102,10 +108,15 @@ public class ErrorMessageAdapter {
         } else if (operation instanceof RenameFileOperation) {
             if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
                 message = res.getString(R.string.rename_local_fail_msg);
-                
-            } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
+
+            } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
+                // Error --> No permissions
+                message = String.format(res.getString(R.string.forbidden_permissions),
+                        res.getString(R.string.forbidden_permissions_rename));
+
+            } else if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) {
                 message = res.getString(R.string.filename_forbidden_characters);
-                
+
             } else if (isNetworkError(result.getCode())) {
                 message = getErrorMessage(result, res);
                 
@@ -121,7 +132,11 @@ public class ErrorMessageAdapter {
         } else if (operation instanceof CreateFolderOperation) {
             if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
                 message = res.getString(R.string.filename_forbidden_characters);
-                
+
+            } else if (result.getCode().equals(ResultCode.FORBIDDEN)) {
+                message = String.format(res.getString(R.string.forbidden_permissions),
+                        res.getString(R.string.forbidden_permissions_create));
+
             } else if (isNetworkError(result.getCode())) {
                 message = getErrorMessage(result, res);
                 
@@ -132,6 +147,11 @@ public class ErrorMessageAdapter {
             if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {        // Error --> SHARE_NOT_FOUND
                 message = res.getString(R.string.share_link_file_no_exist);
                 
+            } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
+                // Error --> No permissions
+                message = String.format(res.getString(R.string.forbidden_permissions),
+                        res.getString(R.string.share_link_forbidden_permissions));
+
             } else if (isNetworkError(result.getCode())) {
                 message = getErrorMessage(result, res);
                 
@@ -145,6 +165,11 @@ public class ErrorMessageAdapter {
             if (result.getCode() == ResultCode.SHARE_NOT_FOUND)  {        // Error --> SHARE_NOT_FOUND
                 message = res.getString(R.string.unshare_link_file_no_exist);
                 
+            } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) {
+                // Error --> No permissions
+                message = String.format(res.getString(R.string.forbidden_permissions),
+                        res.getString(R.string.unshare_link_forbidden_permissions));
+
             } else if (isNetworkError(result.getCode())) {
                 message = getErrorMessage(result, res);