diff --git a/Changelog.md b/Changelog.md index e64f8a404a..1c4ce1d04f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,20 @@ +## 3.7.0 (December 2017) +- OAuth2 support with automatically refresh of new tokens +- New login view redesign +- Improve the automatic parse of valid URL in login view +- Automatic detection of authentication method available from the URL +- Improve network error messages inside the login view and all the app +- Improve UX for network warnings shown on the top of file list view +- Improve accounts handling +- Improve cookie sessions handling +- Improve switching between accounts +- Improve credentials handling in all requests and keychain +- Upgrade new db version +- New option in public share link that allows you to share a folder with only the option of uploading files to it +- Reflect forbidden reshare server capability in app +- Changes in Open-with feature to support whitelisted apps +- Bugs fixing + ## 3.6.2 (June 2017) - Support for private links - Fix crash in public share links on iPads with iOS10 diff --git a/OC Share Sheet/Info.plist b/OC Share Sheet/Info.plist index b21dc9675e..8e77b3e922 100644 --- a/OC Share Sheet/Info.plist +++ b/OC Share Sheet/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1.0.5 + 1.0.6 ITSAppUsesNonExemptEncryption NSAppTransportSecurity diff --git a/OCCommunicationLib b/OCCommunicationLib index 16bc3fbf9b..5b855815bf 160000 --- a/OCCommunicationLib +++ b/OCCommunicationLib @@ -1 +1 @@ -Subproject commit 16bc3fbf9b60e3f23e6d445989c8c7fa2fd120b7 +Subproject commit 5b855815bf49b4e3c05ba0700cedc6c909c14a18 diff --git a/Owncloud iOs Client/AppDelegate.h b/Owncloud iOs Client/AppDelegate.h index 882d8fedd3..035c33bd0e 100644 --- a/Owncloud iOs Client/AppDelegate.h +++ b/Owncloud iOs Client/AppDelegate.h @@ -270,15 +270,6 @@ extern NSString * NotReachableNetworkForDownloadsNotification; */ - (void) cancelTheCurrentUploadsOfTheUser:(NSInteger)userId; -/* - * This method is called after that this class receive the notification that the user - * has resolved the credentials error. - * In this method we changed the kind of error of uploads failed "errorCredentials" to "notAndError" - * for a specific user - * @userId -> userId for a scpecific user. - */ -- (void)changeTheStatusOfCredentialsFilesErrorOfAnUserId:(NSInteger)userId; - ///----------------------------------- /// @name Generate App Interface @@ -295,7 +286,7 @@ extern NSString * NotReachableNetworkForDownloadsNotification; * For iPad: * - The same TabBarController with three items. * - Detail View. - * + * */ - (void) generateAppInterfaceFromLoginScreen:(BOOL)isFromLogin; @@ -330,7 +321,8 @@ extern NSString * NotReachableNetworkForDownloadsNotification; * Method that switches the active user to that passed as a parameter * * @param user -> UserDto to set as active user + * @param isNewAccount -> BOOL if this user is a new account added */ -- (void) switchActiveUserTo:(UserDto *) user inHardMode:(BOOL)hardMode withCompletionHandler:(void (^)(void)) completionHandler; +- (void) switchActiveUserTo:(UserDto *) user isNewAccount:(BOOL)isNewAccount; @end diff --git a/Owncloud iOs Client/AppDelegate.m b/Owncloud iOs Client/AppDelegate.m index 6e5d0cd225..b9737e927a 100644 --- a/Owncloud iOs Client/AppDelegate.m +++ b/Owncloud iOs Client/AppDelegate.m @@ -148,10 +148,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self showSplashScreenFake]; - //Check if the server support shared api [CheckFeaturesSupported updateServerFeaturesAndCapabilitiesOfActiveUser]; - //Needed to use on background tasks if (!k_is_sso_active) { [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum]; @@ -180,6 +178,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( if (user) { self.activeUser = user; + [UtilsCookies deleteCurrentSystemCookieStorageAndRestoreTheCookiesOfActiveUser]; ((CheckAccessToServer*)[CheckAccessToServer sharedManager]).delegate = self; [[CheckAccessToServer sharedManager] isConnectionToTheServerByUrl:user.url withTimeout:k_timeout_fast]; @@ -589,14 +588,16 @@ + (OCCommunication*)sharedOCCommunication //Cookies is allways available in current supported Servers [sharedOCCommunication setIsCookiesAvailable:YES]; - [sharedOCCommunication setOauth2Configuration: [[OCOAuth2Configuration alloc] - initWithClientId:k_oauth2_client_id - clientSecret:k_oauth2_client_secret - redirectUri:k_oauth2_redirect_uri - authorizationEndpoint:k_oauth2_authorization_endpoint - tokenEndpoint:k_oauth2_token_endpoint]]; + OCOAuth2Configuration *ocOAuth2conf = [[OCOAuth2Configuration alloc] + initWithClientId:k_oauth2_client_id + clientSecret:k_oauth2_client_secret + redirectUri:k_oauth2_redirect_uri + authorizationEndpoint:k_oauth2_authorization_endpoint + tokenEndpoint:k_oauth2_token_endpoint]; + + [sharedOCCommunication setValueOauth2Configuration: ocOAuth2conf]; - [sharedOCCommunication setUserAgent:[UtilsUrls getUserAgent]]; + [sharedOCCommunication setValueOfUserAgent:[UtilsUrls getUserAgent]]; OCKeychain *oKeychain = [[OCKeychain alloc] init]; [sharedOCCommunication setValueCredentialsStorage:oKeychain]; @@ -631,14 +632,16 @@ + (OCCommunication*)sharedOCCommunicationDownloadFolder { //Cookies is allways available in current supported Servers [sharedOCCommunicationDownloadFolder setIsCookiesAvailable:YES]; - [sharedOCCommunicationDownloadFolder setOauth2Configuration: [[OCOAuth2Configuration alloc] - initWithClientId:k_oauth2_client_id - clientSecret:k_oauth2_client_secret - redirectUri:k_oauth2_redirect_uri - authorizationEndpoint:k_oauth2_authorization_endpoint - tokenEndpoint:k_oauth2_token_endpoint]]; + OCOAuth2Configuration *ocOAuth2conf = [[OCOAuth2Configuration alloc] + initWithClientId:k_oauth2_client_id + clientSecret:k_oauth2_client_secret + redirectUri:k_oauth2_redirect_uri + authorizationEndpoint:k_oauth2_authorization_endpoint + tokenEndpoint:k_oauth2_token_endpoint]; - [sharedOCCommunicationDownloadFolder setUserAgent:[UtilsUrls getUserAgent]]; + [sharedOCCommunicationDownloadFolder setValueOauth2Configuration:ocOAuth2conf]; + + [sharedOCCommunicationDownloadFolder setValueOfUserAgent:[UtilsUrls getUserAgent]]; OCKeychain *oKeychain = [[OCKeychain alloc] init]; [sharedOCCommunicationDownloadFolder setValueCredentialsStorage:oKeychain]; @@ -974,6 +977,10 @@ - (void)applicationWillTerminate:(UIApplication *)application // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. //Set on the user defaults that the app has been killed by user + + //Store active user cookies on the Database + [UtilsCookies saveCurrentOfActiveUserAndClean]; + NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults]; [standardUserDefaults setBool:YES forKey:k_app_killed_by_user]; [standardUserDefaults synchronize]; @@ -1714,8 +1721,13 @@ - (void) closeAlertViewAndViewControllers { if (self.presentFilesViewController){ //Close the openWith option in FileViewController if (self.presentFilesViewController.openWith) { - [self.presentFilesViewController.openWith.documentInteractionController dismissMenuAnimated:NO]; - self.presentFilesViewController.openWith.documentInteractionController = nil; + if (k_use_open_with_UIDocumentInteractionController) { + [self.presentFilesViewController.openWith.documentInteractionController dismissMenuAnimated:NO]; + self.presentFilesViewController.openWith.documentInteractionController = nil; + } else { + [self.presentFilesViewController.openWith.activityView dismissViewControllerAnimated:NO completion:nil]; + self.presentFilesViewController.openWith.activityView = nil; + } } //Close the delete option in FilesViewController if (self.presentFilesViewController.mDeleteFile.popupQuery) { @@ -2586,39 +2598,6 @@ - (void) cancelTheCurrentUploadsOfTheUser:(NSInteger)userId{ } } - -///----------------------------------- -/// @name Change the Status in uploads with Credential Error -///----------------------------------- - -/** - * This method is called after that this class receive the notification that the user - * has resolved the credentials error. - * In this method we changed the kind of error of uploads failed "errorCredentials" to "notAndError" - * for a specific user - * - * @param userId -> userId for a scpecific user. - * - * @discussion Maybe could be better move this kind of method to a singleton class inicializate in appDelegate. - * - */ -- (void)changeTheStatusOfCredentialsFilesErrorOfAnUserId:(NSInteger)userId{ - - __block ManageUploadRequest *currentManageUploadRequest; - - NSArray *failedUploadsTemp = [NSArray arrayWithArray:_uploadArray]; - - [failedUploadsTemp enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - currentManageUploadRequest = obj; - - if (currentManageUploadRequest.currentUpload.kindOfError == errorCredentials && currentManageUploadRequest.currentUpload.userId == userId) { - DLog(@"ub with name %@ not an error", currentManageUploadRequest.currentUpload.uploadFileName); - currentManageUploadRequest.currentUpload.kindOfError=notAnError; - [ManageUploadsDB setStatus:currentManageUploadRequest.currentUpload.status andKindOfError:notAnError byUploadOffline:currentManageUploadRequest.currentUpload]; - } - }]; -} - - (void) changeUploadsToWaitingForServerConnection{ if (self.uploadArray.count > 0) { @@ -2780,72 +2759,58 @@ -(void)badCertificateNotAcceptedByUser { } -#pragma mark - Active User +#pragma mark - Switch Active User -- (void) switchActiveUserTo:(UserDto *)user inHardMode:(BOOL)hardMode withCompletionHandler:(void (^)(void)) completionHandler { - - // all the switch is performed in background, without blocking the caller thread, that should be main - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ +- (void) switchActiveUserTo:(UserDto *)user isNewAccount:(BOOL)isNewAccount { + self.userSessionCurrentToken = nil; // should be here or right after checking the user really changed? for the moment, here - if (self.activeUser.userId != user.userId || hardMode) { - - //We delete the cookies on SAML - if (k_is_sso_active) { - [UtilsCookies eraseCredentialsAndUrlCacheOfActiveUser]; - } + if (!self.activeUser) { + self.activeUser = user; + } + + if (self.activeUser.userId != user.userId || isNewAccount) { - // Cancel downloads of the previous user, in the same background thread + // Cancel downloads of the previous user [self portedCancelAllDownloads]; + [UtilsCookies saveActiveUserCookiesAndRestoreCookiesOfUser:user]; + // update active state of users in DB [ManageUsersDB setAllUsersNoActive]; [ManageUsersDB setActiveAccountByUserId:user.userId]; user.activeaccount = YES; - - //Restore the cookies of the future activeUser - //1- Store the new cookies on the Database - [UtilsCookies setOnDBStorageCookiesByUser:self.activeUser]; - //2- Clean the cookies storage - [UtilsFramework deleteAllCookies]; - //3- We restore the previous cookies of the active user on the System cookies storage - [UtilsCookies setOnSystemStorageCookiesByUser:user]; - //4- We delete the cookies of the active user on the database because it could change and it is not necessary keep them there - [ManageCookiesStorageDB deleteCookiesByUser:user]; - + //Change the active user in appDelegate global variable self.activeUser = user; - + + //We check the connection here because we need to accept the certificate on the self signed server before go to the files tab + [[CheckAccessToServer sharedManager] isConnectionToTheServerByUrl:[UtilsUrls getFullRemoteServerPath:user]]; + [CheckFeaturesSupported updateServerFeaturesAndCapabilitiesOfActiveUser]; - - [UtilsCookies eraseURLCache]; - - //we create the user folder to haver multiuser - [UtilsFileSystem createFolderForUser:APP_DELEGATE.activeUser]; + + //we create the user folder to have multiuser + [UtilsFileSystem createFolderForUser:user]; self.isNewUser = YES; ManageAccounts *manageAccounts = [ManageAccounts new]; - [manageAccounts updateDisplayNameOfUserWithUser:self.activeUser]; + [manageAccounts updateDisplayNameOfUserWithUser:user]; + } - - // completion handler is called in main thread - dispatch_async(dispatch_get_main_queue(), ^{ - if (completionHandler) { - completionHandler(); - } - }); - }); } - (void) portedCancelAllDownloads { //Cancel downloads in ipad - [self.downloadManager cancelDownloads]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + + [self.downloadManager cancelDownloads]; - [[AppDelegate sharedSyncFolderManager] cancelAllDownloads]; + [[AppDelegate sharedSyncFolderManager] cancelAllDownloads]; + }); } diff --git a/Owncloud iOs Client/Branding/Customization.h b/Owncloud iOs Client/Branding/Customization.h index 3c78969271..b449268a2f 100644 --- a/Owncloud iOs Client/Branding/Customization.h +++ b/Owncloud iOs Client/Branding/Customization.h @@ -19,8 +19,6 @@ //URLs Setting #define k_help_url @"http://owncloud.com/mobile/help" -#define k_recomended_url @"http://owncloud.com/mobile/recommend" -#define k_send_feedback @"http://owncloud.com/mobile/feedback" //Hide url server #define k_hide_url_server NO @@ -33,9 +31,6 @@ //Show multiaccount or disconnect #define k_multiaccount_available YES - -//Have icon on backbutton -#define k_have_icon_on_popover YES //Have image background on navigation bar #define k_have_image_background_navigation_bar NO @@ -69,18 +64,12 @@ //Show impressum #define k_show_imprint_option_on_settings NO -//Buy more storage company name -#define k_company_name_buy_more_storage @"" - //Customize UITabBar #define k_is_customize_uitabbar YES //Customize Unselected UITabBarItems (The images of tabBar should be the unseleted tabs) #define k_is_customize_unselectedUITabBarItems NO -//Set Image on Preview Bottom toolBar on iPhone -#define k_set_image_on_preview_bottom_toolBar_on_iPhone NO - //Impressum is a File #define k_impressum_is_file YES @@ -90,26 +79,17 @@ //Customize recomend mail #define k_is_custom_recommend_mail NO #define k_is_username_recommend_mail NO -//#define k_subject_recommend_mail @"Sehen Sie sich die mobilcom-debitel Cloud an!" #define k_subject_recommend_mail @"" // /r/n needed for CR and LF #define k_text_recommend_mail @"" #define k_is_sign_custom_usign_username NO -//Customize background of bar bottom preview with image or color -#define k_is_image_background_preview_bottom_bar NO - //Social customize #define k_is_custom_twitter NO #define k_custom_twitter_message @"" #define k_is_custom_facebook NO #define k_custom_facebook_message @"" -//Autocomplete Login -#define k_is_autocomplete_username_necessary NO -#define k_letter_to_begin_autocomplete @"@" -#define k_text_to_autocomplete @"" - //Number of uploads shown in recents tab from the database #define k_number_uploads_shown 30 @@ -155,7 +135,6 @@ #define k_oauth2_client_secret @"KFeFWWEZO9TkisIQzR3fo7hfiMXlOpaqP8CFuTbSHzV1TUuGECglPxpiVKJfOXIx" - //Following not in use in 3.7.0 /****************************************************************/ //Have oauth active @@ -166,6 +145,11 @@ #define k_oauth_token @"" #define k_oauth_webservice @"" #define k_oauth_client_id @"" //the same in k_oauth_login + +//Autocomplete Login +#define k_is_autocomplete_username_necessary NO +#define k_letter_to_begin_autocomplete @"@" +#define k_text_to_autocomplete @"" /***************************************************************/ diff --git a/Owncloud iOs Client/Branding/UIColor+Constants.h b/Owncloud iOs Client/Branding/UIColor+Constants.h index b0bb4a7589..2dfa56e1fe 100644 --- a/Owncloud iOs Client/Branding/UIColor+Constants.h +++ b/Owncloud iOs Client/Branding/UIColor+Constants.h @@ -6,7 +6,7 @@ // /* - Copyright (C) 2016, ownCloud GmbH. + Copyright (C) 2017, ownCloud GmbH. This code is covered by the GNU Public License Version 3. For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/ You should have received a copy of this license diff --git a/Owncloud iOs Client/Branding/UIColor+Constants.m b/Owncloud iOs Client/Branding/UIColor+Constants.m index a845c8d973..514a92ba3b 100644 --- a/Owncloud iOs Client/Branding/UIColor+Constants.m +++ b/Owncloud iOs Client/Branding/UIColor+Constants.m @@ -6,7 +6,7 @@ // /* - Copyright (C) 2016, ownCloud GmbH. + Copyright (C) 2017, ownCloud GmbH. This code is covered by the GNU Public License Version 3. For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/ You should have received a copy of this license diff --git a/Owncloud iOs Client/DataBase/Queries/ManageDB.h b/Owncloud iOs Client/DataBase/Queries/ManageDB.h index 440252da54..3041ab4256 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageDB.h +++ b/Owncloud iOs Client/DataBase/Queries/ManageDB.h @@ -269,8 +269,12 @@ /** * Changes: * + * Support version 3.7.0 * Alter Keychain items to use credentialsDto as value instead password + * Alter users table, added new field to store that the server has fed shares, share link option name and share link option upload only API support. */ + (void) updateDBVersion21To22; + + @end diff --git a/Owncloud iOs Client/DataBase/Queries/ManageDB.m b/Owncloud iOs Client/DataBase/Queries/ManageDB.m index e83ff78a0d..1bcd302491 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageDB.m +++ b/Owncloud iOs Client/DataBase/Queries/ManageDB.m @@ -48,7 +48,7 @@ +(void) createDataBase { BOOL correctQuery=NO; - correctQuery = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS 'users' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , 'url' VARCHAR, 'ssl' BOOL, 'activeaccount' BOOL, 'storage_occupied' LONG NOT NULL DEFAULT 0, 'storage' LONG NOT NULL DEFAULT 0, 'has_share_api_support' INTEGER NOT NULL DEFAULT 0, 'has_sharee_api_support' INTEGER NOT NULL DEFAULT 0, 'has_cookies_support' INTEGER NOT NULL DEFAULT 0, 'has_forbidden_characters_support' INTEGER NOT NULL DEFAULT 0, 'has_capabilities_support' INTEGER NOT NULL DEFAULT 0, 'image_instant_upload' BOOL NOT NULL DEFAULT 0, 'video_instant_upload' BOOL NOT NULL DEFAULT 0, 'background_instant_upload' BOOL NOT NULL DEFAULT 0, 'path_instant_upload' VARCHAR, 'only_wifi_instant_upload' BOOL NOT NULL DEFAULT 0, 'timestamp_last_instant_upload_image' DOUBLE, 'timestamp_last_instant_upload_video' DOUBLE, 'url_redirected' VARCHAR, 'sorting_type' INTEGER NOT NULL DEFAULT 0, 'predefined_url' VARCHAR)"]; + correctQuery = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS 'users' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , 'url' VARCHAR, 'ssl' BOOL, 'activeaccount' BOOL, 'storage_occupied' LONG NOT NULL DEFAULT 0, 'storage' LONG NOT NULL DEFAULT 0, 'has_share_api_support' INTEGER NOT NULL DEFAULT 0, 'has_sharee_api_support' INTEGER NOT NULL DEFAULT 0, 'has_cookies_support' INTEGER NOT NULL DEFAULT 0, 'has_forbidden_characters_support' INTEGER NOT NULL DEFAULT 0, 'has_capabilities_support' INTEGER NOT NULL DEFAULT 0, 'image_instant_upload' BOOL NOT NULL DEFAULT 0, 'video_instant_upload' BOOL NOT NULL DEFAULT 0, 'background_instant_upload' BOOL NOT NULL DEFAULT 0, 'path_instant_upload' VARCHAR, 'only_wifi_instant_upload' BOOL NOT NULL DEFAULT 0, 'timestamp_last_instant_upload_image' DOUBLE, 'timestamp_last_instant_upload_video' DOUBLE, 'url_redirected' VARCHAR, 'sorting_type' INTEGER NOT NULL DEFAULT 0, 'predefined_url' VARCHAR, has_fed_shares_option_share_support INTEGER NOT NULL DEFAULT 0, has_public_share_link_option_name_support INTEGER NOT NULL DEFAULT 0, has_public_share_link_option_upload_only_support INTEGER NOT NULL DEFAULT 0)"]; if (!correctQuery) { DLog(@"Error in createDataBase table users"); @@ -1262,10 +1262,39 @@ + (void) updateDBVersion20To21 { + (void) updateDBVersion21To22 { - //1.- Migrate the current password stored in keychain + //1.- Alter users table to add more supported share options + + FMDatabaseQueue *queue = Managers.sharedDatabase; + + [queue inTransaction:^(FMDatabase *db, BOOL *rollback) { + + BOOL dbOperationSuccessful; + + dbOperationSuccessful =[db executeUpdate:@"ALTER TABLE users ADD has_fed_shares_option_share_support INTEGER NOT NULL DEFAULT 0"]; + if (!dbOperationSuccessful) { + DLog(@"Error update version 21 to 22 table users add column has_fed_shares_option_share_support"); + } + + dbOperationSuccessful =[db executeUpdate:@"ALTER TABLE users ADD has_public_share_link_option_name_support INTEGER NOT NULL DEFAULT 0"]; + if (!dbOperationSuccessful) { + DLog(@"Error update version 21 to 22 table users add column has_public_share_link_option_name_support"); + } + + dbOperationSuccessful =[db executeUpdate:@"ALTER TABLE users ADD has_public_share_link_option_upload_only_support INTEGER NOT NULL DEFAULT 0"]; + if (!dbOperationSuccessful) { + DLog(@"Error update version 21 to 22 table users add column has_public_share_link_option_upload_only_support"); + } + + }]; + + + //2.- Migrate the current password stored in keychain + [OCKeychain updateAllKeychainItemsFromDBVersion21To22ToStoreCredentialsDtoAsValueAndAuthenticationType]; + + } diff --git a/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m b/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m index 04d5e073b2..ffbc0fb1f2 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m +++ b/Owncloud iOs Client/DataBase/Queries/ManageFilesDB.m @@ -49,7 +49,7 @@ + (NSMutableArray *) getFilesByFileIdForActiveUser:(NSInteger) fileId { #endif __block NSMutableArray *output = [NSMutableArray new]; - DLog(@"getFilesByFileId: %ld",(long)fileId); + DLog(@"getFilesByFileId: %ld for active user %ld, %@",(long)fileId, mUser.userId, mUser.username); FMDatabaseQueue *queue = Managers.sharedDatabase; @@ -307,7 +307,7 @@ +(NSMutableArray *) getAllFoldersByBeginFilePath:(NSString *) beginFilePath { +(void) setFileIsDownloadState: (NSInteger) idFile andState:(enumDownload)downloadState { - DLog(@"setFileIsDownloadState"); + DLog(@"_setFileIsDownloadState id =%ld",(long)idFile); FMDatabaseQueue *queue = Managers.sharedDatabase; [queue inTransaction:^(FMDatabase *db, BOOL *rollback) { @@ -316,7 +316,7 @@ +(void) setFileIsDownloadState: (NSInteger) idFile andState:(enumDownload)downlo correctQuery = [db executeUpdate:@"UPDATE files SET is_download=? WHERE id = ?", [NSNumber numberWithInt:downloadState], [NSNumber numberWithInteger:idFile]]; if (!correctQuery) { - DLog(@"Error in setFileIsDownloadState"); + DLog(@"Error in setFileIsDownloadState id =%ld",(long)idFile); } }]; @@ -1261,10 +1261,10 @@ + (void) setFile:(NSInteger)idFile isNecessaryUpdate:(BOOL)isNecessaryUpdate { } -+ (BOOL) isGetFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto *) currentUser andFolder:(NSString *) folder { ++ (BOOL) isGetFilesByDownloadState:(enumDownload)downloadState andByUser:(UserDto *)currentUser andFolder:(NSString *)folder { __block BOOL output = NO; - DLog(@"getFilesByFileId:(int) fileId"); + DLog(@"isGetFilesByDownloadState: %d andByUser: %@",downloadState, currentUser); FMDatabaseQueue *queue = Managers.sharedDatabase; diff --git a/Owncloud iOs Client/DataBase/Queries/ManageUploadsDB.h b/Owncloud iOs Client/DataBase/Queries/ManageUploadsDB.h index b6399ef615..cd5b34d47b 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageUploadsDB.h +++ b/Owncloud iOs Client/DataBase/Queries/ManageUploadsDB.h @@ -122,7 +122,7 @@ +(void) saveInUploadsOfflineTableTheFirst:(NSUInteger)uploads; /* - * Method that update all the files with error credential that have been corrected by user + * Method that update all the uploads with credentialsError to a notAnError by user */ + (void) updateErrorCredentialFiles:(NSInteger) userSelected; diff --git a/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.h b/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.h index 8ded792257..5033016cf8 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.h +++ b/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.h @@ -99,7 +99,7 @@ /* * Method that returns last user inserted on the Database */ -+ (UserDto *) getLastUserInserted; ++ (UserDto *) getLastUserInsertedWithoutCredentials; //----------------------------------- diff --git a/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.m b/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.m index 46b5f76081..c4972cf17f 100644 --- a/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.m +++ b/Owncloud iOs Client/DataBase/Queries/ManageUsersDB.m @@ -42,20 +42,18 @@ +(UserDto *) insertUser:(UserDto *)userDto { FMDatabaseQueue *queue = Managers.sharedDatabase; + __block BOOL correctQuery=NO; [queue inTransaction:^(FMDatabase *db, BOOL *rollback) { - BOOL correctQuery=NO; - - correctQuery = [db executeUpdate:@"INSERT INTO users(url, ssl, activeaccount, has_share_api_support, has_sharee_api_support, has_cookies_support, has_forbidden_characters_support, has_capabilities_support, url_redirected, predefined_url) Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", userDto.url, [NSNumber numberWithBool:userDto.ssl], [NSNumber numberWithBool:userDto.activeaccount] , [NSNumber numberWithInteger:userDto.hasShareApiSupport], [NSNumber numberWithInteger:userDto.hasShareeApiSupport], [NSNumber numberWithBool:userDto.hasCookiesSupport], [NSNumber numberWithInteger:userDto.hasForbiddenCharactersSupport], [NSNumber numberWithInteger:userDto.hasCapabilitiesSupport], userDto.urlRedirected, userDto.predefinedUrl]; - - if (!correctQuery) { - DLog(@"Error in insertUser"); - } - + correctQuery = [db executeUpdate:@"INSERT INTO users(url, ssl, activeaccount, has_share_api_support, has_sharee_api_support, has_cookies_support, has_forbidden_characters_support, has_capabilities_support, url_redirected, predefined_url, has_fed_shares_option_share_support, has_public_share_link_option_name_support, has_public_share_link_option_upload_only_support) Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", userDto.url, [NSNumber numberWithBool:userDto.ssl], [NSNumber numberWithBool:userDto.activeaccount] , [NSNumber numberWithInteger:userDto.hasShareApiSupport], [NSNumber numberWithInteger:userDto.hasShareeApiSupport], [NSNumber numberWithBool:userDto.hasCookiesSupport], [NSNumber numberWithInteger:userDto.hasForbiddenCharactersSupport], [NSNumber numberWithInteger:userDto.hasCapabilitiesSupport], userDto.urlRedirected, userDto.predefinedUrl, [NSNumber numberWithInteger:userDto.hasFedSharesOptionShareSupport], [NSNumber numberWithInteger:userDto.hasPublicShareLinkOptionNameSupport], [NSNumber numberWithInteger:userDto.hasPublicShareLinkOptionUploadOnlySupport] ]; }]; + if (!correctQuery) { + DLog(@"Error in insertUser"); + return nil; + } - UserDto *lastUser = [self getLastUserInserted]; + UserDto *lastUser = [self getLastUserInsertedWithoutCredentials]; if (lastUser) { lastUser.username = userDto.username; @@ -93,6 +91,7 @@ + (UserDto *) getActiveUser { output.activeaccount = [rs intForColumn:@"activeaccount"]; output.storageOccupied = [rs longForColumn:@"storage_occupied"]; output.storage = [rs longForColumn:@"storage"]; + output.hasShareApiSupport = [rs intForColumn:@"has_share_api_support"]; output.hasShareeApiSupport = [rs intForColumn:@"has_sharee_api_support"]; output.hasCookiesSupport = [rs intForColumn:@"has_cookies_support"]; @@ -110,6 +109,10 @@ + (UserDto *) getActiveUser { output.urlRedirected = [rs stringForColumn:@"url_redirected"]; output.sortingType = [rs intForColumn:@"sorting_type"]; output.predefinedUrl = [rs stringForColumn:@"predefined_url"]; + + output.hasFedSharesOptionShareSupport = [rs intForColumn:@"has_fed_shares_option_share_support"]; + output.hasPublicShareLinkOptionNameSupport = [rs intForColumn:@"has_public_share_link_option_name_support"]; + output.hasPublicShareLinkOptionUploadOnlySupport = [rs intForColumn:@"has_public_share_link_option_upload_only_support"]; } [rs close]; @@ -153,6 +156,7 @@ + (UserDto *) getActiveUserWithoutCredentials { output.activeaccount = [rs intForColumn:@"activeaccount"]; output.storageOccupied = [rs longForColumn:@"storage_occupied"]; output.storage = [rs longForColumn:@"storage"]; + output.hasShareApiSupport = [rs intForColumn:@"has_share_api_support"]; output.hasShareeApiSupport = [rs intForColumn:@"has_sharee_api_support"]; output.hasCookiesSupport = [rs intForColumn:@"has_cookies_support"]; @@ -168,13 +172,15 @@ + (UserDto *) getActiveUserWithoutCredentials { output.timestampInstantUploadVideo = [rs doubleForColumn:@"timestamp_last_instant_upload_video"]; output.urlRedirected = [rs stringForColumn:@"url_redirected"]; + output.sortingType = [rs intForColumn:@"sorting_type"]; + output.predefinedUrl = [rs stringForColumn:@"predefined_url"]; + + output.hasFedSharesOptionShareSupport = [rs intForColumn:@"has_fed_shares_option_share_support"]; + output.hasPublicShareLinkOptionNameSupport = [rs intForColumn:@"has_public_share_link_option_name_support"]; + output.hasPublicShareLinkOptionUploadOnlySupport = [rs intForColumn:@"has_public_share_link_option_upload_only_support"]; output.username = nil; output.credDto = nil; - - output.sortingType = [rs intForColumn:@"sorting_type"]; - - output.predefinedUrl = [rs stringForColumn:@"predefined_url"]; } [rs close]; @@ -207,6 +213,7 @@ + (UserDto *) getUserByUserId:(NSInteger) userId { user.activeaccount = [rs intForColumn:@"activeaccount"]; user.storageOccupied = [rs longForColumn:@"storage_occupied"]; user.storage = [rs longForColumn:@"storage"]; + user.hasShareApiSupport = [rs intForColumn:@"has_share_api_support"]; user.hasShareeApiSupport = [rs intForColumn:@"has_sharee_api_support"]; user.hasCookiesSupport = [rs intForColumn:@"has_cookies_support"]; @@ -224,6 +231,10 @@ + (UserDto *) getUserByUserId:(NSInteger) userId { user.urlRedirected = [rs stringForColumn:@"url_redirected"]; user.sortingType = [rs intForColumn:@"sorting_type"]; user.predefinedUrl = [rs stringForColumn:@"predefined_url"]; + + user.hasFedSharesOptionShareSupport = [rs intForColumn:@"has_fed_shares_option_share_support"]; + user.hasPublicShareLinkOptionNameSupport = [rs intForColumn:@"has_public_share_link_option_name_support"]; + user.hasPublicShareLinkOptionUploadOnlySupport = [rs intForColumn:@"has_public_share_link_option_upload_only_support"]; } [rs close]; @@ -281,6 +292,7 @@ + (NSMutableArray *) getAllUsers { current.activeaccount = [rs intForColumn:@"activeaccount"]; current.storageOccupied = [rs longForColumn:@"storage_occupied"]; current.storage = [rs longForColumn:@"storage"]; + current.hasShareApiSupport = [rs intForColumn:@"has_share_api_support"]; current.hasShareeApiSupport = [rs intForColumn:@"has_sharee_api_support"]; current.hasCookiesSupport = [rs intForColumn:@"has_cookies_support"]; @@ -296,11 +308,13 @@ + (NSMutableArray *) getAllUsers { current.timestampInstantUploadVideo = [rs doubleForColumn:@"timestamp_last_instant_upload_video"]; current.urlRedirected = [rs stringForColumn:@"url_redirected"]; - current.sortingType = [rs intForColumn:@"sorting_type"]; - current.predefinedUrl = [rs stringForColumn:@"predefined_url"]; + current.hasFedSharesOptionShareSupport = [rs intForColumn:@"has_fed_shares_option_share_support"]; + current.hasPublicShareLinkOptionNameSupport = [rs intForColumn:@"has_public_share_link_option_name_support"]; + current.hasPublicShareLinkOptionUploadOnlySupport = [rs intForColumn:@"has_public_share_link_option_upload_only_support"]; + OCCredentialsDto *credDto = [OCKeychain getCredentialsOfUser:current]; current.username = credDto.userName; current.credDto = credDto; @@ -342,6 +356,7 @@ + (NSMutableArray *) getAllUsersWithOutCredentialInfo{ current.activeaccount = [rs intForColumn:@"activeaccount"]; current.storageOccupied = [rs longForColumn:@"storage_occupied"]; current.storage = [rs longForColumn:@"storage"]; + current.hasShareApiSupport = [rs intForColumn:@"has_share_api_support"]; current.hasShareeApiSupport = [rs intForColumn:@"has_sharee_api_support"]; current.hasCookiesSupport = [rs intForColumn:@"has_cookies_support"]; @@ -357,16 +372,17 @@ + (NSMutableArray *) getAllUsersWithOutCredentialInfo{ current.timestampInstantUploadVideo = [rs doubleForColumn:@"timestamp_last_instant_upload_video"]; current.urlRedirected = [rs stringForColumn:@"url_redirected"]; + current.sortingType = [rs intForColumn:@"sorting_type"]; + current.predefinedUrl = [rs stringForColumn:@"predefined_url"]; + + current.hasFedSharesOptionShareSupport = [rs intForColumn:@"has_fed_shares_option_share_support"]; + current.hasPublicShareLinkOptionNameSupport = [rs intForColumn:@"has_public_share_link_option_name_support"]; + current.hasPublicShareLinkOptionUploadOnlySupport = [rs intForColumn:@"has_public_share_link_option_upload_only_support"]; current.username = nil; current.credDto = nil; - current.sortingType = [rs intForColumn:@"sorting_type"]; - - current.predefinedUrl = [rs stringForColumn:@"predefined_url"]; - [output addObject:current]; - } [rs close]; @@ -560,7 +576,7 @@ +(void) updateStorageByUserDto:(UserDto *) user { } -+ (UserDto *) getLastUserInserted { ++ (UserDto *) getLastUserInsertedWithoutCredentials { __block UserDto *output = nil; @@ -580,6 +596,7 @@ + (UserDto *) getLastUserInserted { output.activeaccount = [rs intForColumn:@"activeaccount"]; output.storageOccupied = [rs longForColumn:@"storage_occupied"]; output.storage = [rs longForColumn:@"storage"]; + output.hasShareApiSupport = [rs intForColumn:@"has_share_api_support"]; output.hasShareeApiSupport = [rs intForColumn:@"has_sharee_api_support"]; output.hasCookiesSupport = [rs intForColumn:@"has_cookies_support"]; @@ -595,10 +612,12 @@ + (UserDto *) getLastUserInserted { output.timestampInstantUploadVideo = [rs doubleForColumn:@"timestamp_last_instant_upload_video"]; output.urlRedirected = [rs stringForColumn:@"url_redirected"]; - output.sortingType = [rs intForColumn:@"sorting_type"]; - output.predefinedUrl = [rs stringForColumn:@"predefined_url"]; + + output.hasFedSharesOptionShareSupport = [rs intForColumn:@"has_fed_shares_option_share_support"]; + output.hasPublicShareLinkOptionNameSupport = [rs intForColumn:@"has_public_share_link_option_name_support"]; + output.hasPublicShareLinkOptionUploadOnlySupport = [rs intForColumn:@"has_public_share_link_option_upload_only_support"]; } [rs close]; @@ -616,7 +635,7 @@ + (void) updateUserByUserDto:(UserDto *) user { [queue inTransaction:^(FMDatabase *db, BOOL *rollback) { BOOL correctQuery=NO; - correctQuery = [db executeUpdate:@"UPDATE users SET url=?, ssl=?, activeaccount=?, storage_occupied=?, storage=?, has_share_api_support=?, has_sharee_api_support=?, has_cookies_support=?, has_forbidden_characters_support=?, has_capabilities_support=?, image_instant_upload=?, video_instant_upload=?, background_instant_upload=?, path_instant_upload=?, only_wifi_instant_upload=?, timestamp_last_instant_upload_image=?, timestamp_last_instant_upload_video=?, url_redirected=?, sorting_type=?, predefined_url=? WHERE id = ?", user.url, [NSNumber numberWithBool:user.ssl], [NSNumber numberWithBool:user.activeaccount], [NSNumber numberWithLong:user.storageOccupied], [NSNumber numberWithLong:user.storage], [NSNumber numberWithInteger:user.hasShareApiSupport], [NSNumber numberWithInteger:user.hasShareeApiSupport], [NSNumber numberWithInteger:user.hasCookiesSupport], [NSNumber numberWithInteger:user.hasForbiddenCharactersSupport], [NSNumber numberWithInteger:user.hasCapabilitiesSupport], [NSNumber numberWithBool:user.imageInstantUpload], [NSNumber numberWithBool:user.videoInstantUpload], [NSNumber numberWithBool:user.backgroundInstantUpload], user.pathInstantUpload, [NSNumber numberWithBool:user.onlyWifiInstantUpload], [NSNumber numberWithLong:user.timestampInstantUploadImage], [NSNumber numberWithLong:user.timestampInstantUploadVideo], user.urlRedirected, [NSNumber numberWithInteger:user.sortingType],user.predefinedUrl, [NSNumber numberWithInteger:user.userId]]; + correctQuery = [db executeUpdate:@"UPDATE users SET url=?, ssl=?, activeaccount=?, storage_occupied=?, storage=?, has_share_api_support=?, has_sharee_api_support=?, has_cookies_support=?, has_forbidden_characters_support=?, has_capabilities_support=?, image_instant_upload=?, video_instant_upload=?, background_instant_upload=?, path_instant_upload=?, only_wifi_instant_upload=?, timestamp_last_instant_upload_image=?, timestamp_last_instant_upload_video=?, url_redirected=?, sorting_type=?, predefined_url=?, has_fed_shares_option_share_support=?, has_public_share_link_option_name_support=?, has_public_share_link_option_upload_only_support=? WHERE id = ?", user.url, [NSNumber numberWithBool:user.ssl], [NSNumber numberWithBool:user.activeaccount], [NSNumber numberWithLong:user.storageOccupied], [NSNumber numberWithLong:user.storage], [NSNumber numberWithInteger:user.hasShareApiSupport], [NSNumber numberWithInteger:user.hasShareeApiSupport], [NSNumber numberWithInteger:user.hasCookiesSupport], [NSNumber numberWithInteger:user.hasForbiddenCharactersSupport], [NSNumber numberWithInteger:user.hasCapabilitiesSupport], [NSNumber numberWithBool:user.imageInstantUpload], [NSNumber numberWithBool:user.videoInstantUpload], [NSNumber numberWithBool:user.backgroundInstantUpload], user.pathInstantUpload, [NSNumber numberWithBool:user.onlyWifiInstantUpload], [NSNumber numberWithLong:user.timestampInstantUploadImage], [NSNumber numberWithLong:user.timestampInstantUploadVideo], user.urlRedirected, [NSNumber numberWithInteger:user.sortingType],user.predefinedUrl, [NSNumber numberWithInteger:user.hasFedSharesOptionShareSupport], [NSNumber numberWithInteger:user.hasPublicShareLinkOptionNameSupport], [NSNumber numberWithInteger:user.hasPublicShareLinkOptionUploadOnlySupport], [NSNumber numberWithInteger:user.userId]]; if (!correctQuery) { DLog(@"Error updating a user"); diff --git a/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m b/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m index f6ea45108b..e0c51c2696 100755 --- a/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m +++ b/Owncloud iOs Client/Files/Preview/DetailView/DetailViewController.m @@ -844,8 +844,12 @@ - (void)presentWhiteView { self.view.backgroundColor = [UIColor colorOfBackgroundDetailViewiPad]; _titleLabel.text = @""; - - [_openWith.documentInteractionController dismissMenuAnimated:YES]; + + if (k_use_open_with_UIDocumentInteractionController) { + [_openWith.documentInteractionController dismissMenuAnimated:YES]; + } else { + [_openWith.activityPopoverController dismissPopoverAnimated:YES]; + } [self removeThePreviousViews]; @@ -1055,8 +1059,15 @@ - (IBAction)didPressOpenWithButton:(id)sender - (IBAction)didPressShareLinkButton:(id)sender { DLog(@"Share button clicked"); - if (_openWith && _openWith.documentInteractionController) { - [_openWith.documentInteractionController dismissMenuAnimated:YES]; + if (k_use_open_with_UIDocumentInteractionController) { + + if (_openWith && _openWith.documentInteractionController) { + [_openWith.documentInteractionController dismissMenuAnimated:YES]; + } + } else { + if (_openWith && _openWith.activityView) { + [_openWith.activityPopoverController dismissPopoverAnimated:YES]; + } } DLog(@"Share Link Option"); @@ -1746,7 +1757,12 @@ - (void) customWillRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterf } if (_openWith) { - [_openWith.documentInteractionController dismissMenuAnimated:NO]; + + if (k_use_open_with_UIDocumentInteractionController) { + [_openWith.documentInteractionController dismissMenuAnimated:NO]; + } else { + [_openWith.activityPopoverController dismissPopoverAnimated:NO]; + } } } diff --git a/Owncloud iOs Client/Login/Keychain/OCKeychain.m b/Owncloud iOs Client/Login/Keychain/OCKeychain.m index f3932aca7c..8f74823744 100644 --- a/Owncloud iOs Client/Login/Keychain/OCKeychain.m +++ b/Owncloud iOs Client/Login/Keychain/OCKeychain.m @@ -43,6 +43,10 @@ +(BOOL)storeCredentials:(OCCredentialsDto *)credDto migratingFromDB9to10:(BOOL)m BOOL output = NO; + if (credDto.userDisplayName == nil) { + credDto.userDisplayName = @""; + } + NSMutableDictionary *keychainItem = [NSMutableDictionary dictionary]; [keychainItem setObject:(__bridge id)(kSecClassGenericPassword) forKey:(__bridge id)kSecClass]; @@ -99,7 +103,7 @@ +(NSDictionary *)getKeychainDictionaryOfUserId:(NSString *)userId { OSStatus stsExist = SecItemCopyMatching((__bridge CFDictionaryRef)keychainItem, (CFTypeRef *)&result); - DLog(@"(getCredentials)Error Code %d (0 = success)", (int)stsExist); + DLog(@"(getCredentials of userId %@)Error Code %d (0 = success)", userId, (int)stsExist); if (stsExist != errSecSuccess) { NSLog(@"Unable to get the item with userId=%@ ",userId); @@ -183,6 +187,10 @@ +(BOOL)updateCredentials:(OCCredentialsDto *)credDto { BOOL output = NO; + if (credDto.userDisplayName == nil) { + credDto.userDisplayName = @""; + } + NSMutableDictionary *keychainItem = [NSMutableDictionary dictionary]; [keychainItem setObject:(__bridge id)(kSecClassGenericPassword) forKey:(__bridge id)kSecClass]; diff --git a/Owncloud iOs Client/Login/Login/GetPublicInfoFromServerJob.swift b/Owncloud iOs Client/Login/Login/GetPublicInfoFromServerJob.swift index d585d0f5ab..cf3981615a 100644 --- a/Owncloud iOs Client/Login/Login/GetPublicInfoFromServerJob.swift +++ b/Owncloud iOs Client/Login/Login/GetPublicInfoFromServerJob.swift @@ -77,9 +77,7 @@ class GetPublicInfoFromServerJob: NSObject, CheckAccessToServerDelegate { checkAccessToServer() } else { - self.completion?(nil, nil, error, statusCode) - - print("No connection to the server") + self.completion?(nil, nil, error, statusCode) } } else { diff --git a/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift b/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift index cf7c92131a..40cc46ee4a 100644 --- a/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift +++ b/Owncloud iOs Client/Login/Login/UniversalLoginViewController.swift @@ -60,7 +60,7 @@ public enum TextfieldType: String { @IBOutlet var textFieldURL: UITextField! @IBOutlet var buttonReconnection: UIButton! - @IBOutlet weak var buttonReconnectionURL: UIButton! + @IBOutlet var buttonReconnectionURL: UIButton! @IBOutlet var imageViewURLFooter: UIImageView! @IBOutlet var labelURLFooter: UILabel! @IBOutlet var activityIndicatorURLFooter: UIActivityIndicatorView! @@ -144,13 +144,12 @@ public enum TextfieldType: String { self.oAuth2Manager.trustedCertificatesStore = SSLCertificateManager() if self.loginMode == .update { - self.buttonReconnectionURL.isHidden = true - self.labelURLFooter.text = nil - self.imageViewURLFooter.image = nil + self.setReconnectionButtons(hiddenStatus: true) + self.setURLFooter(isType: .None) self.checkCurrentUrl() } - UtilsCookies.clear() // network requests from log-in view need to be independent of existing sessions + UtilsCookies.saveCurrentOfActiveUserAndClean() // network requests from log-in view need to be independent of existing sessions print("Init login with loginMode: \(loginMode.rawValue) (0=Create,1=Update,2=Expire,3=Migrate)") } @@ -159,8 +158,9 @@ public enum TextfieldType: String { super.viewWillDisappear(animated) self.removeNotificationsAboutKeyboard() + if self.loginMode == .update || self.loginMode == .migrate { - UtilsCookies.restoreTheCookiesOfActiveUser() + UtilsCookies.deleteCurrentSystemCookieStorageAndRestoreTheCookiesOfActiveUser() } } @@ -239,10 +239,12 @@ public enum TextfieldType: String { DispatchQueue.main.async { if (self.basicAuthInfoStackView.isHidden) { self.setURLFooter(isType: .Error, errorMessage: message) + self.setConnectButton(status: false) + } else { self.setPasswordFooterError(errorMessage: message) + self.setConnectButton(status: true) } - self.setConnectButton(status: true) } } @@ -257,21 +259,28 @@ public enum TextfieldType: String { self.imageViewURLFooter.image = UIImage(named: "CredentialsError.png")! self.labelURLFooter.text = errorMessage self.setReconnectionButtons(hiddenStatus: false) + self.setConnectButton(status: false) return // beware: return here, break in the rest case .TestingConnection: footerMessage = "testing_connection" self.setActivityIndicator(isVisible: true) + self.setConnectButton(status: false) + break case .ConnectionEstablishedNonSecure: self.imageViewURLFooter.image = UIImage(named: "NonSecureConnectionIcon.png")! footerMessage = "connection_established" + self.setConnectButton(status: true) + break case .ConnectionEstablishedSecure: self.imageViewURLFooter.image = UIImage(named: "SecureConnectionIcon.png")! footerMessage = "secure_connection_established" + self.setConnectButton(status: true) + break case .None: @@ -358,6 +367,9 @@ public enum TextfieldType: String { self.setURLStackView(hiddenStatus: true) } + self.textFieldUsername.autocorrectionType = .no + self.textFieldURL.autocorrectionType = .no + //set user&pass visibility self.updateInputFieldsFromCurrentAuthMethodToLogin() @@ -482,6 +494,7 @@ public enum TextfieldType: String { // MARK: dismiss func closeLoginView() { self.setNetworkActivityIndicator(status: false) + UtilsCookies.deleteCurrentSystemCookieStorageAndRestoreTheCookiesOfActiveUser() self.dismiss(animated: true, completion: nil) } @@ -613,16 +626,16 @@ public enum TextfieldType: String { public func setCookieForSSO(_ cookieString: String?, serverPath: String?) { self.setNetworkActivityIndicator(status: false) - if self.loginMode == .update { - ManageCookiesStorageDB.deleteCookies(byUser: self.user) - UtilsCookies.eraseCredentials(withURL: UtilsUrls.getFullRemoteServerPath(withWebDav: self.user)) - UtilsCookies.eraseURLCache() - } let userCredDto :OCCredentialsDto = OCCredentialsDto() userCredDto.accessToken = cookieString; userCredDto.authenticationMethod = .SAML_WEB_SSO; + if self.loginMode == .expire { + let app: AppDelegate = (UIApplication.shared.delegate as! AppDelegate) + userCredDto.userName = app.activeUser.username + } + if cookieString == nil || cookieString == "" { self.showCredentialsError(NSLocalizedString("authentification_not_valid", comment: "") ) @@ -630,6 +643,7 @@ public enum TextfieldType: String { return; } + UtilsCookies.updateOfActiveUserInDB() self.detectUserDataAndValidate(credentials: userCredDto, serverPath: serverPath!) } @@ -833,24 +847,29 @@ public enum TextfieldType: String { func detectUserDataAndValidate(credentials: OCCredentialsDto, serverPath: String) { - DetectUserData .getUserDisplayName(ofServer: serverPath, credentials: credentials) { (displayName, error) in + DetectUserData .getUserDisplayName(ofServer: serverPath, credentials: credentials) { (serverUserID, displayName, error) in - if (displayName != nil) { + if (serverUserID != nil && displayName != nil) { if credentials.authenticationMethod == .SAML_WEB_SSO { - - credentials.userName = displayName + if credentials.userName == nil { + credentials.userName = serverUserID + credentials.userDisplayName = displayName + } + } else { + + if (serverUserID == credentials.userName) { + + if (displayName != credentials.userDisplayName){ + credentials.userDisplayName = displayName + } + } } - credentials.userDisplayName = displayName - - } - + } self.validateCredentialsAndStoreAccount(credentials: credentials) } - } - func validateCredentialsAndStoreAccount(credentials: OCCredentialsDto) { //get list of files in root to check session validty, if ok store new account let urlToGetRootFiles = NSURL (string: UtilsUrls.getFullRemoteServerPathWithWebDav(byNormalizedUrl: validatedServerURL) ) @@ -864,45 +883,55 @@ public enum TextfieldType: String { if (listOfFileDtos != nil && !((listOfFileDtos?.isEmpty)!)) { /// credentials allowed access to root folder: well done - if ( (self.loginMode == .update || self.loginMode == .expire) && credentials.userName != self.user?.username ) { + let tryingToUpdateDifferentUser = (self.user != nil && (self.loginMode == .update || self.loginMode == .expire) && credentials.userName != self.user?.username) + + if tryingToUpdateDifferentUser { + //Delete current wrong cookies and relaunch check url to get correct ones + UtilsFramework.deleteAllCookies() self.showCredentialsError(NSLocalizedString("credentials_different_user", comment: "") ) } else { - if self.user == nil { - self.user = UserDto() - } - - self.user?.url = self.validatedServerURL - self.user?.username = credentials.userName - self.user?.ssl = self.validatedServerURL.hasPrefix("https") - self.user?.urlRedirected = app.urlServerRedirected - self.user?.predefinedUrl = k_default_url_server + if self.loginMode == .create || self.loginMode == .migrate { + let newUser = UserDto() + if self.loginMode == .migrate { + newUser.userId = self.user!.userId + } + newUser.url = self.validatedServerURL + newUser.username = credentials.userName + newUser.ssl = self.validatedServerURL.hasPrefix("https") + newUser.urlRedirected = app.urlServerRedirected + newUser.predefinedUrl = k_default_url_server + + self.user = newUser.copy() as? UserDto + } + credentials.baseURL = UtilsUrls.getFullRemoteServerPath(self.user) if self.loginMode == .create { if (ManageUsersDB.isExistUser(self.user)) { + //Delete current wrong cookies and relaunch check url to get correct ones + UtilsFramework.deleteAllCookies() self.showURLError(NSLocalizedString("account_not_new", comment: "")) } else { - + self.user = ManageAccounts().storeAccountOfUser(self.user!, withCredentials: credentials) if self.user != nil { ManageFiles().storeListOfFiles(listOfFileDtos!, forFileId: 0, andUser: self.user!) - app.switchActiveUser(to: self.user, inHardMode: true, withCompletionHandler: - { - app.generateAppInterface(fromLoginScreen: true) - }) + app.switchActiveUser(to: self.user, isNewAccount: true) + app.generateAppInterface(fromLoginScreen: true) + } else { self.showURLError(NSLocalizedString("error_could_not_add_account", comment: "")) } } - } else { + } else { ManageAccounts().updateAccountOfUser(self.user!, withCredentials: credentials) if (app.activeUser != nil && app.activeUser.userId == self.user?.userId) { @@ -912,7 +941,7 @@ public enum TextfieldType: String { if self.loginMode == .migrate { // migration mode needs to start a fresh list of files, so that it is updated with the new URL app.generateAppInterface(fromLoginScreen: true) - + } else { self.closeLoginView() } diff --git a/Owncloud iOs Client/Login/SSO/SSOViewController.m b/Owncloud iOs Client/Login/SSO/SSOViewController.m index 641bf79a3c..6c174e2751 100644 --- a/Owncloud iOs Client/Login/SSO/SSOViewController.m +++ b/Owncloud iOs Client/Login/SSO/SSOViewController.m @@ -64,13 +64,10 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; if (app.activeUser) { - //1- Storage the active account cookies on the Database - [UtilsCookies setOnDBStorageCookiesByUser:app.activeUser]; + [UtilsCookies saveCurrentOfActiveUserAndClean]; } - //2- Delete the current cookies because we delete the current active user - [UtilsFramework deleteAllCookies]; - //3- Init SSLCertificateManager instance to access user-accepted server certificates + //Init SSLCertificateManager instance to access user-accepted server certificates self.sslCertificateManager = [SSLCertificateManager new]; } diff --git a/Owncloud iOs Client/Network/Favorites/ManageFavorites.m b/Owncloud iOs Client/Network/Favorites/ManageFavorites.m index 76e48ffb86..640cc93cda 100644 --- a/Owncloud iOs Client/Network/Favorites/ManageFavorites.m +++ b/Owncloud iOs Client/Network/Favorites/ManageFavorites.m @@ -6,7 +6,7 @@ // /* - Copyright (C) 2016, ownCloud GmbH. + Copyright (C) 2017, ownCloud GmbH. This code is covered by the GNU Public License Version 3. For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/ You should have received a copy of this license @@ -51,15 +51,6 @@ -(id) init { } -///----------------------------------- -/// @name isOnAnUpdatingProcessThisFavoriteFile -///----------------------------------- - -/** - * This method checks if the file is currently on an updating process. It is check by fileName, filePath and userId - * - * @param favoriteFile > FileDto. The file which is going to be checked - */ - (BOOL) isOnAnUpdatingProcessThisFavoriteFile:(FileDto *)favoriteFile { //Create a copy of the favorite array @@ -85,46 +76,22 @@ - (BOOL) isOnAnUpdatingProcessThisFavoriteFile:(FileDto *)favoriteFile { } -///----------------------------------- -/// @name Sync All Favorites of User -///----------------------------------- - -/** - * Method that begin a process to update all favorites files of a specific user - * - * 1.- Get all favorites of a specific user - * - * 2.- Send the list to a specific method to update the favorites - * - * @param NSInteger -> userId - * - */ - - (void) syncAllFavoritesOfUser:(NSInteger)userId{ - NSArray *dataBaseFavorites = [ManageFilesDB getAllFavoritesFilesOfUserId:userId]; - - [self syncFavoritesOfList:dataBaseFavorites ofThisUser:userId]; - + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + + NSArray *dataBaseFavorites = [ManageFilesDB getAllFavoritesFilesOfUserId:userId]; + [self syncFavoritesOfList:dataBaseFavorites ofThisUser:userId]; + }); } -///----------------------------------- -/// @name Sync Favorites of Folder with User -///----------------------------------- - -/** - * Method that begin a process to sync favorites of a specific path and user - * - * @param idFolder -> NSInteger - * @param userId -> NSInteger - * - */ - (void) syncFavoritesOfFolder:(FileDto *)folder withUser:(NSInteger)userId { - NSArray *dataBaseFavorites = [ManageFilesDB getAllFavoritesByFolder:folder]; - [self syncFavoritesOfList:dataBaseFavorites ofThisUser:userId]; - + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSArray *dataBaseFavorites = [ManageFilesDB getAllFavoritesByFolder:folder]; + [self syncFavoritesOfList:dataBaseFavorites ofThisUser:userId]; + }); } ///----------------------------------- @@ -254,15 +221,6 @@ - (void) syncFavoritesOfList:(NSArray*)favoritesFilesAndFolders ofThisUser:(NSIn } -///----------------------------------- -/// @name Remove of sync process file -///----------------------------------- - -/** - * Method that find the equal file stored in _favoritesSyncing and remove it - * - * @param file -> FileDto - */ - (void) removeOfSyncProcessFile:(FileDto*)file{ FileDto *fileDto = [self getFileEqualTo:file]; @@ -303,15 +261,6 @@ - (FileDto *)getFileEqualTo:(FileDto*)file{ } -///----------------------------------- -/// @name thereIsANewVersionAvailableOfThisFile -///----------------------------------- - -/** - * This method check if there is a new version on the server for a concret file - * - * @param favoriteFile -> FileDto - */ - (void) thereIsANewVersionAvailableOfThisFile: (FileDto *)favoriteFile { AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; @@ -393,11 +342,7 @@ - (BOOL) isInsideAFavoriteFolderThisFile:(FileDto *) file { return isSonOfFavorite; } -/** - * This method mark all files and folders behind "folder" as not favorites - * - * @param folder > FileDto. The folder parent - */ + - (void) setAllFilesAndFoldersAsNoFavoriteBehindFolder:(FileDto *) folder { NSMutableArray *listOfFoldersToMarkAsNotFavorite = [NSMutableArray new]; [listOfFoldersToMarkAsNotFavorite addObject:folder]; @@ -459,13 +404,6 @@ - (void)updateOrCancelTheDownload:(id)download{ #pragma mark - Update just single file -///----------------------------------- -/// @name downloadSingleFavoriteFileSonOfFavoriteFolder -///----------------------------------- - -/** - * Method force the download of a favorite file son of a favorite folder - */ - (void) downloadSingleFavoriteFileSonOfFavoriteFolder:(FileDto *) file { AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; diff --git a/Owncloud iOs Client/Network/Server Version Checks/CheckFeaturesSupported.m b/Owncloud iOs Client/Network/Server Version Checks/CheckFeaturesSupported.m index 13323b6aa7..01d6ccabfa 100644 --- a/Owncloud iOs Client/Network/Server Version Checks/CheckFeaturesSupported.m +++ b/Owncloud iOs Client/Network/Server Version Checks/CheckFeaturesSupported.m @@ -40,10 +40,7 @@ + (void) updateServerFeaturesAndCapabilitiesOfActiveUser{ if (capabilities) { [CheckCapabilities updateServerCapabilitiesOfActiveAccountInDB:capabilities]; - //if server version change update supported features - if (![app.activeUser.capabilitiesDto.versionString isEqualToString:capabilities.versionString]) { - [self updateServerFeaturesOfActiveUserForVersion:capabilities.versionString]; - } + [self updateServerFeaturesOfActiveUserForVersion:capabilities.versionString]; //update file list view if needed BOOL capabilitiesShareAPIChanged = (app.activeUser.capabilitiesDto.isFilesSharingAPIEnabled == capabilities.isFilesSharingAPIEnabled)? NO:YES; diff --git a/Owncloud iOs Client/Network/Uploads/ManageUploadRequest.m b/Owncloud iOs Client/Network/Uploads/ManageUploadRequest.m index 6a4f01dfa6..50cb6e2abc 100644 --- a/Owncloud iOs Client/Network/Uploads/ManageUploadRequest.m +++ b/Owncloud iOs Client/Network/Uploads/ManageUploadRequest.m @@ -229,6 +229,8 @@ - (void) startUploadFile { self.userUploading = [ManageUsersDB getUserByUserId:self.currentUpload.userId]; [[AppDelegate sharedOCCommunication] setCredentials:self.userUploading.credDto]; + DLog(@"starting to upload to destinyFolder: %@, uploadFileName:%@, of user:%@ with accessToken:%@ and refreshToken:%@",self.currentUpload.destinyFolder, self.currentUpload.uploadFileName, _userUploading.credDto.userId, _userUploading.credDto.accessToken, _userUploading.credDto.refreshToken); + [[AppDelegate sharedOCCommunication] setUserAgent:[UtilsUrls getUserAgent]]; diff --git a/Owncloud iOs Client/Network/UserData/DetectUserData.h b/Owncloud iOs Client/Network/UserData/DetectUserData.h index 260d112a7f..9d96785986 100644 --- a/Owncloud iOs Client/Network/UserData/DetectUserData.h +++ b/Owncloud iOs Client/Network/UserData/DetectUserData.h @@ -19,6 +19,6 @@ @interface DetectUserData : NSObject + (void) getUserDisplayNameOfServer:(NSString*)path credentials:(OCCredentialsDto *)credentials - withCompletion:(void(^)(NSString *displayName, NSError *error))completion; + withCompletion:(void(^)(NSString *serverUserID, NSString *displayName, NSError *error))completion; @end diff --git a/Owncloud iOs Client/Network/UserData/DetectUserData.m b/Owncloud iOs Client/Network/UserData/DetectUserData.m index df87747110..ba29ff38f1 100644 --- a/Owncloud iOs Client/Network/UserData/DetectUserData.m +++ b/Owncloud iOs Client/Network/UserData/DetectUserData.m @@ -25,26 +25,23 @@ @implementation DetectUserData + (void) getUserDisplayNameOfServer:(NSString*)path credentials:(OCCredentialsDto *)credentials - withCompletion:(void(^)(NSString *displayName, NSError *error))completion { - OCCommunication *sharedCommunication; + withCompletion:(void(^)(NSString *serverUserID, NSString *displayName, NSError *error))completion { - sharedCommunication = [AppDelegate sharedOCCommunication]; - - - [sharedCommunication setCredentials:credentials]; + [[AppDelegate sharedOCCommunication] setCredentials:credentials]; + DLog(@"credDto: %@",credentials.userName); - [sharedCommunication setValueOfUserAgent:[UtilsUrls getUserAgent]]; + [[AppDelegate sharedOCCommunication] setValueOfUserAgent:[UtilsUrls getUserAgent]]; - [sharedCommunication getUserDisplayNameOfServer:path onCommunication:sharedCommunication - success:^(NSHTTPURLResponse *response, NSString *displayName, NSString *redirectedServer) { + [[AppDelegate sharedOCCommunication] getUserDisplayNameOfServer:path onCommunication:[AppDelegate sharedOCCommunication] + success:^(NSHTTPURLResponse *response,NSString *serverUserID, NSString *displayName, NSString *redirectedServer) { if (displayName && ![displayName isEqualToString:@""]) { - completion(displayName, nil); + completion(serverUserID, displayName, nil); } else { - completion(nil, [UtilsFramework getErrorWithCode:0 andCustomMessageFromTheServer:NSLocalizedString(@"server_does_not_give_user_id", nil)]); + completion(nil, nil, [UtilsFramework getErrorWithCode:0 andCustomMessageFromTheServer:NSLocalizedString(@"server_does_not_give_user_id", nil)]); } } failure:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) { DLog(@"error when try to get server displayName: %@", error); - completion(nil, error); + completion(nil, nil, error); }]; } diff --git a/Owncloud iOs Client/Owncloud iOs Client-Info.plist b/Owncloud iOs Client/Owncloud iOs Client-Info.plist index 1cc62c444f..046b484381 100644 --- a/Owncloud iOs Client/Owncloud iOs Client-Info.plist +++ b/Owncloud iOs Client/Owncloud iOs Client-Info.plist @@ -78,7 +78,7 @@ CFBundleVersion - 1.0.5 + 1.0.6 ITSAppUsesNonExemptEncryption LSApplicationCategoryType diff --git a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.h b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.h index c64f81e4bd..99ddddd092 100644 --- a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.h +++ b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.h @@ -47,6 +47,8 @@ #import "SelectFolderNavigation.h" #import "ManageFavorites.h" #import "DetectUserData.h" +#import "TSMessage.h" +#import "TSMessageView.h" #ifdef CONTAINER_APP #import "Owncloud_iOs_Client-Swift.h" @@ -64,7 +66,7 @@ @interface FilesViewController : UIViewController +ELCImagePickerControllerDelegate, UISearchBarDelegate, UIAlertViewDelegate, MBProgressHUDDelegate, UITextFieldDelegate, DeleteFileDelegate, OpenWithDelegate, DownloadViewControllerDelegate, CheckAccessToServerDelegate, RenameDelegate, MoveFileDelegate, SWTableViewCellDelegate, ManageNetworkErrorsDelegate, ManageFavoritesDelegate, TSMessageViewProtocol> //Table view @property(nonatomic, strong) IBOutlet UITableView *tableView; diff --git a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m index c7f3fb8965..2dab7a0210 100644 --- a/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m +++ b/Owncloud iOs Client/Tabs/FileTab/FilesViewController.m @@ -405,7 +405,7 @@ - (void)initFilesView { } } else { DLog(@"User changed while check a folder"); - [UtilsFramework deleteAllCookies]; + [UtilsCookies restoreCookiesOfUser:app.activeUser]; } } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) { @@ -630,7 +630,11 @@ - (BOOL)shouldAutorotate { - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if (self.openWith && !IS_IPHONE) { - [self.openWith.documentInteractionController dismissMenuAnimated:NO]; + if (k_use_open_with_UIDocumentInteractionController) { + [self.openWith.documentInteractionController dismissMenuAnimated:NO]; + } else { + [self.openWith.activityView dismissViewControllerAnimated:NO completion:nil]; + } } if (self.plusActionSheet) { @@ -1027,6 +1031,41 @@ - (void) showAlertView:(NSString*)string { [_alert show]; } + +#pragma mark - TSMessages + +- (void)showWarningMessageWithText: (NSString *) message { + + //Run UI Updates + [TSMessage setDelegate:self]; + + if (self.navigationController.navigationBarHidden){ + [self.navigationController setNavigationBarHidden:NO]; + } + + [TSMessage showNotificationInViewController:self.navigationController + title:message + subtitle:nil + image:nil + type:TSMessageNotificationTypeWarning + duration:TSMessageNotificationDurationAutomatic + callback:nil + buttonTitle:nil + buttonCallback:nil + atPosition:TSMessageNotificationPositionNavBarOverlay + canBeDismissedByUser:YES]; +} + +#pragma mark - TSMessage Delegate + +- (void)customizeMessageView:(TSMessageView *)messageView +{ + messageView.alpha = messageAlpha; + messageView.duration = messageDuration; +} + + + #pragma mark - UITextFieldDelegate methods - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ @@ -1683,7 +1722,7 @@ - (void) goToFolder:(FileDto *) selectedFile { [self goToFolderWithoutCheck]; } else { - [self performSelectorOnMainThread:@selector(showAlertView:) + [self performSelectorOnMainThread:@selector(showWarningMessageWithText:) withObject:NSLocalizedString(@"not_possible_connect_to_server", nil) waitUntilDone:YES]; [self endLoading]; @@ -1779,15 +1818,13 @@ - (void) reloadTableFromDataBaseWithFileDto:(NSNotification *)notification { * show this data in the tableview. */ -(void)reloadTableFromDataBase { - - // DLog(@"self.fileIdToShowFiles.idFile: %d", self.fileIdToShowFiles.idFile); - //Ad the files of the folder + AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; + //Add the files of the folder _currentDirectoryArray = [ManageFilesDB getFilesByFileIdForActiveUser:_fileIdToShowFiles.idFile]; - // DLog(@"self.fileIdToShowFiles: %d", [self.currentDirectoryArray count]); //Sorted the files array - _sortedArray = [SortManager getSortedArrayFromCurrentDirectoryArray:_currentDirectoryArray forUser:APP_DELEGATE.activeUser]; + _sortedArray = [SortManager getSortedArrayFromCurrentDirectoryArray:_currentDirectoryArray forUser:app.activeUser]; //update gallery array [self updateArrayImagesInGallery]; @@ -1808,12 +1845,25 @@ -(void)reloadTableFromDataBase { -(void)reloadTableFileListAfterCapabilitiesUpdated { - _currentDirectoryArray = [ManageFilesDB getFilesByFileIdForActiveUser:_fileIdToShowFiles.idFile]; - _sortedArray = [SortManager getSortedArrayFromCurrentDirectoryArray:_currentDirectoryArray forUser:APP_DELEGATE.activeUser]; - dispatch_async(dispatch_get_main_queue(), ^{ - [self reloadTableFileList]; - }); + + [self updateCurrentFileToShowIfNeeded]; + + [self reloadTableFromDataBase]; +} + +- (void) updateCurrentFileToShowIfNeeded { + AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; + + //Workaround to find the _fileIdToShowFiles because some times there are problems with the changes active user, and this method is launched before the viewwillappear + if (app.activeUser) { + FileDto *rootFileDtoOfActiveUser = [ManageFilesDB getRootFileDtoByUser:app.activeUser]; + if (self.fileIdToShowFiles.userId != rootFileDtoOfActiveUser.userId) { + _fileIdToShowFiles = rootFileDtoOfActiveUser; + DLog(@"Changing between accounts, update _fileIdToShowFiles with root file of active user %ld, %@", (long)app.activeUser.userId, app.activeUser.username); + } + } } + -(void)reloadTableFileList{ [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; } @@ -1825,13 +1875,14 @@ -(void)reloadTableFileList{ -(void)reloadTableFromDataBaseWithoutEndLoading { // DLog(@"self.fileIdToShowFiles.idFile: %d", self.fileIdToShowFiles.idFile); - + AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; + //Ad the files of the folder _currentDirectoryArray = [ManageFilesDB getFilesByFileIdForActiveUser:_fileIdToShowFiles.idFile]; // DLog(@"self.fileIdToShowFiles: %d", [self.currentDirectoryArray count]); //Sorted the files array - _sortedArray = [SortManager getSortedArrayFromCurrentDirectoryArray:_currentDirectoryArray forUser:APP_DELEGATE.activeUser]; + _sortedArray = [SortManager getSortedArrayFromCurrentDirectoryArray:_currentDirectoryArray forUser:app.activeUser]; //update gallery array [self updateArrayImagesInGallery]; @@ -2170,18 +2221,8 @@ - (void) refreshSharedPath{ //GCD to do things async in background queue dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ - //Do operations in background thread - //Workaround to find the _fileIdToShowFiles because some times there are problems with the changes active user, and this method is launched before the viewwillappear - if (app.activeUser) { - FileDto *rootFileDto = [ManageFilesDB getRootFileDtoByUser:app.activeUser]; - NSString *pathActiveUser = rootFileDto.filePath; - - if ([_fileIdToShowFiles.filePath rangeOfString:pathActiveUser].location == NSNotFound) { - _fileIdToShowFiles = rootFileDto; - DLog(@"Changing between accounts, update _fileIdToShowFiles with root path with the active user"); - } - } + [self updateCurrentFileToShowIfNeeded]; NSArray *itemsToDelete = [ManageSharesDB getSharesByFolderPath:[NSString stringWithFormat:@"/%@%@", [UtilsUrls getFilePathOnDBByFilePathOnFileDto:_fileIdToShowFiles.filePath andUser:app.activeUser], _fileIdToShowFiles.fileName]]; @@ -2254,6 +2295,7 @@ - (void)showSortingOptions{ */ - (void) updateActiveUserSortingChoiceTo: (enumSortingType)sortingChoice{ APP_DELEGATE.activeUser.sortingType = sortingChoice; + _mUser.sortingType = sortingChoice; [ManageUsersDB updateSortingWayForUserDto:APP_DELEGATE.activeUser]; } @@ -2298,7 +2340,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn case 3: if (self.isCurrentFolderSonOfFavoriteFolder) { - [self performSelectorOnMainThread:@selector(showAlertView:) + [self performSelectorOnMainThread:@selector(showWarningMessageWithText:) withObject:NSLocalizedString(@"parent_folder_is_available_offline_folder_child", nil) waitUntilDone:YES]; } else { @@ -2320,7 +2362,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn if (_selectedFileDto.isDownload || [[CheckAccessToServer sharedManager] isNetworkIsReachable]){ [self didSelectOpenWithOptionAndFile:_selectedFileDto]; } else { - [self performSelectorOnMainThread:@selector(showAlertView:) + [self performSelectorOnMainThread:@selector(showWarningMessageWithText:) withObject:NSLocalizedString(@"not_possible_connect_to_server", nil) waitUntilDone:YES]; } @@ -2333,7 +2375,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn break; case 3: if (self.isCurrentFolderSonOfFavoriteFolder) { - [self performSelectorOnMainThread:@selector(showAlertView:) + [self performSelectorOnMainThread:@selector(showWarningMessageWithText:) withObject:NSLocalizedString(@"parent_folder_is_available_offline_file_child", nil) waitUntilDone:YES]; } else { @@ -2516,7 +2558,11 @@ - (void)didSelectOpenWithOptionAndFile:(FileDto *)file { if (_selectedIndexPath) { cell = [_tableView cellForRowAtIndexPath:_selectedIndexPath]; _openWith.parentView =_tableView; - _openWith.cellFrame = [self.tableView rectForRowAtIndexPath:self.selectedIndexPath]; + if (k_use_open_with_UIDocumentInteractionController) { + _openWith.cellFrame = [self.tableView rectForRowAtIndexPath:self.selectedIndexPath]; + } else { + _openWith.cellFrame = cell.frame; + } _openWith.isTheParentViewACell = YES; } else { @@ -3285,7 +3331,7 @@ - (void)manageServerErrors: (NSInteger)errorCodeFromServer and:(NSError *)error */ - (void)showError:(NSString *) message { - [self performSelectorOnMainThread:@selector(showAlertView:) + [self performSelectorOnMainThread:@selector(showWarningMessageWithText:) withObject:message waitUntilDone:YES]; @@ -3340,8 +3386,8 @@ -(void)connectionToTheServerWasChecked:(BOOL)isConnected withHttpStatusCode:(NSI DLog(@"Ok, we have connection to the server"); } else { //Error msg - //Call showAlertView in main thread - [self performSelectorOnMainThread:@selector(showAlertView:) + //Call show error in main thread + [self performSelectorOnMainThread:@selector(showWarningMessageWithText:) withObject:NSLocalizedString(@"not_possible_connect_to_server", nil) waitUntilDone:YES]; } diff --git a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h index b61ca389d8..69b4662782 100644 --- a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h +++ b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.h @@ -38,6 +38,12 @@ @property(nonatomic, strong) UIView *parentView; @property(nonatomic, strong) UIDocumentInteractionController *documentInteractionController; +/* Use UIActivityViewController and UIPopoverController instead of UIDocumentInteractionController + * for open with option until fix for UIDocumentInteractionController in iOS11 + */ +@property(nonatomic, strong) UIActivityViewController *activityView; +@property (nonatomic, strong) UIPopoverController *activityPopoverController; + @property(nonatomic, strong) UIBarButtonItem *parentButton; @property(nonatomic, strong) Download *download; @property(nonatomic, strong) NSString *currentLocalFolder; diff --git a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m index b1a9eb99c0..5363326612 100644 --- a/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m +++ b/Owncloud iOs Client/Tabs/FileTab/OpenWith/OpenWith.m @@ -22,6 +22,7 @@ #import "DetailViewController.h" #import "TTOpenInAppActivity.h" #import "PresentedViewUtils.h" +#import "Customization.h" @@ -88,30 +89,104 @@ - (void)openWithFile: (FileDto *) file{ //Check if the localFolder is null. if (file.localFolder) { - DLog(@"File path is %@", file.localFolder); + DLog(@"File path is %@", file.localFolder); - //Pass path to url - NSURL *url = [NSURL fileURLWithPath:file.localFolder]; - self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url]; - [self.documentInteractionController setDelegate:self]; - UIViewController *presentedView = [PresentedViewUtils getPresentedViewControllerInWindow:[[[UIApplication sharedApplication] windows] lastObject]]; - - if (_isTheParentViewACell) { + if (k_use_open_with_UIDocumentInteractionController) { + + //Pass path to url + NSURL *url = [NSURL fileURLWithPath:file.localFolder]; + self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url]; + [self.documentInteractionController setDelegate:self]; + UIViewController *presentedView = [PresentedViewUtils getPresentedViewControllerInWindow:[[[UIApplication sharedApplication] windows] lastObject]]; + + if (_isTheParentViewACell) { + + [self.documentInteractionController presentOpenInMenuFromRect:self.cellFrame inView:self.parentView animated:YES]; + + } else { + + if (IS_IPHONE) { + [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:presentedView.view animated:YES]; + + } else { + [self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.parentButton animated:YES]; + + } + + } - [self.documentInteractionController presentOpenInMenuFromRect:self.cellFrame inView:self.parentView animated:YES]; - } else { + + AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate]; + + DLog(@"File path is %@", file.localFolder); + + //Pass path to url + NSURL *url = [NSURL fileURLWithPath:file.localFolder]; + + TTOpenInAppActivity *openInAppActivity; + + if (_isTheParentViewACell) { + openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.parentView andRect:_cellFrame]; + + }else{ + openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:self.parentView andBarButtonItem:self.parentButton]; + } + + + if (self.activityView) { + [self.activityView dismissViewControllerAnimated:YES completion:nil]; + self.activityView = nil; + } + + if (self.activityPopoverController) { + [self.activityPopoverController dismissPopoverAnimated:YES]; + self.activityPopoverController = nil; + } + + self.activityView = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:@[openInAppActivity]]; if (IS_IPHONE) { - [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:presentedView.view animated:YES]; - + + openInAppActivity.superViewController = self.activityView; + + [app.ocTabBarController presentViewController:self.activityView animated:YES completion:nil]; } else { - [self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.parentButton animated:YES]; - + + if (self.activityPopoverController) { + [self.activityPopoverController setContentViewController:self.activityView]; + } else { + self.activityPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.activityView]; + } + + openInAppActivity.superViewController = self.activityPopoverController; + + if (_isTheParentViewACell && IS_PORTRAIT && (IS_IOS8 || IS_IOS9)) { + + [self.activityPopoverController presentPopoverFromRect:CGRectMake(app.detailViewController.view.frame.size.width/2, app.detailViewController.view.frame.size.width/2, 100, 100) inView:app.detailViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; + + }else{ + + if (_isTheParentViewACell) { + //Present view from cell from file list + [self.activityPopoverController presentPopoverFromRect:_cellFrame inView:_parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; + + } else if (_parentButton) { + //Present view from bar button item + [self.activityPopoverController presentPopoverFromBarButtonItem:_parentButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; + + } else { + //Present view from rect + [self.activityPopoverController presentPopoverFromRect:CGRectMake(100, 100, 200, 400) inView:_parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; + } + } } + } } + + } #pragma mark - UIDocumentInteractionControllerDelegate methods diff --git a/Owncloud iOs Client/Tabs/FileTab/Share/Cells/ShareFileCell.xib b/Owncloud iOs Client/Tabs/FileTab/Share/Cells/ShareFileCell.xib index 4dc2dbd794..96bd6ef716 100644 --- a/Owncloud iOs Client/Tabs/FileTab/Share/Cells/ShareFileCell.xib +++ b/Owncloud iOs Client/Tabs/FileTab/Share/Cells/ShareFileCell.xib @@ -1,10 +1,10 @@ - - + + - + @@ -14,7 +14,7 @@ - + @@ -42,7 +42,7 @@ -