Marino Faggiana 6 жил өмнө
parent
commit
bd44874151

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.h

@@ -618,7 +618,7 @@ typedef enum {
  *
  *
  * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  * @warning to create the full URL to share the file on a link we have to atatch the token to: http://www.myowncloudserver.com/public.php?service=files&t=572d48de3814c90117fbca6442f2f3b2
  */
  */
-- (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password
+- (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password andPermission:(NSInteger)permission
                    onCommunication:(OCCommunication *)sharedOCCommunication
                    onCommunication:(OCCommunication *)sharedOCCommunication
                     successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
                     successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
                     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
                     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;

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

@@ -896,7 +896,7 @@
     }];
     }];
 }
 }
 
 
-- (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password
+- (void) shareFileOrFolderByServer: (NSString *) serverPath andFileOrFolderPath: (NSString *) filePath andPassword:(NSString *)password andPermission:(NSInteger)permission
                    onCommunication:(OCCommunication *)sharedOCCommunication
                    onCommunication:(OCCommunication *)sharedOCCommunication
                     successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
                     successRequest:(void(^)(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer)) successRequest
                     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
                     failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
@@ -908,7 +908,7 @@
     request = [self getRequestWithCredentials:request];
     request = [self getRequestWithCredentials:request];
     
     
     
     
-    [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath andPassword:password onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
+    [request shareByLinkFileOrFolderByServer:serverPath andPath:filePath andPassword:password andPermission:permission onCommunication:sharedOCCommunication success:^(NSHTTPURLResponse *response, id responseObject) {
         
         
         NSData *responseData = (NSData*) responseObject;
         NSData *responseData = (NSData*) responseObject;
         
         

+ 1 - 1
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.h

@@ -348,7 +348,7 @@ extern NSString * _Nullable OCWebDAVModificationDateKey;
  * @param failure A block callback, to be fired upon the failure of the request, with two arguments: the request operation and error.
  * @param failure A block callback, to be fired upon the failure of the request, with two arguments: the request operation and error.
  *
  *
  */
  */
-- (void)shareByLinkFileOrFolderByServer:(NSString * _Nonnull)serverPath andPath:(NSString * _Nonnull) filePath andPassword:(NSString * _Nonnull)password
+- (void)shareByLinkFileOrFolderByServer:(NSString * _Nonnull)serverPath andPath:(NSString * _Nonnull) filePath andPassword:(NSString * _Nonnull)password andPermission:(NSInteger)permission
                         onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication
                         onCommunication:(OCCommunication * _Nonnull)sharedOCCommunication
                                 success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success
                                 success:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id _Nonnull))success
                                 failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull))failure;
                                 failure:(void(^ _Nonnull)(NSHTTPURLResponse * _Nonnull, id  _Nullable responseObject, NSError * _Nonnull))failure;

+ 2 - 2
iOSClient/Library/OCCommunicationLib/OCWebDavClient/OCWebDAVClient.m

@@ -605,7 +605,7 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     [operation resume];
     [operation resume];
 }
 }
 
 
-- (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString *) filePath andPassword:(NSString *)password
+- (void)shareByLinkFileOrFolderByServer:(NSString *)serverPath andPath:(NSString *) filePath andPassword:(NSString *)password andPermission:(NSInteger)permission
                         onCommunication:(OCCommunication *)sharedOCCommunication
                         onCommunication:(OCCommunication *)sharedOCCommunication
                                 success:(void(^)(NSHTTPURLResponse *, id))success
                                 success:(void(^)(NSHTTPURLResponse *, id))success
                                 failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *))failure {
                                 failure:(void(^)(NSHTTPURLResponse *, id  _Nullable responseObject, NSError *))failure {
@@ -614,7 +614,7 @@ NSString const *OCWebDAVModificationDateKey	= @"modificationdate";
     _requestMethod = @"POST";
     _requestMethod = @"POST";
     
     
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
     NSMutableURLRequest *request = [self sharedRequestWithMethod:_requestMethod path:serverPath parameters:nil timeout:k_timeout_webdav];
-    _postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=3&password=%@",filePath,password];
+    _postStringForShare = [NSString stringWithFormat: @"path=%@&shareType=3&permissions=%lu&password=%@",filePath,permission,password];
     [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
     [request setHTTPBody:[_postStringForShare dataUsingEncoding:NSUTF8StringEncoding]];
     
     
     OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];
     OCHTTPRequestOperation *operation = [self mr_operationWithRequest:request onCommunication:sharedOCCommunication success:success failure:failure];

+ 2 - 1
iOSClient/Main/CCMain.m

@@ -2145,7 +2145,7 @@
     [self tableViewReloadData];
     [self tableViewReloadData];
 }
 }
 
 
