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: Adjust Hub workflow, if device is already registerd #3210

Merged
merged 13 commits into from Jan 11, 2024

Conversation

infeo
Copy link
Member

@infeo infeo commented Nov 17, 2023

Closes #3203

Removes the "device already exists label" in register device screen and shows setupFailed screen, when the device already exists. This changes it now to a unlock terminating action.

The setupFailed screen shows a custom message, if it is shown with a DeviceAlreadyExistsException:
grafik

Summary by CodeRabbit

  • New Features

    • Enhanced registration flow with improved error handling and messaging.
  • Bug Fixes

    • Fixed an issue where closing the registration window did not properly cancel the operation.
  • Refactor

    • Updated class and method names to reflect the shift from device setup to device registration.
  • Style

    • Adjusted UI alignment attributes for error messages.
  • Documentation

    • Updated user-facing messages and labels for greater clarity in the registration process.

@infeo infeo self-assigned this Nov 17, 2023
@infeo infeo added the misc:gui label Nov 17, 2023
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.

While we're at it, I'd like to change "naming device" to "registering device".

src/main/resources/i18n/strings.properties Outdated Show resolved Hide resolved
src/main/resources/i18n/strings.properties Outdated Show resolved Hide resolved
src/main/resources/i18n/strings.properties Outdated Show resolved Hide resolved
Co-authored-by: Tobias Hagemann <tobias.hagemann@skymatic.de>
/**
* Thrown, when Hub registerDevice-Request returns with 409
*/
public class DeviceAlreadyExistsException extends RuntimeException {}
Copy link
Member

Choose a reason for hiding this comment

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

We have a checked exception type for errors during unlock. I believe its name is sth like MasterkeyLoadingFailed

