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: License status endpoint #264

Merged
merged 8 commits into from
Apr 17, 2024
Merged

Conversation

infeo
Copy link
Member

@infeo infeo commented Mar 15, 2024

Fixes #262.

This PR adds the new REST endpoint /license.

This endpoint is intended to give information about the license set in the hub instance. Currently, this endpoint does not have any direct actions, but only a subresource /license/user-info. This is intentional, because the longterm goal is to move the /billing endpoint to /license.

The subresource /license/user-info is intended for any user to get necessary information about the license like expiration date and licensed seats.

Remark: The license endpoint could also be used in the VaultDetails vue component, but due to a required refactoring there it is not used.

Summary by CodeRabbit

  • New Features

    • Introduced a new LicenseResource class to provide endpoints for retrieving license status information.
    • Added LicenseStatusDto and LicenseService in the frontend to support license status checks and display.
    • Enhanced the Vault List view to show LicenseAlert based on license status.
  • Bug Fixes

    • Corrected the license seats count logic in the billing system.
  • Refactor

    • Improved logging in LicenseHolder.
    • Renamed and updated methods for clarity and testing compatibility.
  • Style

    • Updated MenuButton attributes in VaultList.vue for better user interaction based on license status.

@infeo infeo requested a review from SailReal March 15, 2024 14:47
@infeo infeo self-assigned this Mar 15, 2024
@infeo infeo added this to the next milestone Mar 15, 2024
Copy link

coderabbitai bot commented Mar 15, 2024

Walkthrough

The update involves enhancing license management and enforcement in a software system. Changes were made to accurately track and control the number of licensed seats, improve the license status reporting, and ensure that vault creation adheres to license limits. These adjustments are aimed at ensuring compliance with licensing terms, enhancing user experience by providing clear feedback on license status, and preventing unauthorized use of software features beyond the licensed capacity.

Changes

Files Change Summary
.../api/LicenseResource.java Introduced LicenseResource class for license status endpoints with related functionality.
.../license/LicenseHolder.java Enhanced logging and method visibility for testing in LicenseHolder.
.../api/BillingResourceTest.java Updated test to reflect changes in getSeats() return value.
frontend/src/common/backend.ts Added LicenseUserInfoDto and LicenseService for license user information retrieval.
frontend/src/components/LicenseAlert.vue Updated functionality to use license object for license-related checks and data retrieval.
frontend/src/components/VaultList.vue Modified UI logic for license alerts and integrated licenseStatus fetching.

Assessment against linked issues

