CCSharePermissionOC.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // CCSharePermissionOC.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/03/16.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCSharePermissionOC.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCSharePermissionOC ()
  27. {
  28. AppDelegate *appDelegate;
  29. OCSharedDto *shareDto;
  30. }
  31. @end
  32. @implementation CCSharePermissionOC
  33. - (instancetype)initWithCoder:(NSCoder *)coder
  34. {
  35. self = [super initWithCoder:coder];
  36. if (self) {
  37. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  38. }
  39. return self;
  40. }
  41. - (void)initializeForm
  42. {
  43. XLFormDescriptor *form ;
  44. XLFormSectionDescriptor *section;
  45. XLFormRowDescriptor *row;
  46. form = [XLFormDescriptor formDescriptor];
  47. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  48. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)];
  49. [form addFormSection:section];
  50. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"edit" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_edit_", nil)];
  51. if ([UtilsFramework isAnyPermissionToEdit:shareDto.permissions]) row.value = @1;
  52. else row.value = @0;
  53. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  54. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  55. [section addFormRow:row];
  56. if (shareDto.isDirectory) {
  57. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"create" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_", nil)];
  58. row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"];
  59. if ([UtilsFramework isPermissionToCanCreate:shareDto.permissions]) row.value = @1;
  60. else row.value = @0;
  61. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  62. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  63. [section addFormRow:row];
  64. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"change" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_change_", nil)];
  65. row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"];
  66. if ([UtilsFramework isPermissionToCanChange:shareDto.permissions]) row.value = @1;
  67. else row.value = @0;
  68. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  69. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  70. [section addFormRow:row];
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)];
  72. row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"];
  73. if ([UtilsFramework isPermissionToCanDelete:shareDto.permissions]) row.value = @1;
  74. else row.value = @0;
  75. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  76. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  77. [section addFormRow:row];
  78. }
  79. section = [XLFormSectionDescriptor formSection];
  80. [form addFormSection:section];
  81. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)];
  82. if ([UtilsFramework isPermissionToCanShare:shareDto.permissions]) row.value = @1;
  83. else row.value = @0;
  84. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  85. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"tintColor"];
  86. [section addFormRow:row];
  87. section = [XLFormSectionDescriptor formSection];
  88. [form addFormSection:section];
  89. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)];
  90. [form addFormSection:section];
  91. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharepath" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_path_", nil)];
  92. row.value = self.metadata.fileNameView;
  93. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  94. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  95. [section addFormRow:row];
  96. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)];
  97. if (shareDto.shareType == shareTypeUser) row.value = NSLocalizedString(@"_share_permission_typeuser_", nil);
  98. if (shareDto.shareType == shareTypeGroup) row.value = NSLocalizedString(@"_share_permission_typegroup_", nil);
  99. if (shareDto.shareType == shareTypeLink) row.value = NSLocalizedString(@"_share_permission_typepubliclink_", nil);
  100. if (shareDto.shareType == shareTypeRemote) row.value = NSLocalizedString(@"_share_permission_typefederated_", nil);
  101. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  102. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  103. [section addFormRow:row];
  104. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareowner" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_owner_", nil)];
  105. row.value = shareDto.displayNameOwner;
  106. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  107. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  108. [section addFormRow:row];
  109. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharedate" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_date_", nil)];
  110. NSDate *date = [NSDate dateWithTimeIntervalSince1970:shareDto.sharedDate];
  111. row.value = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
  112. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  113. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  114. [section addFormRow:row];
  115. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharemail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_email_", nil)];
  116. if (shareDto.mailSend == 0) row.value = NSLocalizedString(@"_no_", nil);
  117. if (shareDto.mailSend == 1) row.value = NSLocalizedString(@"_yes_", nil);
  118. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  119. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  120. [section addFormRow:row];
  121. self.form = form;
  122. }
  123. - (void)viewDidLoad
  124. {
  125. [super viewDidLoad];
  126. self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  127. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  128. self.endButton.tintColor = [UIColor blackColor];
  129. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  130. shareDto = [appDelegate.sharesID objectForKey:self.idRemoteShared];
  131. [self initializeForm];
  132. }
  133. #pragma --------------------------------------------------------------------------------------------
  134. #pragma mark ===== Networking =====
  135. #pragma --------------------------------------------------------------------------------------------
  136. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload
  137. {
  138. [[OCNetworking sharedManager] shareUpdateAccount:appDelegate.activeAccount shareID:[share integerValue] password:password permission:permission expirationTime:expirationTime hideDownload:hideDownload completion:^(NSString *account, NSString *message, NSInteger errorCode) {
  139. if (errorCode != 0) {
  140. [appDelegate messageNotification:@"_share_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  141. }
  142. [self dismissViewControllerAnimated:YES completion:nil];
  143. }];
  144. }
  145. #pragma --------------------------------------------------------------------------------------------
  146. #pragma mark ===== Button =====
  147. #pragma --------------------------------------------------------------------------------------------
  148. - (IBAction)endButtonAction:(id)sender
  149. {
  150. NSInteger permission;
  151. XLFormRowDescriptor *rowEdit = [self.form formRowWithTag:@"edit"];
  152. XLFormRowDescriptor *rowCreate = [self.form formRowWithTag:@"create"];
  153. XLFormRowDescriptor *rowChange = [self.form formRowWithTag:@"change"];
  154. XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"];
  155. XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"];
  156. if ([rowEdit.value boolValue] == 0)
  157. permission = [UtilsFramework getPermissionsValueByCanEdit:NO andCanCreate:NO andCanChange:NO andCanDelete:NO andCanShare:[rowShare.value boolValue] andIsFolder:shareDto.isDirectory];
  158. else
  159. permission = [UtilsFramework getPermissionsValueByCanEdit:[rowEdit.value boolValue] andCanCreate:[rowCreate.value boolValue] andCanChange:[rowChange.value boolValue] andCanDelete:[rowDelete.value boolValue] andCanShare:[rowShare.value boolValue] andIsFolder:shareDto.isDirectory];
  160. if (permission != shareDto.permissions) {
  161. [self updateShare:self.idRemoteShared metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:permission hideDownload:false];
  162. } else {
  163. [self dismissViewControllerAnimated:YES completion:nil];
  164. }
  165. }
  166. @end