CCShareOC.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  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. //If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
  226. if (![item.uidOwner isEqualToString:appDelegate.activeUserID]) {
  227. row.disabled = @YES;
  228. }
  229. [section addFormRow:row];
  230. // add users
  231. [self.itemsShareWith addObject:item];
  232. }
  233. section.footerTitle = NSLocalizedString(@"_user_sharee_footer_", nil);
  234. } else {
  235. section.footerTitle = @"";
  236. }
  237. self.form.disabled = NO;
  238. [self.tableView reloadData];
  239. self.form.delegate = self;
  240. }
  241. #pragma --------------------------------------------------------------------------------------------
  242. #pragma mark ===== Change Value & Button =====
  243. #pragma --------------------------------------------------------------------------------------------
  244. - (void)sendLinkTo:(XLFormRowDescriptor *)sender
  245. {
  246. [self deselectFormRow:sender];
  247. NSString *sharedLink = self.itemShareLink.token;
  248. NSString *url;
  249. if ([sharedLink hasPrefix:@"http://"] || [sharedLink hasPrefix:@"https://"]) {
  250. url = sharedLink;
  251. } else {
  252. url = [NSString stringWithFormat:@"%@/%@%@", appDelegate.activeUrl, k_share_link_middle_part_url_after_version_8, sharedLink];
  253. }
  254. NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]];
  255. NSArray *applicationActivities = nil;
  256. UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
  257. activityController.popoverPresentationController.sourceView = self.view;
  258. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  259. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  260. activityController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  261. [self presentViewController:activityController animated:YES completion:nil];
  262. }
  263. - (void)shareUserButton:(XLFormRowDescriptor *)rowDescriptor
  264. {
  265. [self deselectFormRow:rowDescriptor];
  266. self.shareUserOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareUserOC"];
  267. self.shareUserOC.delegate = self;
  268. self.shareUserOC.itemsShareWith = self.itemsShareWith;
  269. self.shareUserOC.isDirectory = self.metadata.directory;
  270. [self.shareUserOC setModalPresentationStyle:UIModalPresentationFormSheet];
  271. [self presentViewController:self.shareUserOC animated:YES completion:NULL];
  272. }
  273. - (void)sharePermissionButton:(XLFormRowDescriptor *)rowDescriptor
  274. {
  275. [self deselectFormRow:rowDescriptor];
  276. self.sharePermissionOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCSharePermissionOC"];
  277. self.sharePermissionOC.delegate = self;
  278. self.sharePermissionOC.idRemoteShared = rowDescriptor.tag;
  279. self.sharePermissionOC.metadata = self.metadata;
  280. self.sharePermissionOC.serverUrl = self.serverUrl;
  281. [self.sharePermissionOC setModalPresentationStyle:UIModalPresentationFormSheet];
  282. [self presentViewController:self.sharePermissionOC animated:YES completion:NULL];
  283. }
  284. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  285. {
  286. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  287. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  288. if ([rowDescriptor.tag isEqualToString:@"shareLinkSwitch"]) {
  289. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  290. if (capabilities.isFilesSharingPublicPasswordEnforced == YES) {
  291. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_enforce_password_protection_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  292. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  293. textField.secureTextEntry = true;
  294. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  295. }];
  296. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  297. [self reloadData];
  298. }];
  299. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  300. NSString *password = alertController.textFields.firstObject.text;
  301. XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
  302. rowPassword.value = password;
  303. [self.delegate share:self.metadata serverUrl:self.serverUrl password:password permission:1 hideDownload:false];
  304. [self disableForm];
  305. }];
  306. okAction.enabled = NO;
  307. [alertController addAction:cancelAction];
  308. [alertController addAction:okAction];
  309. [self presentViewController:alertController animated:YES completion:nil];
  310. } else {
  311. [self.delegate share:self.metadata serverUrl:self.serverUrl password:@"" permission:1 hideDownload:false];
  312. [self disableForm];
  313. }
  314. } else {
  315. // unshare
  316. [self.delegate unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl];
  317. [self disableForm];
  318. }
  319. }
  320. if ([rowDescriptor.tag isEqualToString:@"shareLinkPermission"]) {
  321. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:[self getShareLinkPermission:newValue] hideDownload:false];
  322. [self disableForm];
  323. }
  324. if ([rowDescriptor.tag isEqualToString:@"hideDownload"]) {
  325. BOOL hideDownload = [newValue boolValue];
  326. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:0 hideDownload:hideDownload];
  327. [self disableForm];
  328. }
  329. if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) {
  330. // remove expiration date
  331. if ([[rowDescriptor.value valueData] boolValue] == NO) {
  332. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:@"" permission:0 hideDownload:false];
  333. [self disableForm];
  334. } else {
  335. // new date
  336. XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
  337. NSString *expirationDate = [self convertDateInServerFormat:rowExpirationDate.value];
  338. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  339. [self disableForm];
  340. }
  341. }
  342. }
  343. - (void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath
  344. {
  345. long long idRemoteShared = [formRow.tag longLongValue];
  346. if ([formRow.rowType isEqualToString:@"button"] && idRemoteShared > 0) {
  347. [self.delegate unShare:formRow.tag metadata:self.metadata serverUrl:self.serverUrl];
  348. [self disableForm];
  349. }
  350. }
  351. - (void)beginEditing:(XLFormRowDescriptor *)rowDescriptor
  352. {
  353. [super beginEditing:rowDescriptor];
  354. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  355. self.endButton.enabled = NO;
  356. }
  357. }
  358. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  359. {
  360. [super endEditing:rowDescriptor];
  361. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  362. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  363. NSDate *old = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  364. NSDate *new = rowDescriptor.value;
  365. if ([old compare:new] != NSOrderedSame) {
  366. NSString *expirationDate = [self convertDateInServerFormat:rowDescriptor.value];
  367. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  368. [self disableForm];
  369. }
  370. self.endButton.enabled = YES;
  371. }
  372. if ([rowDescriptor.tag isEqualToString:@"password"]) {
  373. NSString *password = rowDescriptor.value;
  374. // Public Password Enforced Test
  375. if (capabilities.isFilesSharingPublicPasswordEnforced == YES && password == nil) {
  376. [appDelegate messageNotification:@"_share_link_" description:@"_password_obligatory_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  377. [self reloadData];
  378. } else {
  379. // if the password is not changed or is 0 lenght
  380. if ([[self.itemShareLink shareWith] isEqualToString:password]) {
  381. [self reloadData];
  382. } else {
  383. if (password == nil)
  384. password = @"";
  385. if (self.shareLink) {
  386. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:password expirationTime:nil permission:0 hideDownload:false];
  387. [self disableForm];
  388. }
  389. }
  390. }
  391. }
  392. }
  393. #pragma --------------------------------------------------------------------------------------------
  394. #pragma mark ===== Button =====
  395. #pragma --------------------------------------------------------------------------------------------
  396. - (IBAction)endButtonAction:(id)sender
  397. {
  398. [self.tableView endEditing:YES];
  399. // reload delegate
  400. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.metadata.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  401. [self dismissViewControllerAnimated:YES completion:nil];
  402. }
  403. #pragma --------------------------------------------------------------------------------------------
  404. #pragma mark ===== User & Group =====
  405. #pragma --------------------------------------------------------------------------------------------
  406. - (void)getUserAndGroup:(NSString *)find
  407. {
  408. [self.delegate getUserAndGroup:find];
  409. }
  410. - (void)reloadUserAndGroup:(NSArray *)items
  411. {
  412. if (self.shareUserOC)
  413. [self.shareUserOC reloadUserAndGroup:items];
  414. }
  415. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission
  416. {
  417. [self.delegate shareUserAndGroup:user shareeType:shareeType permission:permission metadata:self.metadata serverUrl:self.serverUrl];
  418. }
  419. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload
  420. {
  421. [self.delegate updateShare:share metadata:metadata serverUrl:serverUrl password:password expirationTime:expirationTime permission:permission hideDownload:false];
  422. }
  423. #pragma --------------------------------------------------------------------------------------------
  424. #pragma mark ===== Utility =====
  425. #pragma --------------------------------------------------------------------------------------------
  426. - (void)minCharTextFieldDidChange:(UITextField *)sender
  427. {
  428. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  429. if (alertController) {
  430. UITextField *password = alertController.textFields.firstObject;
  431. UIAlertAction *okAction = alertController.actions.lastObject;
  432. okAction.enabled = password.text.length >= 8;
  433. }
  434. }
  435. -(void)disableForm
  436. {
  437. self.form.disabled = YES;
  438. [self.tableView endEditing:YES];
  439. [self.tableView reloadData];
  440. }
  441. - (NSString *)convertDateInServerFormat:(NSDate *)date {
  442. NSDateFormatter *dateFormatter = [NSDateFormatter new];
  443. [dateFormatter setDateFormat:@"YYYY-MM-dd"];
  444. return [dateFormatter stringFromDate:date];
  445. }
  446. -(NSDate *)tomorrow
  447. {
  448. NSDate *now = [NSDate date];
  449. int daysToAdd = 1;
  450. return [now dateByAddingTimeInterval:60*60*24*daysToAdd];
  451. }
  452. - (NSInteger)getShareLinkPermission:(NSString *)value
  453. {
  454. if ([value isEqualToString:NSLocalizedString(@"_share_link_readonly_", nil)]) {
  455. return 1;
  456. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_modify_", nil)]) {
  457. return 3;
  458. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_", nil)]) {
  459. return 4;
  460. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_modify_", nil)]) {
  461. return 15;
  462. } else {
  463. return 1;
  464. }
  465. }
  466. @end