CCSharePermissionOC.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // CCSharePermissionOC.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 07/03/16.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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. OCSharedDto *shareDto;
  29. }
  30. @end
  31. @implementation CCSharePermissionOC
  32. - (instancetype)initWithCoder:(NSCoder *)coder
  33. {
  34. self = [super initWithCoder:coder];
  35. if (self) {
  36. }
  37. return self;
  38. }
  39. - (void)initializeForm
  40. {
  41. XLFormDescriptor *form ;
  42. XLFormSectionDescriptor *section;
  43. XLFormRowDescriptor *row;
  44. form = [XLFormDescriptor formDescriptor];
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_title_", nil)];
  47. [form addFormSection:section];
  48. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"edit" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_edit_", nil)];
  49. if ([UtilsFramework isAnyPermissionToEdit:shareDto.permissions]) row.value = @1;
  50. else row.value = @0;
  51. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  52. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  53. [section addFormRow:row];
  54. if (shareDto.isDirectory) {
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"create" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_create_", nil)];
  56. row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"];
  57. if ([UtilsFramework isPermissionToCanCreate:shareDto.permissions]) row.value = @1;
  58. else row.value = @0;
  59. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  60. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  61. [section addFormRow:row];
  62. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"change" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_change_", nil)];
  63. row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"];
  64. if ([UtilsFramework isPermissionToCanChange:shareDto.permissions]) row.value = @1;
  65. else row.value = @0;
  66. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  67. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  68. [section addFormRow:row];
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"delete" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_delete_", nil)];
  70. row.hidden = [NSString stringWithFormat:@"$%@==0", @"edit"];
  71. if ([UtilsFramework isPermissionToCanDelete:shareDto.permissions]) row.value = @1;
  72. else row.value = @0;
  73. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  74. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  75. [section addFormRow:row];
  76. }
  77. section = [XLFormSectionDescriptor formSection];
  78. [form addFormSection:section];
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"share" rowType:XLFormRowDescriptorTypeBooleanCheck title:NSLocalizedString(@"_share_permission_share_", nil)];
  80. if ([UtilsFramework isPermissionToCanShare:shareDto.permissions]) row.value = @1;
  81. else row.value = @0;
  82. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  83. [row.cellConfig setObject:[NCBrandColor sharedInstance].brand forKey:@"tintColor"];
  84. [section addFormRow:row];
  85. section = [XLFormSectionDescriptor formSection];
  86. [form addFormSection:section];
  87. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_permission_info_", nil)];
  88. [form addFormSection:section];
  89. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharepath" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_path_", nil)];
  90. row.value = self.metadata.fileNamePrint;
  91. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  92. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  93. [section addFormRow:row];
  94. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharetype" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_type_", nil)];
  95. if (shareDto.shareType == shareTypeUser) row.value = NSLocalizedString(@"_share_permission_typeuser_", nil);
  96. if (shareDto.shareType == shareTypeGroup) row.value = NSLocalizedString(@"_share_permission_typegroup_", nil);
  97. if (shareDto.shareType == shareTypeLink) row.value = NSLocalizedString(@"_share_permission_typepubliclink_", nil);
  98. if (shareDto.shareType == shareTypeRemote) row.value = NSLocalizedString(@"_share_permission_typefederated_", nil);
  99. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  100. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  101. [section addFormRow:row];
  102. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareowner" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_owner_", nil)];
  103. row.value = shareDto.displayNameOwner;
  104. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  105. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  106. [section addFormRow:row];
  107. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharedate" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_date_", nil)];
  108. NSDate *date = [NSDate dateWithTimeIntervalSince1970:shareDto.sharedDate];
  109. row.value = [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
  110. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  111. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  112. [section addFormRow:row];
  113. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharemail" rowType:XLFormRowDescriptorTypeInfo title:NSLocalizedString(@"_share_permission_email_", nil)];
  114. if (shareDto.mailSend == 0) row.value = NSLocalizedString(@"_no_", nil);
  115. if (shareDto.mailSend == 1) row.value = NSLocalizedString(@"_yes_", nil);
  116. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  117. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"detailTextLabel.font"];
  118. [section addFormRow:row];
  119. self.form = form;
  120. }
  121. - (void)viewDidLoad
  122. {
  123. [super viewDidLoad];
  124. self.view.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  125. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  126. self.endButton.tintColor = [NCBrandColor sharedInstance].brand;
  127. self.tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  128. shareDto = [app.sharesID objectForKey:self.idRemoteShared];
  129. [self initializeForm];
  130. }
  131. #pragma --------------------------------------------------------------------------------------------
  132. #pragma mark ===== Button =====
  133. #pragma --------------------------------------------------------------------------------------------
  134. - (IBAction)endButtonAction:(id)sender
  135. {
  136. NSInteger permission;
  137. XLFormRowDescriptor *rowEdit = [self.form formRowWithTag:@"edit"];
  138. XLFormRowDescriptor *rowCreate = [self.form formRowWithTag:@"create"];
  139. XLFormRowDescriptor *rowChange = [self.form formRowWithTag:@"change"];
  140. XLFormRowDescriptor *rowDelete = [self.form formRowWithTag:@"delete"];
  141. XLFormRowDescriptor *rowShare = [self.form formRowWithTag:@"share"];
  142. if ([rowEdit.value boolValue] == 0)
  143. permission = [UtilsFramework getPermissionsValueByCanEdit:NO andCanCreate:NO andCanChange:NO andCanDelete:NO andCanShare:[rowShare.value boolValue] andIsFolder:shareDto.isDirectory];
  144. else
  145. 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];
  146. if (permission != shareDto.permissions)
  147. [self.delegate updateShare:self.idRemoteShared metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:permission];
  148. [self dismissViewControllerAnimated:YES completion:nil];
  149. }
  150. @end