Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/rename-accounts] Rename Account without Authentication Flow #1097

Merged
merged 8 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
Changelog for ownCloud iOS Client [unreleased] (UNRELEASED)
=======================================
The following sections list the changes in ownCloud iOS Client unreleased relevant to
ownCloud admins and users.

[unreleased]: https://github.com/owncloud/ios-app/compare/milestone/11.8.2...master

Summary
-------

* Change - Rename Account (without re-authentication): [#972](https://github.com/owncloud/ios-app/issues/972)

Details
-------

* Change - Rename Account (without re-authentication): [#972](https://github.com/owncloud/ios-app/issues/972)

Check if only the account name was changed in edit mode: save and dismiss without
re-authentication

https://github.com/owncloud/ios-app/issues/972

Changelog for ownCloud iOS Client [11.8.2] (2022-01-17)
=======================================
The following sections list the changes in ownCloud iOS Client 11.8.2 relevant to
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/972
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change: Rename Account (without re-authentication)

Check if only the account name was changed in edit mode: save and dismiss without re-authentication

https://github.com/owncloud/ios-app/issues/972
51 changes: 35 additions & 16 deletions ownCloud/Bookmarks/BookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ class BookmarkViewController: StaticTableViewController {
// MARK: - UI elements
var nameSection : StaticTableViewSection?
var nameRow : StaticTableViewRow?
var nameChanged = false

var urlSection : StaticTableViewSection?
var urlRow : StaticTableViewRow?
var urlChanged = false
var certificateRow : StaticTableViewRow?

var credentialsSection : StaticTableViewSection?
Expand Down Expand Up @@ -129,6 +131,7 @@ class BookmarkViewController: StaticTableViewController {
// Name section + row
nameRow = StaticTableViewRow(textFieldWithAction: { [weak self] (_, sender, action) in
if let textField = sender as? UITextField, action == .changed {
self?.nameChanged = true
self?.bookmark?.name = (textField.text?.count == 0) ? nil : textField.text
}
}, placeholder: "Name".localized, value: editBookmark?.name ?? "", identifier: "row-name-name", accessibilityLabel: "Server name".localized)
Expand All @@ -140,6 +143,7 @@ class BookmarkViewController: StaticTableViewController {
if let textField = sender as? UITextField, action == .changed {
var placeholderString = "Name".localized
var changedBookmark = false
self?.urlChanged = true

// Disable Continue button if there is no url
if textField.text != "" {
Expand Down Expand Up @@ -337,6 +341,13 @@ class BookmarkViewController: StaticTableViewController {
}
}

// Check if only account name was changed in edit mode: save and dismiss without re-authentication
if mode == .edit, nameChanged, !urlChanged, let bookmark = bookmark {
updateBookmark(bookmark: bookmark)
completeAndDismiss(with: hudCompletion)
return
}

if (bookmark?.url == nil) || (bookmark?.authenticationMethodIdentifier == nil) {
handleContinueURLProbe(hud: hud, hudCompletion: hudCompletion)
return
Expand Down Expand Up @@ -523,6 +534,21 @@ class BookmarkViewController: StaticTableViewController {
}
}

func completeAndDismiss(with hudCompletion: @escaping (((() -> Void)?) -> Void)) {
guard let userActionCompletionHandler = self.userActionCompletionHandler else { return }

self.userActionCompletionHandler = nil

OnMainThread {
hudCompletion({
OnMainThread {
userActionCompletionHandler(self.bookmark, true)
}
self.presentingViewController?.dismiss(animated: true, completion: nil)
})
}
}

// MARK: - User actions
@objc func userActionCancel() {
let userActionCompletionHandler = self.userActionCompletionHandler
Expand Down Expand Up @@ -553,6 +579,13 @@ class BookmarkViewController: StaticTableViewController {
save(hudCompletion: hudCompletion)
}

func updateBookmark(bookmark: OCBookmark) {
originalBookmark?.setValuesFrom(bookmark)
if let originalBookmark = originalBookmark, !OCBookmarkManager.shared.updateBookmark(originalBookmark) {
Log.error("Changes to \(originalBookmark) not saved as it's not tracked by OCBookmarkManager!")
}
}

func save(hudCompletion: @escaping (((() -> Void)?) -> Void)) {
guard let bookmark = self.bookmark else { return }

Expand All @@ -573,24 +606,10 @@ class BookmarkViewController: StaticTableViewController {

case .edit:
// Update original bookmark
self?.originalBookmark?.setValuesFrom(bookmark)
if let originalBookmark = self?.originalBookmark, !OCBookmarkManager.shared.updateBookmark(originalBookmark) {
Log.error("Changes to \(originalBookmark) not saved as it's not tracked by OCBookmarkManager!")
}
}

let userActionCompletionHandler = strongSelf.userActionCompletionHandler
strongSelf.userActionCompletionHandler = nil

OnMainThread {
hudCompletion({
OnMainThread {
userActionCompletionHandler?(bookmark, true)
}
strongSelf.presentingViewController?.dismiss(animated: true, completion: nil)
})
self?.updateBookmark(bookmark: bookmark)
}

strongSelf.completeAndDismiss(with: hudCompletion)
})
} else {
OnMainThread {
Expand Down