CCShareOC.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. //
  2. // CCShareOC.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 13/11/15.
  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 "CCShareOC.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCShareOC ()
  27. {
  28. AppDelegate *appDelegate;
  29. tableCapabilities *capabilities;
  30. }
  31. @end
  32. @implementation CCShareOC
  33. - (instancetype)initWithCoder:(NSCoder *)coder
  34. {
  35. self = [super initWithCoder:coder];
  36. if (self) {
  37. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  38. self.itemsShareWith = [[NSMutableArray alloc] init];
  39. [self initializeForm];
  40. }
  41. return self;
  42. }
  43. - (void)initializeForm
  44. {
  45. XLFormDescriptor *form ;
  46. XLFormSectionDescriptor *section;
  47. XLFormRowDescriptor *row;
  48. form = [XLFormDescriptor formDescriptor];
  49. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  50. // Share Link
  51. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_link_", nil)];
  52. [form addFormSection:section];
  53. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)];
  54. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  55. [section addFormRow:row];
  56. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"shareLinkPermission" rowType:XLFormRowDescriptorTypePicker];
  57. row.height = 70;
  58. [section addFormRow:row];
  59. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"password" rowType:XLFormRowDescriptorTypePassword title:NSLocalizedString(@"_password_", nil)];
  60. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  61. [section addFormRow:row];
  62. capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
  63. if (capabilities != nil && capabilities.versionMajor >= k_nextcloud_version_15_0) {
  64. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"hideDownload" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_hide_download_", nil)];
  65. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  66. [section addFormRow:row];
  67. }
  68. // Expiration date
  69. section = [XLFormSectionDescriptor formSection];
  70. [form addFormSection:section];
  71. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"expirationDate" rowType:XLFormRowDescriptorTypeDate title:NSLocalizedString(@"_date_", nil)];
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  73. row.value = [self tomorrow];
  74. [row.cellConfigAtConfigure setObject:[self tomorrow] forKey:@"minimumDate"];
  75. [section addFormRow:row];
  76. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"expirationDateSwitch" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_expirationdate_", nil)];
  77. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  78. [section addFormRow:row];
  79. // Send Link To
  80. section = [XLFormSectionDescriptor formSection];
  81. [form addFormSection:section];
  82. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sendLinkTo" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_share_link_button_", nil)];
  83. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  84. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  85. row.action.formSelector = @selector(sendLinkTo:);
  86. [section addFormRow:row];
  87. // Sharee
  88. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_share_title_", nil)];
  89. [form addFormSection:section];
  90. section.footerTitle = NSLocalizedString(@"_add_sharee_footer_", nil);
  91. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"findUser" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_add_sharee_", nil)];
  92. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  93. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  94. row.action.formSelector = @selector(shareUserButton:);
  95. [section addFormRow:row];
  96. section = [XLFormSectionDescriptor formSectionWithTitle:@"" sectionOptions:XLFormSectionOptionCanDelete];
  97. [form addFormSection:section];
  98. self.form = form;
  99. }
  100. - (void)viewDidLoad
  101. {
  102. [super viewDidLoad];
  103. self.view.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  104. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  105. self.endButton.tintColor = [UIColor blackColor];
  106. [self reloadData];
  107. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]]) {
  108. self.fileImageView.image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]];
  109. } else {
  110. if (self.metadata.directory)
  111. self.fileImageView.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
  112. else
  113. self.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
  114. }
  115. self.labelTitle.text = self.metadata.fileNameView;
  116. self.labelTitle.textColor = [UIColor blackColor];
  117. self.tableView.tableHeaderView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0.1 / UIScreen.mainScreen.scale)];
  118. line.backgroundColor = self.tableView.separatorColor;
  119. line;
  120. });
  121. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  122. }
  123. #pragma --------------------------------------------------------------------------------------------
  124. #pragma mark ===== Reload Data =====
  125. #pragma --------------------------------------------------------------------------------------------
  126. - (void)reloadData
  127. {
  128. // bugfix
  129. if (!self.serverUrl || !self.metadata) {
  130. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  131. [self dismissViewControllerAnimated:YES completion:nil];
  132. });
  133. return;
  134. }
  135. self.shareLink = [appDelegate.sharesLink objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]];
  136. self.shareUserAndGroup = [appDelegate.sharesUserAndGroup objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]];
  137. self.itemShareLink = [appDelegate.sharesID objectForKey:self.shareLink];
  138. if ([self.shareUserAndGroup length] > 0) self.itemsUserAndGroupLink = [self.shareUserAndGroup componentsSeparatedByString:@","];
  139. else self.itemsUserAndGroupLink = nil;
  140. self.form.delegate = nil;
  141. XLFormRowDescriptor *rowShareLinkSwitch = [self.form formRowWithTag:@"shareLinkSwitch"];
  142. XLFormRowDescriptor *rowShareLinkPermission = [self.form formRowWithTag:@"shareLinkPermission"];
  143. XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
  144. XLFormRowDescriptor *rowHideDownload = [self.form formRowWithTag:@"hideDownload"];
  145. XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
  146. XLFormRowDescriptor *rowExpirationDateSwitch = [self.form formRowWithTag:@"expirationDateSwitch"];
  147. XLFormRowDescriptor *rowSendLinkTo = [self.form formRowWithTag:@"sendLinkTo"];
  148. // Share Link
  149. if ([self.shareLink length] > 0) {
  150. [rowShareLinkSwitch setValue:@1];
  151. rowShareLinkPermission.disabled = @NO;
  152. rowPassword.disabled = @NO;
  153. rowHideDownload.disabled = @NO;
  154. rowExpirationDate.disabled = @NO;
  155. rowExpirationDateSwitch.disabled = @NO;
  156. rowSendLinkTo.disabled = @NO;
  157. } else {
  158. [rowShareLinkSwitch setValue:@0];
  159. rowShareLinkPermission.disabled = @YES;
  160. rowPassword.disabled = @YES;
  161. rowHideDownload.disabled = @YES;
  162. rowExpirationDate.disabled = @YES;
  163. rowExpirationDateSwitch.disabled = @YES;
  164. rowSendLinkTo.disabled = @YES;
  165. }
  166. // Permission
  167. if (self.metadata.directory) {
  168. rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_upload_modify_", nil), NSLocalizedString(@"_share_link_upload_", nil)];
  169. } else {
  170. rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_modify_", nil)];
  171. }
  172. if (self.itemShareLink.permissions > 0 && self.itemShareLink.shareType == shareTypeLink) {
  173. switch (self.itemShareLink.permissions) {
  174. case 1:
  175. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
  176. break;
  177. case 3:
  178. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_modify_", nil);
  179. break;
  180. case 4:
  181. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_", nil);
  182. break;
  183. case 15:
  184. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_modify_", nil);
  185. break;
  186. default:
  187. break;
  188. }
  189. } else {
  190. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
  191. }
  192. // Password
  193. if ([[self.itemShareLink shareWith] length] > 0 && self.itemShareLink.shareType == shareTypeLink)
  194. rowPassword.value = [self.itemShareLink shareWith];
  195. else
  196. rowPassword.value = @"";
  197. // Hide Download
  198. if (self.itemShareLink.hideDownload) rowHideDownload.value = @1;
  199. else rowHideDownload.value = @0;
  200. // Expiration Date
  201. if (self.itemShareLink.expirationDate) {
  202. rowExpirationDateSwitch.value = @1;
  203. NSDate *expireDate;
  204. if (self.itemShareLink.expirationDate) expireDate = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  205. else expireDate = [self tomorrow];
  206. rowExpirationDate.value = expireDate;
  207. } else {
  208. rowExpirationDateSwitch.value = @0;
  209. rowExpirationDate.value = [self tomorrow];
  210. }
  211. // User & Group
  212. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:4];
  213. [section.formRows removeAllObjects];
  214. [self.itemsShareWith removeAllObjects];
  215. if ([self.itemsUserAndGroupLink count] > 0) {
  216. for (NSString *idRemoteShared in self.itemsUserAndGroupLink) {
  217. OCSharedDto *item = [appDelegate.sharesID objectForKey:idRemoteShared];
  218. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:idRemoteShared rowType:XLFormRowDescriptorTypeButton];
  219. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  220. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  221. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"textLabel.textColor"];
  222. row.action.formSelector = @selector(sharePermissionButton:);
  223. if (item.shareType == shareTypeGroup) row.title = [item.shareWithDisplayName stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  224. else row.title = item.shareWithDisplayName;
  225. [section addFormRow:row];
  226. // add users
  227. [self.itemsShareWith addObject:item];
  228. }
  229. section.footerTitle = NSLocalizedString(@"_user_sharee_footer_", nil);
  230. } else {
  231. section.footerTitle = @"";
  232. }
  233. self.form.disabled = NO;
  234. [self.tableView reloadData];
  235. self.form.delegate = self;
  236. }
  237. #pragma --------------------------------------------------------------------------------------------
  238. #pragma mark ===== Change Value & Button =====
  239. #pragma --------------------------------------------------------------------------------------------
  240. - (void)sendLinkTo:(XLFormRowDescriptor *)sender
  241. {
  242. [self deselectFormRow:sender];
  243. NSString *sharedLink = self.itemShareLink.token;
  244. NSString *url;
  245. if ([sharedLink hasPrefix:@"http://"] || [sharedLink hasPrefix:@"https://"]) {
  246. url = sharedLink;
  247. } else {
  248. url = [NSString stringWithFormat:@"%@/%@%@", appDelegate.activeUrl, k_share_link_middle_part_url_after_version_8, sharedLink];
  249. }
  250. NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]];
  251. NSArray *applicationActivities = nil;
  252. UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
  253. activityController.popoverPresentationController.sourceView = self.view;
  254. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  255. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  256. activityController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  257. [self presentViewController:activityController animated:YES completion:nil];
  258. }
  259. - (void)shareUserButton:(XLFormRowDescriptor *)rowDescriptor
  260. {
  261. [self deselectFormRow:rowDescriptor];
  262. self.shareUserOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareUserOC"];
  263. self.shareUserOC.delegate = self;
  264. self.shareUserOC.itemsShareWith = self.itemsShareWith;
  265. self.shareUserOC.isDirectory = self.metadata.directory;
  266. [self.shareUserOC setModalPresentationStyle:UIModalPresentationFormSheet];
  267. [self presentViewController:self.shareUserOC animated:YES completion:NULL];
  268. }
  269. - (void)sharePermissionButton:(XLFormRowDescriptor *)rowDescriptor
  270. {
  271. [self deselectFormRow:rowDescriptor];
  272. self.sharePermissionOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCSharePermissionOC"];
  273. self.sharePermissionOC.delegate = self;
  274. self.sharePermissionOC.idRemoteShared = rowDescriptor.tag;
  275. self.sharePermissionOC.metadata = self.metadata;
  276. self.sharePermissionOC.serverUrl = self.serverUrl;
  277. [self.sharePermissionOC setModalPresentationStyle:UIModalPresentationFormSheet];
  278. [self presentViewController:self.sharePermissionOC animated:YES completion:NULL];
  279. }
  280. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  281. {
  282. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  283. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  284. if ([rowDescriptor.tag isEqualToString:@"shareLinkSwitch"]) {
  285. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  286. if (capabilities.isFilesSharingPublicPasswordEnforced == YES) {
  287. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_enforce_password_protection_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  288. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  289. textField.secureTextEntry = true;
  290. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  291. }];
  292. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  293. [self reloadData];
  294. }];
  295. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  296. NSString *password = alertController.textFields.firstObject.text;
  297. XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
  298. rowPassword.value = password;
  299. [self.delegate share:self.metadata serverUrl:self.serverUrl password:password permission:1 hideDownload:false];
  300. [self disableForm];
  301. }];
  302. okAction.enabled = NO;
  303. [alertController addAction:cancelAction];
  304. [alertController addAction:okAction];
  305. [self presentViewController:alertController animated:YES completion:nil];
  306. } else {
  307. [self.delegate share:self.metadata serverUrl:self.serverUrl password:@"" permission:1 hideDownload:false];
  308. [self disableForm];
  309. }
  310. } else {
  311. // unshare
  312. [self.delegate unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl];
  313. [self disableForm];
  314. }
  315. }
  316. if ([rowDescriptor.tag isEqualToString:@"shareLinkPermission"]) {
  317. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:[self getShareLinkPermission:newValue] hideDownload:false];
  318. [self disableForm];
  319. }
  320. if ([rowDescriptor.tag isEqualToString:@"hideDownload"]) {
  321. BOOL hideDownload = [newValue boolValue];
  322. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:0 hideDownload:hideDownload];
  323. [self disableForm];
  324. }
  325. if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) {
  326. // remove expiration date
  327. if ([[rowDescriptor.value valueData] boolValue] == NO) {
  328. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:@"" permission:0 hideDownload:false];
  329. [self disableForm];
  330. } else {
  331. // new date
  332. XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
  333. NSString *expirationDate = [self convertDateInServerFormat:rowExpirationDate.value];
  334. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  335. [self disableForm];
  336. }
  337. }
  338. }
  339. - (void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath
  340. {
  341. long long idRemoteShared = [formRow.tag longLongValue];
  342. if ([formRow.rowType isEqualToString:@"button"] && idRemoteShared > 0) {
  343. [self.delegate unShare:formRow.tag metadata:self.metadata serverUrl:self.serverUrl];
  344. [self disableForm];
  345. }
  346. }
  347. - (void)beginEditing:(XLFormRowDescriptor *)rowDescriptor
  348. {
  349. [super beginEditing:rowDescriptor];
  350. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  351. self.endButton.enabled = NO;
  352. }
  353. }
  354. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  355. {
  356. [super endEditing:rowDescriptor];
  357. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  358. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  359. NSDate *old = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  360. NSDate *new = rowDescriptor.value;
  361. if ([old compare:new] != NSOrderedSame) {
  362. NSString *expirationDate = [self convertDateInServerFormat:rowDescriptor.value];
  363. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  364. [self disableForm];
  365. }
  366. self.endButton.enabled = YES;
  367. }
  368. if ([rowDescriptor.tag isEqualToString:@"password"]) {
  369. NSString *password = rowDescriptor.value;
  370. // Public Password Enforced Test
  371. if (capabilities.isFilesSharingPublicPasswordEnforced == YES && password == nil) {
  372. [appDelegate messageNotification:@"_share_link_" description:@"_password_obligatory_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  373. [self reloadData];
  374. } else {
  375. // if the password is not changed or is 0 lenght
  376. if ([[self.itemShareLink shareWith] isEqualToString:password]) {
  377. [self reloadData];
  378. } else {
  379. if (password == nil)
  380. password = @"";
  381. if (self.shareLink) {
  382. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:password expirationTime:nil permission:0 hideDownload:false];
  383. [self disableForm];
  384. }
  385. }
  386. }
  387. }
  388. }
  389. #pragma --------------------------------------------------------------------------------------------
  390. #pragma mark ===== Button =====
  391. #pragma --------------------------------------------------------------------------------------------
  392. - (IBAction)endButtonAction:(id)sender
  393. {
  394. [self.tableView endEditing:YES];
  395. // reload delegate
  396. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.metadata.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  397. [self dismissViewControllerAnimated:YES completion:nil];
  398. }
  399. #pragma --------------------------------------------------------------------------------------------
  400. #pragma mark ===== User & Group =====
  401. #pragma --------------------------------------------------------------------------------------------
  402. - (void)getUserAndGroup:(NSString *)find
  403. {
  404. [self.delegate getUserAndGroup:find];
  405. }
  406. - (void)reloadUserAndGroup:(NSArray *)items
  407. {
  408. if (self.shareUserOC)
  409. [self.shareUserOC reloadUserAndGroup:items];
  410. }
  411. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission
  412. {
  413. [self.delegate shareUserAndGroup:user shareeType:shareeType permission:permission metadata:self.metadata serverUrl:self.serverUrl];
  414. }
  415. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload
  416. {
  417. [self.delegate updateShare:share metadata:metadata serverUrl:serverUrl password:password expirationTime:expirationTime permission:permission hideDownload:false];
  418. }
  419. #pragma --------------------------------------------------------------------------------------------
  420. #pragma mark ===== Utility =====
  421. #pragma --------------------------------------------------------------------------------------------
  422. - (void)minCharTextFieldDidChange:(UITextField *)sender
  423. {
  424. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  425. if (alertController) {
  426. UITextField *password = alertController.textFields.firstObject;
  427. UIAlertAction *okAction = alertController.actions.lastObject;
  428. okAction.enabled = password.text.length >= 8;
  429. }
  430. }
  431. -(void)disableForm
  432. {
  433. self.form.disabled = YES;
  434. [self.tableView endEditing:YES];
  435. [self.tableView reloadData];
  436. }
  437. - (NSString *)convertDateInServerFormat:(NSDate *)date {
  438. NSDateFormatter *dateFormatter = [NSDateFormatter new];
  439. [dateFormatter setDateFormat:@"YYYY-MM-dd"];
  440. return [dateFormatter stringFromDate:date];
  441. }
  442. -(NSDate *)tomorrow
  443. {
  444. NSDate *now = [NSDate date];
  445. int daysToAdd = 1;
  446. return [now dateByAddingTimeInterval:60*60*24*daysToAdd];
  447. }
  448. - (NSInteger)getShareLinkPermission:(NSString *)value
  449. {
  450. if ([value isEqualToString:NSLocalizedString(@"_share_link_readonly_", nil)]) {
  451. return 1;
  452. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_modify_", nil)]) {
  453. return 3;
  454. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_", nil)]) {
  455. return 4;
  456. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_modify_", nil)]) {
  457. return 15;
  458. } else {
  459. return 1;
  460. }
  461. }
  462. @end