CCShareOC.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. XLFormRowDescriptor *rowFindUser = [self.form formRowWithTag:@"findUser"];
  149. // Share Link
  150. if ([self.shareLink length] > 0) {
  151. [rowShareLinkSwitch setValue:@1];
  152. rowShareLinkPermission.disabled = @NO;
  153. rowPassword.disabled = @NO;
  154. rowHideDownload.disabled = @NO;
  155. rowExpirationDate.disabled = @NO;
  156. rowExpirationDateSwitch.disabled = @NO;
  157. rowSendLinkTo.disabled = @NO;
  158. } else {
  159. [rowShareLinkSwitch setValue:@0];
  160. rowShareLinkPermission.disabled = @YES;
  161. rowPassword.disabled = @YES;
  162. rowHideDownload.disabled = @YES;
  163. rowExpirationDate.disabled = @YES;
  164. rowExpirationDateSwitch.disabled = @YES;
  165. rowSendLinkTo.disabled = @YES;
  166. }
  167. // Permission
  168. if (self.metadata.directory) {
  169. rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_upload_modify_", nil), NSLocalizedString(@"_share_link_upload_", nil)];
  170. } else {
  171. rowShareLinkPermission.selectorOptions = @[NSLocalizedString(@"_share_link_readonly_", nil), NSLocalizedString(@"_share_link_modify_", nil)];
  172. }
  173. if (self.itemShareLink.permissions > 0 && self.itemShareLink.shareType == shareTypeLink) {
  174. switch (self.itemShareLink.permissions) {
  175. case 1:
  176. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
  177. break;
  178. case 3:
  179. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_modify_", nil);
  180. break;
  181. case 4:
  182. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_", nil);
  183. break;
  184. case 15:
  185. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_upload_modify_", nil);
  186. break;
  187. default:
  188. break;
  189. }
  190. } else {
  191. rowShareLinkPermission.value = NSLocalizedString(@"_share_link_readonly_", nil);
  192. }
  193. // Password
  194. if ([[self.itemShareLink shareWith] length] > 0 && self.itemShareLink.shareType == shareTypeLink)
  195. rowPassword.value = [self.itemShareLink shareWith];
  196. else
  197. rowPassword.value = @"";
  198. // Hide Download
  199. if (self.itemShareLink.hideDownload) rowHideDownload.value = @1;
  200. else rowHideDownload.value = @0;
  201. // Expiration Date
  202. if (self.itemShareLink.expirationDate) {
  203. rowExpirationDateSwitch.value = @1;
  204. NSDate *expireDate;
  205. if (self.itemShareLink.expirationDate) expireDate = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  206. else expireDate = [self tomorrow];
  207. rowExpirationDate.value = expireDate;
  208. } else {
  209. rowExpirationDateSwitch.value = @0;
  210. rowExpirationDate.value = [self tomorrow];
  211. }
  212. // User & Group
  213. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:4];
  214. [section.formRows removeAllObjects];
  215. [self.itemsShareWith removeAllObjects];
  216. if ([self.itemsUserAndGroupLink count] > 0) {
  217. for (NSString *idRemoteShared in self.itemsUserAndGroupLink) {
  218. OCSharedDto *item = [appDelegate.sharesID objectForKey:idRemoteShared];
  219. XLFormRowDescriptor *row = [XLFormRowDescriptor formRowDescriptorWithTag:idRemoteShared rowType:XLFormRowDescriptorTypeButton];
  220. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  221. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  222. [row.cellConfig setObject:[NCBrandColor sharedInstance].brandElement forKey:@"textLabel.textColor"];
  223. row.action.formSelector = @selector(sharePermissionButton:);
  224. if (item.shareType == shareTypeGroup) row.title = [item.shareWithDisplayName stringByAppendingString:NSLocalizedString(@"_user_is_group_", nil)];
  225. else row.title = item.shareWithDisplayName;
  226. //If the initiator or the recipient is not the current user, show the list of sharees without any options to edit it.
  227. if (![item.uidOwner isEqualToString:appDelegate.activeUserID] && ![item.uidFileOwner isEqualToString:appDelegate.activeUserID]) {
  228. row.disabled = @YES;
  229. }
  230. [section addFormRow:row];
  231. // add users
  232. [self.itemsShareWith addObject:item];
  233. // shared with you by
  234. self.labelSharedWithYouBy.text = [NSString stringWithFormat:@"%@ %@", NSLocalizedString(@"_shared_with_you_by_", nil), item.displayNameFileOwner];
  235. }
  236. section.footerTitle = NSLocalizedString(@"_user_sharee_footer_", nil);
  237. } else {
  238. section.footerTitle = @"";
  239. }
  240. // canShare
  241. BOOL canShare = [self.metadata.permissions containsString:k_permission_can_share];
  242. if (! canShare) {
  243. rowShareLinkSwitch.disabled = @YES;
  244. rowShareLinkPermission.disabled = @YES;
  245. rowPassword.disabled = @YES;
  246. rowHideDownload.disabled = @YES;
  247. rowExpirationDate.disabled = @YES;
  248. rowExpirationDateSwitch.disabled = @YES;
  249. rowSendLinkTo.disabled = @YES;
  250. rowFindUser.disabled = @YES;
  251. XLFormSectionDescriptor *section = [self.form formSectionAtIndex:4];
  252. [section.formRows removeAllObjects];
  253. }
  254. self.form.disabled = NO;
  255. [self.tableView reloadData];
  256. self.form.delegate = self;
  257. }
  258. #pragma --------------------------------------------------------------------------------------------
  259. #pragma mark ===== Change Value & Button =====
  260. #pragma --------------------------------------------------------------------------------------------
  261. - (void)sendLinkTo:(XLFormRowDescriptor *)sender
  262. {
  263. [self deselectFormRow:sender];
  264. NSString *sharedLink = self.itemShareLink.token;
  265. NSString *url;
  266. if ([sharedLink hasPrefix:@"http://"] || [sharedLink hasPrefix:@"https://"]) {
  267. url = sharedLink;
  268. } else {
  269. url = [NSString stringWithFormat:@"%@/%@%@", appDelegate.activeUrl, k_share_link_middle_part_url_after_version_8, sharedLink];
  270. }
  271. NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]];
  272. NSArray *applicationActivities = nil;
  273. UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
  274. activityController.popoverPresentationController.sourceView = self.view;
  275. NSIndexPath *indexPath = [self.form indexPathOfFormRow:sender];
  276. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  277. activityController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  278. [self presentViewController:activityController animated:YES completion:nil];
  279. }
  280. - (void)shareUserButton:(XLFormRowDescriptor *)rowDescriptor
  281. {
  282. [self deselectFormRow:rowDescriptor];
  283. self.shareUserOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCShareUserOC"];
  284. self.shareUserOC.delegate = self;
  285. self.shareUserOC.itemsShareWith = self.itemsShareWith;
  286. self.shareUserOC.isDirectory = self.metadata.directory;
  287. [self.shareUserOC setModalPresentationStyle:UIModalPresentationFormSheet];
  288. [self presentViewController:self.shareUserOC animated:YES completion:NULL];
  289. }
  290. - (void)sharePermissionButton:(XLFormRowDescriptor *)rowDescriptor
  291. {
  292. [self deselectFormRow:rowDescriptor];
  293. self.sharePermissionOC = [[UIStoryboard storyboardWithName:@"CCShare" bundle:nil] instantiateViewControllerWithIdentifier:@"CCSharePermissionOC"];
  294. self.sharePermissionOC.delegate = self;
  295. self.sharePermissionOC.idRemoteShared = rowDescriptor.tag;
  296. self.sharePermissionOC.metadata = self.metadata;
  297. self.sharePermissionOC.serverUrl = self.serverUrl;
  298. [self.sharePermissionOC setModalPresentationStyle:UIModalPresentationFormSheet];
  299. [self presentViewController:self.sharePermissionOC animated:YES completion:NULL];
  300. }
  301. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  302. {
  303. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  304. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  305. if ([rowDescriptor.tag isEqualToString:@"shareLinkSwitch"]) {
  306. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  307. if (capabilities.isFilesSharingPublicPasswordEnforced == YES) {
  308. __weak __typeof(UIAlertController) *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_enforce_password_protection_",nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
  309. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  310. textField.secureTextEntry = true;
  311. [textField addTarget:self action:@selector(minCharTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  312. }];
  313. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_",nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  314. [self reloadData];
  315. }];
  316. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  317. NSString *password = alertController.textFields.firstObject.text;
  318. XLFormRowDescriptor *rowPassword = [self.form formRowWithTag:@"password"];
  319. rowPassword.value = password;
  320. [self.delegate share:self.metadata serverUrl:self.serverUrl password:password permission:1 hideDownload:false];
  321. [self disableForm];
  322. }];
  323. okAction.enabled = NO;
  324. [alertController addAction:cancelAction];
  325. [alertController addAction:okAction];
  326. [self presentViewController:alertController animated:YES completion:nil];
  327. } else {
  328. [self.delegate share:self.metadata serverUrl:self.serverUrl password:@"" permission:1 hideDownload:false];
  329. [self disableForm];
  330. }
  331. } else {
  332. // unshare
  333. [self.delegate unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl];
  334. [self disableForm];
  335. }
  336. }
  337. if ([rowDescriptor.tag isEqualToString:@"shareLinkPermission"]) {
  338. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:[self getShareLinkPermission:newValue] hideDownload:false];
  339. [self disableForm];
  340. }
  341. if ([rowDescriptor.tag isEqualToString:@"hideDownload"]) {
  342. BOOL hideDownload = [newValue boolValue];
  343. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:nil permission:0 hideDownload:hideDownload];
  344. [self disableForm];
  345. }
  346. if ([rowDescriptor.tag isEqualToString:@"expirationDateSwitch"]) {
  347. // remove expiration date
  348. if ([[rowDescriptor.value valueData] boolValue] == NO) {
  349. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:@"" permission:0 hideDownload:false];
  350. [self disableForm];
  351. } else {
  352. // new date
  353. XLFormRowDescriptor *rowExpirationDate = [self.form formRowWithTag:@"expirationDate"];
  354. NSString *expirationDate = [self convertDateInServerFormat:rowExpirationDate.value];
  355. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  356. [self disableForm];
  357. }
  358. }
  359. }
  360. - (void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath
  361. {
  362. long long idRemoteShared = [formRow.tag longLongValue];
  363. if ([formRow.rowType isEqualToString:@"button"] && idRemoteShared > 0) {
  364. [self.delegate unShare:formRow.tag metadata:self.metadata serverUrl:self.serverUrl];
  365. [self disableForm];
  366. }
  367. }
  368. - (void)beginEditing:(XLFormRowDescriptor *)rowDescriptor
  369. {
  370. [super beginEditing:rowDescriptor];
  371. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  372. self.endButton.enabled = NO;
  373. }
  374. }
  375. - (void)endEditing:(XLFormRowDescriptor *)rowDescriptor
  376. {
  377. [super endEditing:rowDescriptor];
  378. //OCSharedDto *shareDto = [appDelegate.sharesID objectForKey:self.shareLink];
  379. if ([rowDescriptor.tag isEqualToString:@"expirationDate"]) {
  380. NSDate *old = [NSDate dateWithTimeIntervalSince1970: self.itemShareLink.expirationDate];
  381. NSDate *new = rowDescriptor.value;
  382. if ([old compare:new] != NSOrderedSame) {
  383. NSString *expirationDate = [self convertDateInServerFormat:rowDescriptor.value];
  384. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:nil expirationTime:expirationDate permission:0 hideDownload:false];
  385. [self disableForm];
  386. }
  387. self.endButton.enabled = YES;
  388. }
  389. if ([rowDescriptor.tag isEqualToString:@"password"]) {
  390. NSString *password = rowDescriptor.value;
  391. // Public Password Enforced Test
  392. if (capabilities.isFilesSharingPublicPasswordEnforced == YES && password == nil) {
  393. [appDelegate messageNotification:@"_share_link_" description:@"_password_obligatory_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
  394. [self reloadData];
  395. } else {
  396. // if the password is not changed or is 0 lenght
  397. if ([[self.itemShareLink shareWith] isEqualToString:password]) {
  398. [self reloadData];
  399. } else {
  400. if (password == nil)
  401. password = @"";
  402. if (self.shareLink) {
  403. [self.delegate updateShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl password:password expirationTime:nil permission:0 hideDownload:false];
  404. [self disableForm];
  405. }
  406. }
  407. }
  408. }
  409. }
  410. #pragma --------------------------------------------------------------------------------------------
  411. #pragma mark ===== Button =====
  412. #pragma --------------------------------------------------------------------------------------------
  413. - (IBAction)endButtonAction:(id)sender
  414. {
  415. [self.tableView endEditing:YES];
  416. // reload delegate
  417. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.metadata.serverUrl fileID:self.metadata.fileID action:k_action_MOD];
  418. [self dismissViewControllerAnimated:YES completion:nil];
  419. }
  420. #pragma --------------------------------------------------------------------------------------------
  421. #pragma mark ===== User & Group =====
  422. #pragma --------------------------------------------------------------------------------------------
  423. - (void)getUserAndGroup:(NSString *)find
  424. {
  425. [self.delegate getUserAndGroup:find];
  426. }
  427. - (void)reloadUserAndGroup:(NSArray *)items
  428. {
  429. if (self.shareUserOC)
  430. [self.shareUserOC reloadUserAndGroup:items];
  431. }
  432. - (void)shareUserAndGroup:(NSString *)user shareeType:(NSInteger)shareeType permission:(NSInteger)permission
  433. {
  434. [self.delegate shareUserAndGroup:user shareeType:shareeType permission:permission metadata:self.metadata serverUrl:self.serverUrl];
  435. }
  436. - (void)updateShare:(NSString *)share metadata:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl password:(NSString *)password expirationTime:(NSString *)expirationTime permission:(NSInteger)permission hideDownload:(BOOL)hideDownload
  437. {
  438. [self.delegate updateShare:share metadata:metadata serverUrl:serverUrl password:password expirationTime:expirationTime permission:permission hideDownload:false];
  439. }
  440. #pragma --------------------------------------------------------------------------------------------
  441. #pragma mark ===== Utility =====
  442. #pragma --------------------------------------------------------------------------------------------
  443. - (void)minCharTextFieldDidChange:(UITextField *)sender
  444. {
  445. UIAlertController *alertController = (UIAlertController *)self.presentedViewController;
  446. if (alertController) {
  447. UITextField *password = alertController.textFields.firstObject;
  448. UIAlertAction *okAction = alertController.actions.lastObject;
  449. okAction.enabled = password.text.length >= 8;
  450. }
  451. }
  452. -(void)disableForm
  453. {
  454. self.form.disabled = YES;
  455. [self.tableView endEditing:YES];
  456. [self.tableView reloadData];
  457. }
  458. - (NSString *)convertDateInServerFormat:(NSDate *)date {
  459. NSDateFormatter *dateFormatter = [NSDateFormatter new];
  460. [dateFormatter setDateFormat:@"YYYY-MM-dd"];
  461. return [dateFormatter stringFromDate:date];
  462. }
  463. -(NSDate *)tomorrow
  464. {
  465. NSDate *now = [NSDate date];
  466. int daysToAdd = 1;
  467. return [now dateByAddingTimeInterval:60*60*24*daysToAdd];
  468. }
  469. - (NSInteger)getShareLinkPermission:(NSString *)value
  470. {
  471. if ([value isEqualToString:NSLocalizedString(@"_share_link_readonly_", nil)]) {
  472. return 1;
  473. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_modify_", nil)]) {
  474. return 3;
  475. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_", nil)]) {
  476. return 4;
  477. } else if ([value isEqualToString:NSLocalizedString(@"_share_link_upload_modify_", nil)]) {
  478. return 15;
  479. } else {
  480. return 1;
  481. }
  482. }
  483. @end