CCSharePermissionOC.m 9.3 KB

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