Browse Source

fix wipe NC 17

marinofaggiana 5 years ago
parent
commit
3922b94062

+ 1 - 1
iOSClient/AppDelegate.h

@@ -145,7 +145,7 @@
 
 // Setting Account
 - (void)settingActiveAccount:(NSString *)activeAccount activeUrl:(NSString *)activeUrl activeUser:(NSString *)activeUser activeUserID:(NSString *)activeUserID activePassword:(NSString *)activePassword;
-- (void)deleteAccount:(NSString *)account withChangeUser:(BOOL)withChangeUser;
+- (void)deleteAccount:(NSString *)account wipe:(BOOL)wipe;
 
 // Quick Actions - ShotcutItem
 - (void)configDynamicShortcutItems;

+ 6 - 4
iOSClient/AppDelegate.m

@@ -383,7 +383,7 @@ PKPushRegistry *pushRegistry;
     [CCNetworking sharedNetworking].delegate = [NCNetworkingMain sharedInstance];
 }
 
-- (void)deleteAccount:(NSString *)account withChangeUser:(BOOL)withChangeUser
+- (void)deleteAccount:(NSString *)account wipe:(BOOL)wipe
 {
     [self unsubscribingNextcloudServerPushNotification:account url:self.activeUrl withSubscribing:false];
     [self settingActiveAccount:nil activeUrl:nil activeUser:nil activeUserID:nil activePassword:nil];
@@ -395,15 +395,17 @@ PKPushRegistry *pushRegistry;
     [CCUtility setCertificateError:account error:false];
     [CCUtility setPassword:account password:nil];
        
-    if (withChangeUser) {
+    if (wipe) {
         NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];
         if ([listAccount count] > 0) {
-            tableAccount *newAccount = listAccount[0];
-            [self settingActiveAccount:newAccount.account activeUrl:newAccount.url activeUser:newAccount.user activeUserID:newAccount.userID activePassword:[CCUtility getPassword:newAccount.account]];
+            NSString *newAccount = listAccount[0];
+            tableAccount *tableAccount = [[NCManageDatabase sharedInstance] setAccountActive:newAccount];
+            [self settingActiveAccount:newAccount activeUrl:tableAccount.url activeUser:tableAccount.user activeUserID:tableAccount.userID activePassword:[CCUtility getPassword:tableAccount.account]];
             [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil userInfo:nil];
         } else {
             [self openLoginView:self.window.rootViewController delegate:self loginType:k_login_Add_Forced selector:k_intro_login];
         }
+        [self messageNotification:account description:@"_wipe_account_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:k_CCErrorInternalError];
     }
 }
 

+ 2 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -3128,7 +3128,8 @@
         
         if (jsongParsed && jsongParsed.allKeys > 0) {
             
-            successRequest(response, false, request.redirectedServer);
+            BOOL wipe = [jsongParsed valueForKey:@"wipe"];
+            successRequest(response, wipe, request.redirectedServer);
             
         } else {
             

+ 2 - 0
iOSClient/Networking/OCNetworking.h

@@ -29,6 +29,8 @@
 
 + (OCNetworking *)sharedManager;
 
+@property BOOL checkRemoteWipeInProgress;
+
 #pragma mark ===== OCCommunication =====
 
 - (OCCommunication *)sharedOCCommunication;

+ 26 - 15
iOSClient/Networking/OCNetworking.m

@@ -37,6 +37,7 @@
     {
         if (!sharedManager) {
             sharedManager = [OCNetworking new];
+            sharedManager.checkRemoteWipeInProgress = false;
         }
         return sharedManager;
     }
@@ -2325,23 +2326,33 @@
 
 - (void)checkRemoteWipe:(NSString *)account
 {
-    tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:account];
-    if (capabilities != nil && capabilities.versionMajor >= k_nextcloud_version_17_0) {
-        [[OCNetworking sharedManager] getRemoteWipeStatusWithAccount:account completion:^(NSString *account, BOOL wipe, NSString *message, NSInteger errorCode) {
-            
-            if (wipe) {
+    @synchronized(self) {
+        if (self.checkRemoteWipeInProgress) {
+            return;
+        } else {
+            self.checkRemoteWipeInProgress = true;
+        }
+        
+        tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:account];
+        if (capabilities != nil && capabilities.versionMajor >= k_nextcloud_version_17_0 && [CCUtility getPassword:account] != nil) {
+            [[OCNetworking sharedManager] getRemoteWipeStatusWithAccount:account completion:^(NSString *account, BOOL wipe, NSString *message, NSInteger errorCode) {
                 
-#ifndef EXTENSION
-                [(AppDelegate *)[[UIApplication sharedApplication] delegate] deleteAccount:account withChangeUser:true];
-#endif
-            } else {
+                if (wipe) {
+                    
+    #ifndef EXTENSION
+                    [(AppDelegate *)[[UIApplication sharedApplication] delegate] deleteAccount:account withChangeUser:true];
+    #endif
+                } else {
+                    
+                    [CCUtility setPassword:account password:nil];
+                }
                 
-                [CCUtility setPassword:account password:nil];
-            }
-        }];
-    } else {
-        
-        [CCUtility setPassword:account password:nil];
+                self.checkRemoteWipeInProgress = false;
+            }];
+        } else if ([CCUtility getPassword:account] != nil) {
+            
+            [CCUtility setPassword:account password:nil];
+        }
     }
 }
 

+ 1 - 1
iOSClient/Settings/CCManageAccount.m

@@ -437,7 +437,7 @@
         NSString *account = tableAccount.account;
         
         if (account) {
-            [appDelegate deleteAccount:account withChangeUser:false];
+            [appDelegate deleteAccount:account wipe:false];
         }
         
         NSArray *listAccount = [[NCManageDatabase sharedInstance] getAccounts];

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -108,6 +108,7 @@
 "_details_"                 = "Details";
 "_dark_mode_"               = "Dark mode";
 "_screen_"                  = "Screen";
+"_wipe_account_"            = "Account wiped from server";
 
 // App