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

Add UnauthorizedError screen for invalid cloud access in Files app #384

Merged
merged 5 commits into from
Oct 15, 2024

Conversation

iammajid
Copy link
Contributor

@iammajid iammajid commented Oct 9, 2024

This feature introduces a screen that is displayed when using the files app and the authentication fails for a cloud provider. The screen informs the user that they need to return to the main app to reauthenticate in order to regain access to the vault. This enhancement was implemented in response to #18.

Copy link

coderabbitai bot commented Oct 9, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces three new source files: ReauthenticationViewController.swift, UnauthorizedErrorViewController.swift, and FileProviderCoordinatorError.swift, to the Cryptomator project. Modifications to the FileProviderCoordinator class enhance error handling and navigation related to reauthentication and unauthorized access. Additionally, localizable strings for reauthentication have been added in both German and English to provide user feedback. These changes collectively improve the user experience during authentication processes within the application.

Changes

File Change Summary
Cryptomator.xcodeproj/project.pbxproj Added new source files: ReauthenticationViewController.swift, UnauthorizedErrorViewController.swift, and FileProviderCoordinatorError.swift under "Sources".
FileProviderExtensionUI/FileProviderCoordinator.swift Modified FileProviderCoordinator to enhance error handling and added methods for reauthentication. New variable isReauthenticationInProgress added.
FileProviderExtensionUI/ReauthenticationViewController.swift Introduced ReauthenticationViewController class with methods for managing reauthentication UI. Added ReauthenticationHeaderView class.
FileProviderExtensionUI/UnauthorizedErrorViewController.swift Introduced UnauthorizedErrorViewController class for handling unauthorized access errors.
FileProviderExtensionUI/FileProviderCoordinatorError.swift Added enumeration FileProviderCoordinatorError to represent unauthorized access errors.
SharedResources/de.lproj/Localizable.strings Added new localization string for reauthentication in German.
SharedResources/en.lproj/Localizable.strings Added new localization string for reauthentication in English.

Poem

In the code where bunnies hop,
New views for errors, we won't stop!
With strings in two tongues,
Our message now sung,
"Authenticate, dear vault, don't drop!" 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (5)
FileProviderExtensionUI/ReauthenticationViewController.swift (4)

16-31: LGTM: Well-implemented lazy property and initializer.

The lazy property for the cell and the custom initializer are well-implemented. Good use of localization for the cell text.

Consider adding a comment explaining why init(coder:) is unavailable, for better code documentation:

/// This view controller is not designed to be initialized from a storyboard
@available(*, unavailable)
required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

33-44: LGTM: UI setup and cancellation handling look good.

The viewDidLoad method properly sets up the UI elements, and the done method correctly delegates the cancellation action to the coordinator.

Consider adding a check for the coordinator's existence in the done method to handle potential nil cases:

@objc func done() {
    coordinator?.userCancelled() ?? print("Warning: Coordinator is nil")
}

This will help catch any unexpected nil coordinator scenarios during development.


60-70: LGTM: TableView delegate methods are well-implemented.

The UITableViewDelegate methods are correctly implemented. The header view creation and row selection handling are appropriate.

Consider adding a check for the coordinator's existence in the didSelectRowAt method:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)
    coordinator?.openCryptomatorApp() ?? print("Warning: Coordinator is nil")
}

This will help catch any unexpected nil coordinator scenarios during development.


82-82: Fix trailing newline.

Add a single trailing newline at the end of the file to comply with SwiftLint rules and maintain consistent formatting.

 }
+
🧰 Tools
🪛 SwiftLint

[Warning] 82-82: Files should have a single trailing newline

(trailing_newline)

SharedResources/en.lproj/Localizable.strings (1)

104-104: LGTM! Consider adding a period at the end for consistency.

The new localization string for reauthentication is clear, informative, and aligns well with the PR objectives. It provides specific instructions to the user and uses a placeholder for the vault name, which is good for localization.

For consistency with other error messages in this file, consider adding a period at the end of the sentence.

Here's a suggested minor improvement:

-"fileprovider.error.reauthentication" = "The cloud access of your vault \"%@\" needs to be re-authenticated. Open the main app to do so.";
+"fileprovider.error.reauthentication" = "The cloud access of your vault \"%@\" needs to be re-authenticated. Open the main app to do so.";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 87bda1b and 58e8dc1.

📒 Files selected for processing (5)
  • Cryptomator.xcodeproj/project.pbxproj (4 hunks)
  • FileProviderExtensionUI/FileProviderCoordinator.swift (3 hunks)
  • FileProviderExtensionUI/ReauthenticationViewController.swift (1 hunks)
  • SharedResources/de.lproj/Localizable.strings (1 hunks)
  • SharedResources/en.lproj/Localizable.strings (1 hunks)