Objective Addressed Explanation
Prevent vault creation if license exceeded (#262)
Allow vault creation flow start but stop with error if license limit surpassed (#262)
Prevent vault creation on returning to vault list after license exceedance error (#262)
Check license compliance during vault creation to prevent recovery key display (#262)
Address unexpected vault creation despite license exceedance error (#262)

Poem

In the code where licenses dwell,
A rabbit worked, its magic spell.
🐇💻 With every line and clever tweak,
Ensured the software's not for the meek.
"No vaults too many," it declared with cheer,
For rules are rules, let's make that clear!"
🌟 With every commit, pushed with might,
Ensured the license stood just right.


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f9c3f00 and fedd8de.
Files selected for processing (4)
  • backend/src/main/java/org/cryptomator/hub/api/LicenseResource.java (1 hunks)
  • frontend/src/common/backend.ts (3 hunks)
  • frontend/src/components/LicenseAlert.vue (3 hunks)
  • frontend/src/components/VaultList.vue (6 hunks)
Files skipped from review as they are similar to previous changes (2)
  • backend/src/main/java/org/cryptomator/hub/api/LicenseResource.java
  • frontend/src/common/backend.ts
Additional comments not posted (5)
frontend/src/components/LicenseAlert.vue (2)

2-2: Ensure that the condition for displaying the license expiration alert is robust and correctly handles potential null values in license.expiresAt.

Verification successful

The verification process confirms that the condition license?.expiresAt && now > license.expiresAt in LicenseAlert.vue is the only instance where the license?.expiresAt property is used. This condition correctly handles potential null values by using optional chaining (?.), which safely accesses expiresAt only if license is not null. Therefore, the implementation is robust as per the requirements specified in the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the license object always has the expiresAt property when it is used.
ast-grep --lang javascript --pattern $'license?.expiresAt'

Length of output: 59



Script:

#!/bin/bash
# Search for textual occurrences of 'license?.expiresAt' in JavaScript files to ensure all usages are captured.
rg 'license\?.expiresAt' --glob '*.vue' --glob '*.js'

Length of output: 195


39-52: Ensure proper error handling in the fetchData function. Consider displaying a user-friendly message or UI element when fetching license information fails.

Consider enhancing the user experience by providing feedback in the UI when an error occurs during the fetching of license information.

frontend/src/components/VaultList.vue (3)

11-11: Ensure that the isLicenseSuspicious computed property is correctly implemented to reflect the intended license checks.

Verification successful

The isLicenseSuspicious computed property is indeed implemented in the VaultList.vue file. The ripgrep output shows that this property is used within a <LicenseAlert> component and a <MenuButton> component, and it is defined as a computed property. This confirms that the property is actively used to control UI elements based on the license status, aligning with the intended functionality described in the review comment.

Conclusion: The isLicenseSuspicious computed property is correctly implemented in the VaultList.vue file to reflect the intended license checks.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of isLicenseSuspicious to ensure it correctly uses licenseStatus properties.
ast-grep --lang javascript --pattern $'isLicenseSuspicious'

Length of output: 58



Script:

#!/bin/bash
# Adjusting the search pattern to find `isLicenseSuspicious` within a computed properties block in Vue components
ast-grep --lang javascript --pattern $'computed { $$$ isLicenseSuspicious { $$$ } $$$ }'

Length of output: 560



Script:

#!/bin/bash
# Simplifying the search pattern to find `isLicenseSuspicious` in any context within JavaScript files
ast-grep --lang javascript --pattern $'isLicenseSuspicious { $$$ }'

Length of output: 518



Script:

#!/bin/bash
# Using ripgrep to search for 'isLicenseSuspicious' in Vue component files to ensure it is defined and implemented correctly
rg 'isLicenseSuspicious' --glob '*.vue'

Length of output: 586


43-43: Review the implementation of the disabled state for the MenuButton to ensure it is correctly tied to the isLicenseSuspicious flag.


140-153: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [124-191]

Ensure robust error handling and user feedback mechanisms are in place for the fetchData function, especially considering its critical role in fetching and handling license information.

Consider implementing more comprehensive error handling and user feedback in the fetchData function to enhance reliability and user experience.


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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.
  • 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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b663f0a and b073e88.
Files selected for processing (6)
  • backend/src/main/java/org/cryptomator/hub/api/BillingResource.java (2 hunks)
  • backend/src/main/java/org/cryptomator/hub/api/LicenseResource.java (1 hunks)
  • backend/src/main/java/org/cryptomator/hub/license/LicenseHolder.java (2 hunks)
  • backend/src/test/java/org/cryptomator/hub/api/BillingResourceTest.java (1 hunks)
  • frontend/src/common/backend.ts (3 hunks)
  • frontend/src/components/VaultList.vue (6 hunks)
Additional comments: 11
backend/src/main/java/org/cryptomator/hub/api/LicenseResource.java (2)
  • 25-33: The implementation of the /license/status endpoint looks good and follows RESTful principles and Java EE standards.
  • 36-45: The LicenseStatusDto record is well-defined, making good use of Java records and JSON property annotations for clarity and serialization purposes.
backend/src/main/java/org/cryptomator/hub/api/BillingResource.java (1)
  • 73-73: The update in the BillingDto creation method to use licenseHolder.getSeats() aligns with the new licensing model and is correctly implemented.
backend/src/main/java/org/cryptomator/hub/license/LicenseHolder.java (2)
  • 86-86: Including the exception in the log message enhances error visibility and debugging capabilities. Good improvement.
  • 179-183: The renaming of getNoLicenseSeats to seatsOnNotExisingLicense improves clarity, and making it visible for testing is a positive step towards ensuring code quality.
backend/src/test/java/org/cryptomator/hub/api/BillingResourceTest.java (1)
  • 58-58: The adjustment in the test to expect 5 seats by default correctly reflects the changes in the licensing model. Good update to keep the tests aligned with the application logic.
frontend/src/components/VaultList.vue (3)
  • 11-11: Changing the condition to display LicenseAlert based on isLicenseSuspicious is a sensible approach to alert users about potential license issues.
  • 43-43: The updates to the MenuButton attributes, including disabling and styling based on isLicenseSuspicious, are well-implemented to enforce license compliance.
  • 143-150: The introduction of licenseStatus and isLicenseSuspicious computed properties is a smart way to dynamically adjust the UI based on the license status. This enhances the user experience by providing immediate feedback on license issues.
frontend/src/common/backend.ts (2)
  • 198-213: The LicenseStatusDto class implementation looks good. However, consider the following:
  • Ensure that the date comparison in isExpired() accounts for potential timezone differences.
  • Verify that seat counts (licensedSeats and usedSeats) are always integers to avoid floating-point precision issues.
  • 398-399: The addition of LicenseService to the services object is correctly implemented, ensuring seamless integration and accessibility across the application.

frontend/src/common/backend.ts Outdated Show resolved Hide resolved
@@ -24,6 +24,7 @@
import java.time.Instant;
import java.util.Optional;

//TODO: redirect ot /license path
Copy link

Choose a reason for hiding this comment

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

The TODO comment about redirecting to the /license path should be tracked in an issue to ensure it's addressed in the future.

Would you like me to open a GitHub issue for this task?

Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

LGTM 👍 , would only slightly improve the optional expiration date handling.

frontend/src/common/backend.ts Outdated Show resolved Hide resolved
frontend/src/common/backend.ts Outdated Show resolved Hide resolved
@SailReal
Copy link
Member

Another thing I noticed: in https://github.com/cryptomator/hub/blob/feature/license-status-endpoint/frontend/src/components/LicenseAlert.vue we still use the billing resource, which means that still only admins see this alert, do we want to adjust this in a separate PR or in this one?

@infeo infeo requested a review from SailReal April 17, 2024 08:23
@infeo
Copy link
Member Author

infeo commented Apr 17, 2024

means that still only admins see this alert, do we want to adjust this in a separate PR or in this one?

I changed it in fedd8de

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

frontend/src/components/LicenseAlert.vue Show resolved Hide resolved
Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@infeo infeo merged commit 592edff into develop Apr 17, 2024
4 checks passed
@infeo infeo deleted the feature/license-status-endpoint branch April 17, 2024 14:08
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.

On License exceedance vault creation possible
2 participants