-- (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password
+- (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password permission:(NSInteger)permission
 {
 {
     CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
     CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
     
     
@@ -2153,6 +2153,7 @@
     metadataNet.fileID = metadata.fileID;
     metadataNet.fileID = metadata.fileID;
     metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl];
     metadataNet.fileName = [CCUtility returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl activeUrl:appDelegate.activeUrl];
     metadataNet.fileNameView = metadata.fileNameView;
     metadataNet.fileNameView = metadata.fileNameView;
+    metadataNet.sharePermission = permission;
     metadataNet.password = password;
     metadataNet.password = password;
     metadataNet.selector = selectorShare;
     metadataNet.selector = selectorShare;
     metadataNet.serverUrl = serverUrl;
     metadataNet.serverUrl = serverUrl;

+ 1 - 1
iOSClient/Networking/OCNetworking.m

@@ -1253,7 +1253,7 @@
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setCredentialsWithUser:_activeUser andUserID:_activeUserID andPassword:_activePassword];
     [communication setUserAgent:[CCUtility getUserAgent]];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
     
-    [communication shareFileOrFolderByServer:[_activeUrl stringByAppendingString:@"/"] andFileOrFolderPath:[_metadataNet.fileName encodeString:NSUTF8StringEncoding] andPassword:[_metadataNet.password encodeString:NSUTF8StringEncoding] onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
+    [communication shareFileOrFolderByServer:[_activeUrl stringByAppendingString:@"/"] andFileOrFolderPath:[_metadataNet.fileName encodeString:NSUTF8StringEncoding] andPassword:[_metadataNet.password encodeString:NSUTF8StringEncoding] andPermission:_metadataNet.sharePermission onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *token, NSString *redirectedServer) {
         
         
         [self readShareServer];
         [self readShareServer];
         
         

+ 1 - 1
iOSClient/Share/CCShareOC.h

@@ -59,7 +59,7 @@
 
 
 @protocol CCShareOCDelegate
 @protocol CCShareOCDelegate
 
 
-- (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password;
+- (void)share:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password permission:(NSInteger)permission;
 - (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl;
 - (void)unShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl;
 - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission;
 - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission;
 
 

+ 62 - 6
iOSClient/Share/CCShareOC.m

@@ -61,14 +61,20 @@
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_link_", nil)];
     section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_link_", nil)];
     [form addFormSection:section];
     [form addFormSection:section];
 
 
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypePassword title:NSLocalizedString(@"_password_", nil)];
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [section addFormRow:row];
     [section addFormRow:row];
     
     
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)];
+    
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkPermission" rowType:XLFormRowDescriptorTypePicker];
+    row.height = 70;
+    [section addFormRow:row];
+    
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypePassword title:NSLocalizedString(@"_password_", nil)];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
     [section addFormRow:row];
     [section addFormRow:row];
     
     
+   
     // Expiration date
     // Expiration date
     
     
     section = [XLFormSectionDescriptor formSection];
     section = [XLFormSectionDescriptor formSection];
@@ -173,20 +179,46 @@
 
 
     self.form.delegate = nil;
     self.form.delegate = nil;
 
 
-    XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
     XLFormRowDescriptor *rowShareLinkSwitch = [self.form formRowWithTag:@"shareLinkSwitch"];
     XLFormRowDescriptor *rowShareLinkSwitch = [self.form formRowWithTag:@"shareLinkSwitch"];
+    XLFormRowDescriptor *rowShareLinkPermission = [self.form formRowWithTag:@"shareLinkPermission"];
+    XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
     
     
     XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
     XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
     XLFormRowDescriptor *rowExpirationDateSwitch = [self.form formRowWithTag:@"expirationDateSwitch"];
     XLFormRowDescriptor *rowExpirationDateSwitch = [self.form formRowWithTag:@"expirationDateSwitch"];
     
     
     XLFormRowDescriptor *rowSendLinkTo = [self.form formRowWithTag:@"sendLinkTo"];
     XLFormRowDescriptor *rowSendLinkTo = [self.form formRowWithTag:@"sendLinkTo"];
 
 
-    // Passoword
+    // Password
     if ([[self.itemShareLink shareWith] length] > 0 && self.itemShareLink.shareType == shareTypeLink)
     if ([[self.itemShareLink shareWith] length] > 0 && self.itemShareLink.shareType == shareTypeLink)
         rowPassword.value = [self.itemShareLink shareWith];
         rowPassword.value = [self.itemShareLink shareWith];
     else
     else
         rowPassword.value = @"";
         rowPassword.value = @"";
 
 
+    // Permission
+    if (self.metadata.directory) {
+        rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_upload_modify_", nil), NSLocalizedString(@"_share_link_upload_", nil)];
+    } else {
+        rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_modify_", nil)];
+    }
+    if (self.itemShareLink.permissions > 0 && self.itemShareLink.shareType == shareTypeLink) {
+        switch (self.itemShareLink.permissions) {
+            case 1:
+                rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
+                break;
+            case 3:
+                rowShareLinkPermission.value = NSLocalizedString(@"_share_link_modify_", nil);
+                break;
+            case 4:
+                rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_", nil);
+                break;
+            case 15:
+                rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_modify_", nil);
+                break;
+            default:
+                break;
+        }
+    }
+    
     // Share Link
     // Share Link
     if ([self.shareLink length] > 0) {
     if ([self.shareLink length] > 0) {
         
         
@@ -338,10 +370,9 @@
         
         
         if ([[rowDescriptor.value valueData] boolValue] == YES) {
         if ([[rowDescriptor.value valueData] boolValue] == YES) {
             
             
-            // share
             XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
             XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
             
             
-            [self.delegate share:self.metadata serverUrl:self.serverUrl password:rowPassword.value];
+            [self.delegate share:self.metadata serverUrl:self.serverUrl password:rowPassword.value permission:[self getShareLinkPermission]];
             [self disableForm];
             [self disableForm];
             
             
         } else {
         } else {
@@ -352,6 +383,14 @@
         }
         }
     }
     }
     
     
+    if ([rowDescriptor.tag isEqualToString:@"shareLinkPermission"]) {
+        
+        XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
+
+        [self.delegate share:self.metadata serverUrl:self.serverUrl password:rowPassword.value permission:[self getShareLinkPermission]];
+        [self disableForm];
+    }
+    
     if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) {
     if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) {
         
         
         // remove expiration date
         // remove expiration date
@@ -512,4 +551,21 @@
     return [now dateByAddingTimeInterval:60*60*24*daysToAdd];
     return [now dateByAddingTimeInterval:60*60*24*daysToAdd];
 }
 }
 
 