🧰 Additional context used
🪛 SwiftLint
FileProviderExtensionUI/FileProviderCoordinator.swift

[Warning] 89-89: Lines should not have trailing whitespace

(trailing_whitespace)

FileProviderExtensionUI/ReauthenticationViewController.swift

[Warning] 82-82: Files should have a single trailing newline

(trailing_newline)

🔇 Additional comments (10)
FileProviderExtensionUI/ReauthenticationViewController.swift (4)

1-15: LGTM: Imports and class declaration are well-structured.

The imports, class declaration, and property definitions are appropriate for the ReauthenticationViewController. The weak reference to the FileProviderCoordinator is a good practice to avoid retain cycles.


46-58: LGTM: TableView data source methods are correctly implemented.

The implementation of the UITableViewDataSource methods is correct and efficient for a single-cell table view. Good use of the pre-configured openCryptomatorCell.


72-82: LGTM: ReauthenticationHeaderView is well-implemented.

The ReauthenticationHeaderView class is correctly implemented as a private inner class. Good use of system images and localized strings for creating a context-specific header view.

🧰 Tools
🪛 SwiftLint

[Warning] 82-82: Files should have a single trailing newline

(trailing_newline)


1-82: Overall: Well-implemented reauthentication view controller.

The ReauthenticationViewController is well-structured and follows good Swift programming practices. It effectively handles the reauthentication UI for the Cryptomator app. The code is clean, uses appropriate iOS UI patterns, and incorporates localization for better user experience.

Minor suggestions were made for improved error handling and documentation, but these are not critical issues. The implementation aligns well with the PR objectives of adding a reauthentication screen for invalid cloud access in the Files app.

Great job on this implementation!

🧰 Tools
🪛 SwiftLint

[Warning] 82-82: Files should have a single trailing newline

(trailing_newline)

SharedResources/en.lproj/Localizable.strings (1)

Line range hint 1-104: Summary: New localization string added for reauthentication scenario

The changes in this file are minimal and focused. A single new localization string has been added to handle the reauthentication scenario for cloud access in vaults. This addition aligns perfectly with the PR objectives of introducing a new screen for authentication failure.

The new string provides clear instructions to the user and uses proper localization techniques (placeholder for vault name). Its placement in the file is appropriate, and it follows the existing naming conventions.

These changes enhance the user experience by providing clear guidance when reauthentication is needed, which is a valuable improvement to the application.

SharedResources/de.lproj/Localizable.strings (1)

104-104: LGTM! New localization string aligns with PR objectives.

The newly added German localization string for reauthentication is well-formed and consistent with the existing localization style. It clearly instructs the user to open the main app to reauthenticate when cloud access becomes invalid, which directly addresses the PR objective of adding a reauthentication screen.

Cryptomator.xcodeproj/project.pbxproj (1)

437-437: LGTM: New ReauthenticationViewController added correctly

The ReauthenticationViewController.swift file has been properly added to the project. This addition aligns with the PR objective of implementing a reauthentication screen for invalid cloud access in the Files app. The file is correctly included in the build phase and integrated into the project structure.

FileProviderExtensionUI/FileProviderCoordinator.swift (3)

19-19: Initialization of isReauthenticationInProgress

The addition of isReauthenticationInProgress correctly initializes the reauthentication tracking state.


144-147: Proper handling of unauthorized error

The unauthorized error case is handled appropriately by initiating reauthentication and updating the reauthentication state.


152-154: Guard statement prevents further actions during reauthentication

The guard statement correctly prevents further actions if reauthentication is already in progress.

FileProviderExtensionUI/FileProviderCoordinator.swift Outdated Show resolved Hide resolved
FileProviderExtensionUI/FileProviderCoordinator.swift Outdated Show resolved Hide resolved
Copy link
Member

@tobihagemann tobihagemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also fix the SwiftLint errors that were brought up in the CI action. You can also run these checks locally, see: https://github.com/cryptomator/ios?tab=readme-ov-file#contributing

SharedResources/de.lproj/Localizable.strings Outdated Show resolved Hide resolved
FileProviderExtensionUI/FileProviderCoordinator.swift Outdated Show resolved Hide resolved
FileProviderExtensionUI/FileProviderCoordinator.swift Outdated Show resolved Hide resolved
SharedResources/en.lproj/Localizable.strings Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
FileProviderExtensionUI/FileProviderCoordinatorError.swift (1)

11-13: LGTM: Enum declaration is well-structured. Consider adding documentation.