Comment on lines 188 to 190
if (cause instanceof DeviceAlreadyExistsException) {
LOG.debug("Device already registered in hub instance {} for different user", hubConfig.authSuccessUrl);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Can be a separate case in the switch block

Comment on lines 75 to 82
@Provides
@KeyLoadingScoped
@Named("registerException")
static AtomicReference<Throwable> provideRegisterException() {
return new AtomicReference<>();
}


Copy link
Member

Choose a reason for hiding this comment

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

What is this used for?

Copy link
Member Author

Choose a reason for hiding this comment

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

I reused the registrationFailed dialog. To differentiate between "Device already exists" and any other generic error, i have to inject the Throwable into the dialog controller. This is the injection object.

Copy link
Member

Choose a reason for hiding this comment

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

The point is: According to its name, this exception is specific to "registration", however I'm pretty certain that we already have some kind of mechanism to reference exceptional outcomes during this unlock workflow.

@infeo infeo added this to the 1.12.0 milestone Dec 18, 2023
Copy link

coderabbitai bot commented Jan 11, 2024

Warning

Rate Limit Exceeded

@overheadhunter has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 20 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between b85e455 and bfb26f6.

Walkthrough

The updates primarily address error handling and user feedback for device registration with Cryptomator Hub. A new exception class is introduced for a specific error case, and related UI components are updated to reflect more accurate error messages. The changes ensure that the error presented to the user when attempting to register a device already in use is clear and accurate. Additionally, there's a minor update to handle a window close event.

Changes

File Path Change Summary
.../common/FxmlFile.java
.../keyloading/hub/HubKeyLoadingModule.java
Renamed enum constant and updated annotation parameter from HUB_SETUP_DEVICE to HUB_REGISTER_DEVICE.
.../keyloading/hub/DeviceAlreadyExistsException.java Added a custom exception class for handling specific API response status.
.../keyloading/hub/HubKeyLoadingStrategy.java
.../keyloading/hub/ReceiveKeyController.java
.../keyloading/hub/RegisterDeviceController.java
.../keyloading/hub/RegisterFailedController.java
Introduced window close handling, adjusted method names, and added logic for handling new exception case.
.../resources/fxml/hub_register_device.fxml
.../resources/fxml/hub_register_failed.fxml
Updated FXML to adjust UI elements for error messaging.
.../resources/i18n/strings.properties Modified text properties for clearer user messages on registration success and failure.

Assessment against linked issues

Objective Addressed Explanation
Update error message for device already in use (#3203)
Refine API path structure anomaly (#3203) The provided summary does not clearly indicate whether the API path issue with the double forward slash has been addressed.

Poem

In the world of code where bugs do hop,
A rabbit fixed the Hub with a hop and a bop.
No more confusion, no more despair,
"Device in use," it declares with care. 🐰✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 06859fe and a6d6474.
Files selected for processing (10)
  • src/main/java/org/cryptomator/ui/common/FxmlFile.java (1 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/DeviceAlreadyExistsException.java (1 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java (2 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java (2 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java (5 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java (6 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java (1 hunks)
  • src/main/resources/fxml/hub_register_device.fxml (1 hunks)
  • src/main/resources/fxml/hub_register_failed.fxml (1 hunks)
  • src/main/resources/i18n/strings.properties (1 hunks)
Additional comments: 18
src/main/java/org/cryptomator/ui/keyloading/hub/DeviceAlreadyExistsException.java (1)
  • 3-6: The DeviceAlreadyExistsException class is well-defined and extends RuntimeException. The comment above the class provides clear context for when this exception should be thrown.
src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java (1)
  • 7-37: The updates to RegisterFailedController include handling a new type of exception (DeviceAlreadyExistsException) and differentiating between a generic error and a device already existing error. These changes are consistent with the PR objectives.
src/main/resources/fxml/hub_register_failed.fxml (1)
  • 41-42: The FXML changes include adding two new Label elements with conditional visibility based on controller properties, providing different error messages for generic registration failure and device already existing failure. These changes are consistent with the PR objectives.
src/main/java/org/cryptomator/ui/common/FxmlFile.java (1)
  • 26-26: The FxmlFile enum has been updated to rename the HUB_SETUP_DEVICE constant to HUB_REGISTER_DEVICE. This change is consistent with the PR objectives.
src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java (1)
  • 46-46: The addition of a window close event handler in HubKeyLoadingStrategy to cancel the registration process if the window is closed is a good control flow improvement and is consistent with the PR objectives.
src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java (2)
  • 75-80: The addition of the provideRegisterException method in HubKeyLoadingModule is a new feature that supports the differentiation of errors in the registration process, aligning with the PR objectives.

  • 146-149: The update to provideHubRegisterDeviceScene method to use the renamed FXML file HUB_REGISTER_DEVICE is consistent with the PR objectives and the renaming done in the FxmlFile enum.

src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java (3)
  • 58-80: The updates to RegisterDeviceController include the addition of the registerException field and modifications to the constructor to handle the new exception type. These changes are consistent with the PR objectives.

  • 173-178: The handleRegisterDeviceResponse method has been updated to handle the DeviceAlreadyExistsException specifically, which aligns with the PR objectives to improve the user experience when a device is already registered with another user.

  • 188-193: The setupFailed method has been refined to log different messages based on whether the cause is a DeviceAlreadyExistsException or another type of exception. This is a good approach to provide more specific feedback to the user.

src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java (3)
  • 58-70: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [52-67]

The updates to ReceiveKeyController include renaming the setupDeviceScene field to registerDeviceScreen and modifying the needsDeviceSetup method to needsDeviceRegistration. These changes are consistent with the PR objectives.

  • 142-142: The needsDeviceRegistration method has been correctly updated to reflect the new registration flow, which is part of the PR objectives to improve the device registration process.

  • 150-151: The needsDeviceRegistration method correctly sets the scene to registerDeviceScreen, which is the updated flow for registering a device that is not yet associated with the user.

src/main/resources/i18n/strings.properties (5)
  • 164-164: The label for the registration button has been changed from "Confirm" to "Authorize" to better reflect the action being taken by the user.

  • 166-166: The success message for device registration has been updated to "Device registered" for clarity and to confirm the successful action.

  • 169-169: The failure message for device registration has been changed to "Device registration failed" which is more specific and informative.

  • 170-170: The generic error description for a failed registration has been updated to reflect the registration context rather than the previous "naming" context.

  • 171-171: A new error description has been added for the DeviceAlreadyExistsException, providing clear guidance for the user on how to proceed if the device is already registered under a different user.

use separate views, no need to pass state between views
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a6d6474 and a902400.
Files selected for processing (6)
  • src/main/java/org/cryptomator/ui/common/FxmlFile.java (1 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java (1 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java (6 hunks)
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java (2 hunks)
  • src/main/resources/fxml/hub_register_device_already_exists.fxml (1 hunks)
  • src/main/resources/fxml/hub_register_failed.fxml (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/RegisterFailedController.java
  • src/main/resources/fxml/hub_register_failed.fxml
Additional comments: 2
src/main/resources/fxml/hub_register_device_already_exists.fxml (1)
  • 1-51: The FXML structure for the hub_register_device_already_exists.fxml appears to be well-formed and correctly defines the UI elements for the new error screen. The use of FontAwesome5IconView for the icon, Label for messages, and Button for the close action are appropriate. The RegisterFailedController is correctly set as the controller for this view.

Ensure that the keys %hub.registerFailed.message and %hub.registerFailed.description.deviceAlreadyExists are properly defined in the strings.properties file and that they provide clear and user-friendly messages as intended by the PR objectives.

src/main/java/org/cryptomator/ui/common/FxmlFile.java (1)
  • 25-27: The changes to the FxmlFile enum include the addition of the HUB_REGISTER_DEVICE_ALREADY_EXISTS constant and the update to the HUB_REGISTER_DEVICE constant. This aligns with the PR objectives to introduce a new error screen and update the device registration flow.

Ensure that the new FXML file paths provided as constants are correct and that the corresponding FXML files exist at those locations in the project. Also, verify that all references to the old HUB_SETUP_DEVICE constant have been updated to the new HUB_REGISTER_DEVICE constant throughout the codebase.

Verification successful

The verification scripts have successfully located the hub_register_device_already_exists.fxml and hub_register_device.fxml files in the src/main/resources/fxml directory, confirming their existence in the codebase. Additionally, the rg command did not produce any output, which indicates that there are no remaining references to the HUB_SETUP_DEVICE constant in the Java files. This aligns with the PR objectives and the changes mentioned in the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new FXML file exists.
fd 'hub_register_device_already_exists.fxml' --exec test -f

# Verify that the renamed FXML file exists.
fd 'hub_register_device.fxml' --exec test -f

# Search for any remaining references to the old constant name.
rg 'HUB_SETUP_DEVICE' --type java

Length of output: 210



Script:

#!/bin/bash
# Correct the verification of the existence of the new FXML file.
fd 'hub_register_device_already_exists.fxml' --exec test -f {}

# Correct the verification of the existence of the renamed FXML file.
fd 'hub_register_device.fxml' --exec test -f {}

# Re-run the search for any remaining references to the old constant name with a corrected command.
rg 'HUB_SETUP_DEVICE' --type java

Length of output: 220



Script:

#!/bin/bash
# Simplify the verification of the existence of the new FXML file.
fd 'hub_register_device_already_exists.fxml'

# Simplify the verification of the existence of the renamed FXML file.
fd 'hub_register_device.fxml'

# Confirm that the rg command is executed correctly and there are no references to HUB_SETUP_DEVICE.
rg 'HUB_SETUP_DEVICE' --type java

Length of output: 221

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a902400 and b85e455.
Files selected for processing (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/ReceiveKeyController.java

Copy link
Member

@overheadhunter overheadhunter left a comment

Choose a reason for hiding this comment

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

I addressed my aforementioned findings by removing state variables such as registerException (which has only ever been used as a kind of "flag") and instead just add a new FXML dialog.

This might be a few more LoC, but is a way simpler structure.

@overheadhunter overheadhunter merged commit 5759b7e into develop Jan 11, 2024
5 checks passed
@overheadhunter overheadhunter deleted the feature/3203-device-already-registered branch January 11, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reusing a Cryptomator Hub device with another user shows device name already exists error
3 participants