Procházet zdrojové kódy

add API lock unlock e2e

Marino Faggiana před 7 roky
rodič
revize
b5b439b49f

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

@@ -2264,6 +2264,8 @@
     
     [request lockEndToEndFolderEncrypted:serverPath onCommunication:sharedOCComunication success:^(NSHTTPURLResponse *response, id responseObject) {
         
+        NSData *responseData = (NSData*) responseObject;
+
         NSString *token;
         
         //Return success

+ 1 - 7
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -1007,10 +1007,7 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
 - (void)lockEndToEndFolderEncrypted:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCCommunication success:(void(^)(NSHTTPURLResponse *operation, id response))success
                             failure:(void(^)(NSHTTPURLResponse *operation, id  _Nullable responseObject, NSError *error))failure{
     
-    _requestMethod = @"PUT";
-    
-    NSString *jsonQuery = [NSString stringWithFormat:@"?format=json"];
-    serverPath = [serverPath stringByAppendingString:jsonQuery];
+    _requestMethod = @"POST";
     
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];
     
@@ -1025,9 +1022,6 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     
     _requestMethod = @"DELETE";
     
-    NSString *jsonQuery = [NSString stringWithFormat:@"?format=json"];
-    serverPath = [serverPath stringByAppendingString:jsonQuery];
-    
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil];
     
     OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];

+ 29 - 2
iOSClient/Main/CCMain.m

@@ -4007,7 +4007,7 @@
         }
 
 #ifdef DEBUG
-        if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory && [CCUtility isEndToEndEnabled:app.activeAccount]) {
+        if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
             
             [actionSheet addButtonWithTitle:@"Mark as encrypted"
                                       image:[UIImage imageNamed:@"actionSheetCrypto"]
@@ -4020,7 +4020,7 @@
                                     }];
         }
         
-        if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES) && !lockDirectory && [CCUtility isEndToEndEnabled:app.activeAccount]) {
+        if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
             
             [actionSheet addButtonWithTitle:@"Delete mark as encrypted"
                                       image:[UIImage imageNamed:@"actionSheetCrypto"]
@@ -4032,6 +4032,33 @@
                                         [app.endToEndInterface deletemarkEndToEndFolderEncrypted:_metadata];
                                     }];
         }
+        
+        if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
+            
+            [actionSheet addButtonWithTitle:@"Lock file"
+                                      image:[UIImage imageNamed:@"actionSheetCrypto"]
+                            backgroundColor:[UIColor whiteColor]
+                                     height: 50.0
+                                       type:AHKActionSheetButtonTypeEncrypted
+                                    handler:^(AHKActionSheet *as) {
+                                        
+                                        [app.endToEndInterface lockEndToEndFolderEncrypted:_metadata];
+                                    }];
+        }
+        
+        if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
+            
+            [actionSheet addButtonWithTitle:@"Unlock file"
+                                      image:[UIImage imageNamed:@"actionSheetCrypto"]
+                            backgroundColor:[UIColor whiteColor]
+                                     height: 50.0
+                                       type:AHKActionSheetButtonTypeEncrypted
+                                    handler:^(AHKActionSheet *as) {
+                                        
+                                        [app.endToEndInterface unlockEndToEndFolderEncrypted:_metadata];
+                                    }];
+        }
+        
 #endif
         
         if (!([_metadata.fileName isEqualToString:autoUploadFileName] == YES && [serverUrl isEqualToString:autoUploadDirectory] == YES)) {

+ 58 - 0
iOSClient/Security/NCEntoToEndInterface.swift

@@ -389,6 +389,64 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
         appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
     }
     
+    // --------------------------------------------------------------------------------------------
+    // MARK: Mark/Delete Encrypted Folder
+    // --------------------------------------------------------------------------------------------
+
+    func unlockEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
+        print("E2E lock file  success")
+    }
+    
+    func unlockEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
+        
+        // Unauthorized
+        if (errorCode == kOCErrorServerUnauthorized) {
+            appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
+        }
+        
+        if (errorCode != kOCErrorServerUnauthorized) {
+            
+            appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+        }
+    }
+    
+    @objc func unlockEndToEndFolderEncrypted(_ metadata: tableMetadata) {
+        
+        let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
+        
+        metadataNet.action = actionUnlockEndToEndFolderEncrypted;
+        metadataNet.fileID = metadata.fileID;
+        
+        appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+    }
+    
+    func lockEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
+        print("E2E lock file  success")
+    }
+    
+    func lockEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
+        
+        // Unauthorized
+        if (errorCode == kOCErrorServerUnauthorized) {
+            appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
+        }
+        
+        if (errorCode != kOCErrorServerUnauthorized) {
+            
+            appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
+        }
+    }
+    
+    @objc func lockEndToEndFolderEncrypted(_ metadata: tableMetadata) {
+        
+        let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
+        
+        metadataNet.action = actionLockEndToEndFolderEncrypted;
+        metadataNet.fileID = metadata.fileID;
+        
+        appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
+    }
+    
     // --------------------------------------------------------------------------------------------
     // MARK: Form
     // --------------------------------------------------------------------------------------------