The FileProviderCoordinatorError enum is correctly defined as public and conforms to the Error protocol. The unauthorized case with its associated vaultName value is appropriate for the intended use case.

Consider adding documentation comments to describe the enum and its case. This can improve code readability and help generate better documentation. For example:

/// Represents errors that can occur in the FileProviderCoordinator.
public enum FileProviderCoordinatorError: Error {
    /// Indicates that access to a vault is unauthorized.
    /// - Parameter vaultName: The name of the vault that couldn't be accessed.
    case unauthorized(vaultName: String)
}
FileProviderExtensionUI/FileProviderCoordinator.swift (1)

143-144: LGTM: Improved error handling for unauthorized access

The addition of the LocalizedCloudProviderError.unauthorized case improves error handling and aligns with the PR objectives. Throwing a FileProviderCoordinatorError.unauthorized with the vault name is a good approach for triggering the reauthentication screen.

Minor suggestion: Consider adding a comment explaining the purpose of this specific error case, especially since FileProviderCoordinatorError is likely defined in another file.

FileProviderExtensionUI/UnauthorizedErrorViewController.swift (2)

37-37: Rename done method to cancel for clarity and consistency

The doneButton is initialized with barButtonSystemItem: .cancel, but the action method is named done. For clarity and consistency, consider renaming the method to cancel to match the button's purpose and system item.

Apply this change to rename the method and selector:

- let doneButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(done))
+ let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancel))

Update the method accordingly:

- @objc func done() {
+ @objc func cancel() {
    coordinator?.userCancelled()
}

Also applies to: 43-44


Line range hint 73-82: Implement required initializer in UnauthorizedErrorHeaderView

The subclass UnauthorizedErrorHeaderView should implement the required initializer init?(coder:). Omitting this initializer could lead to compilation errors or runtime issues if the class is ever initialized from a storyboard or nib.

Add the following unavailable initializer:

@available(*, unavailable)
required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 58e8dc1 and 99a4534.

📒 Files selected for processing (5)
  • Cryptomator.xcodeproj/project.pbxproj (4 hunks)
  • FileProviderExtensionUI/FileProviderCoordinator.swift (2 hunks)
  • FileProviderExtensionUI/FileProviderCoordinatorError.swift (1 hunks)
  • FileProviderExtensionUI/UnauthorizedErrorViewController.swift (1 hunks)
  • SharedResources/en.lproj/Localizable.strings (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • SharedResources/en.lproj/Localizable.strings
🧰 Additional context used
🔇 Additional comments (10)
FileProviderExtensionUI/FileProviderCoordinatorError.swift (1)

1-10: LGTM: File header and imports are appropriate.

The file header contains all the necessary information, and the Foundation import is correct for defining an error type in Swift.

FileProviderExtensionUI/FileProviderCoordinator.swift (2)

83-87: LGTM: New method for showing unauthorized error screen

The showUnauthorizedError(vaultName:) method is well-implemented. It correctly creates and presents an UnauthorizedErrorViewController, which aligns with the PR objective of introducing a reauthentication screen for invalid cloud access.


Line range hint 1-204: Overall assessment: Well-implemented reauthentication functionality

The changes in this file successfully implement the new reauthentication screen functionality for invalid cloud access in the Files app. The additions and modifications align well with the PR objectives and follow good coding practices. The error handling has been improved to address unauthorized access scenarios, which should enhance the user experience.

Cryptomator.xcodeproj/project.pbxproj (3)

437-438: New file added: UnauthorizedErrorViewController.swift

The UnauthorizedErrorViewController.swift file has been correctly added to the project. It is included in the PBXBuildFile section with a unique identifier, which is the standard way of adding new files to an Xcode project.


438-439: New file added: FileProviderCoordinatorError.swift

The FileProviderCoordinatorError.swift file has been properly added to the project. It is also included in the PBXBuildFile section with a unique identifier, following the correct procedure for adding new files to an Xcode project.


437-439: Summary of changes

The project file has been updated to include two new Swift files: UnauthorizedErrorViewController.swift and FileProviderCoordinatorError.swift. These additions are consistent with the AI-generated summary and appear to be correctly integrated into the project structure. No other significant changes or inconsistencies were found in the project file.

These new files likely introduce functionality for handling unauthorized errors and defining error types for the file provider coordinator, which aligns with the PR objective of adding a reauthentication screen for invalid cloud access in the Files app.

FileProviderExtensionUI/UnauthorizedErrorViewController.swift (4)

13-13: Use of weak reference for coordinator prevents retain cycles

Declaring coordinator as a weak variable appropriately prevents retain cycles between the view controller and the coordinator.


36-36: Verify that long vault names display correctly in the navigation bar

Setting title = vaultName may cause layout issues if vaultName is excessively long. Ensure that long vault names are properly truncated or adjusted to fit within the navigation bar without affecting the UI layout.


76-76: Ensure color contrast meets accessibility standards

The symbolImage uses .systemYellow, which might not provide sufficient contrast against certain background colors. Verify that the color contrast meets accessibility guidelines to enhance readability for all users.

You can use accessibility inspection tools to check the contrast ratio.


78-78: Verify localized string formatting

Ensure that the localized string for key "fileprovider.error.reauthentication" includes the correct format specifier (e.g., %@) to properly insert the vaultName. This prevents runtime issues and ensures the message displays correctly in all languages.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
FileProviderExtensionUI/UnauthorizedErrorViewController.swift (1)

46-70: LGTM: Table view methods are well-implemented.

The table view data source and delegate methods are correctly implemented for a single-section, single-row table view. The code is clear and concise.

Consider grouping the UITableViewDataSource and UITableViewDelegate methods together under a single MARK: comment for better code organization:

// MARK: - UITableViewDataSource & UITableViewDelegate

override func numberOfSections(in tableView: UITableView) -> Int {
    // ...
}

// ... (other methods)

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    // ...
}

This grouping can improve readability, especially as the file grows.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f7821ec and 0bfa725.

📒 Files selected for processing (3)
  • FileProviderExtensionUI/FileProviderCoordinator.swift (3 hunks)
  • FileProviderExtensionUI/UnauthorizedErrorViewController.swift (1 hunks)
  • SharedResources/en.lproj/Localizable.strings (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • FileProviderExtensionUI/FileProviderCoordinator.swift
  • SharedResources/en.lproj/Localizable.strings
🧰 Additional context used
🔇 Additional comments (3)
FileProviderExtensionUI/UnauthorizedErrorViewController.swift (3)

1-11: LGTM: File header and imports are appropriate.

The file header contains the necessary copyright information, and the imports are relevant for the functionality implemented in this file.


1-81: Summary: Solid implementation with room for minor enhancements

Overall, the UnauthorizedErrorViewController and UnauthorizedErrorHeaderView classes are well-implemented and fulfill their purpose of handling unauthorized access errors. The code is clear, concise, and follows good practices for iOS development.

Main points for improvement:

  1. Implement dynamic type support for better accessibility, especially in the UnauthorizedErrorHeaderView.
  2. Extract string literals to constants or enums for improved maintainability.
  3. Consider grouping table view methods under a single MARK comment for better code organization.

These enhancements will further improve the code quality and user experience. Great job on the implementation!


72-81: 🛠️ Refactor suggestion

Ensure consistency with DetectedVaultFailureView and implement dynamic type support.

The UnauthorizedErrorHeaderView implementation looks good overall, but there are two points to address:

  1. Consistency: A previous comment noted that DetectedVaultFailureView uses a point size of 120. This class is now consistent with that, which is good.

  2. Dynamic Type Support: As mentioned in a previous comment, implement dynamic type support for better accessibility.

To address both points, update the init method as follows:

init(vaultName: String) {
    let basePointSize: CGFloat = 120
    let scaledPointSize = UIFontMetrics.default.scaledValue(for: basePointSize)
    let config = UIImage.SymbolConfiguration(pointSize: scaledPointSize)
    let symbolImage = UIImage(systemName: "exclamationmark.triangle.fill", withConfiguration: config)?
        .withTintColor(.systemYellow, renderingMode: .alwaysOriginal)

    let infoText = String(format: LocalizedString.getValue("fileprovider.error.unauthorized.text"), vaultName)

    super.init(image: symbolImage, infoText: infoText)
}

This change maintains consistency with DetectedVaultFailureView while also supporting dynamic type.

To ensure consistency across the app, let's check if DetectedVaultFailureView also needs this update:

#!/bin/bash
# Search for DetectedVaultFailureView implementation
rg --type swift 'class DetectedVaultFailureView'

@tobihagemann tobihagemann changed the title Add Reauthentication screen for invalid cloud access in Files app Add UnauthorizedError screen for invalid cloud access in Files app Oct 15, 2024
@tobihagemann tobihagemann merged commit 483223f into develop Oct 15, 2024
3 of 4 checks passed
@tobihagemann tobihagemann deleted the feature/authentication-failure-screen branch October 15, 2024 10:16
@tobihagemann tobihagemann added this to the 2.6.3 milestone Oct 15, 2024
@tobihagemann tobihagemann linked an issue Oct 15, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Screen: Files App - Auth Failure
2 participants