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

fix: Prevent selecting "Drive root" and select "My personal files" #1296

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Changes from all 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
30 changes: 26 additions & 4 deletions kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ class SaveFileViewController: UIViewController {
) {
selectedDriveFileManager = driveFileManager
}
selectedDirectory = lastSelectedDirectory?.driveId == selectedDriveFileManager?.drive.id
? lastSelectedDirectory
: selectedDriveFileManager?.getCachedRootFile()
selectedDirectory = getBestDirectory()
}

closeBarButtonItem.accessibilityLabel = KDriveResourcesStrings.Localizable.buttonClose
Expand Down Expand Up @@ -161,6 +159,30 @@ class SaveFileViewController: UIViewController {
)
}

func getBestDirectory() -> File? {
if lastSelectedDirectory?.driveId == selectedDriveFileManager?.drive.id {
return lastSelectedDirectory
}

guard let selectedDriveFileManager else { return nil }

let myFilesDirectory = selectedDriveFileManager.database.fetchResults(ofType: File.self) { lazyFiles in
lazyFiles.filter("rawVisibility = %@", FileVisibility.isPrivateSpace.rawValue)
}.first

if let myFilesDirectory {
return myFilesDirectory.freezeIfNeeded()
}

// If we are in a shared with me, we only have access to some folders that are shared with the user
guard selectedDriveFileManager.drive.sharedWithMe else { return nil }

let firstAvailableSharedDriveDirectory = selectedDriveFileManager.database.fetchResults(ofType: File.self) { lazyFiles in
lazyFiles.filter("rawVisibility = %@ AND driveId == %d", FileVisibility.isInSharedSpace.rawValue, selectedDriveFileManager.drive.id)
}.first
return firstAvailableSharedDriveDirectory?.freezeIfNeeded()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
MatomoUtils.track(view: [MatomoUtils.Views.save.displayName, "SaveFile"])
Expand Down Expand Up @@ -476,7 +498,7 @@ extension SaveFileViewController: SelectDriveDelegate {
func didSelectDrive(_ drive: Drive) {
if let selectedDriveFileManager = accountManager.getDriveFileManager(for: drive.id, userId: drive.userId) {
self.selectedDriveFileManager = selectedDriveFileManager
selectedDirectory = selectedDriveFileManager.getCachedRootFile()
selectedDirectory = getBestDirectory()
sections = [.fileName, .driveSelection, .directorySelection]
if itemProvidersContainHeicPhotos {
sections.append(.photoFormatOption)
Expand Down
Loading