Skip to content

Commit

Permalink
#972 rename account name only (bookmark) is possible without re-authe…
Browse files Browse the repository at this point in the history
…ntication flow
  • Loading branch information
hosy committed Jan 31, 2022
1 parent 8f8385a commit fe4e2d4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 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,25 @@ 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 {
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!")
}

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

return
}

if (bookmark?.url == nil) || (bookmark?.authenticationMethodIdentifier == nil) {
handleContinueURLProbe(hud: hud, hudCompletion: hudCompletion)
return
Expand Down

0 comments on commit fe4e2d4

Please sign in to comment.