+- (NSInteger)getShareLinkPermission
+{
+    XLFormRowDescriptor *row = [self.form formRowWithTag:@"shareLinkPermission"];
+
+    if ([row.value isEqualToString:NSLocalizedString(@"_share_link_readonly_", nil)]) {
+        return 1;
+    } else if ([row.value isEqualToString:NSLocalizedString(@"_share_link_modify_", nil)]) {
+        return 3;
+    } else if ([row.value isEqualToString:NSLocalizedString(@"_share_link_upload_", nil)]) {
+        return 4;
+    } else if ([row.value isEqualToString:NSLocalizedString(@"_share_link_upload_modify_", nil)]) {
+        return 15;
+    } else {
+        return 1;
+    }
+}
+
 @end
 @end

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

@@ -457,6 +457,10 @@
 "_share_permission_owner_"          = "Owner";
 "_share_permission_owner_"          = "Owner";
 "_share_permission_date_"           = "Date";
 "_share_permission_date_"           = "Date";
 "_share_permission_email_"          = "Notification via email";
 "_share_permission_email_"          = "Notification via email";
+"_share_link_readonly_"             = "Read only";
+"_share_link_modify_"               = "Allow editing";
+"_share_link_upload_"               = "File drop (upload only)";
+"_share_link_upload_modify_"        = "Allow upload and editing";
 
 
 // ShareInfoCMOC
 // ShareInfoCMOC