CCShareOC.m 27 KB

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