cryptomator / hub

Cryptomator Hub helps you manage vaults in large teams
GNU Affero General Public License v3.0
36 stars 8 forks source link

Feature: License status endpoint #264

Closed infeo closed 2 months ago

infeo commented 3 months ago

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

coderabbitai[bot] commented 3 months ago

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 f9c3f00f7f1d5197a054455571229cbe1ae3e716 and fedd8de23e1a1f918e42a319c2c5dc5cfe814b5d.
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: ```shell #!/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: ```shell #!/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 `` component and a `` 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: ```shell #!/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: ```shell #!/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: ```shell #!/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: ```shell #!/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`: > :memo: **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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
SailReal commented 3 months ago

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 commented 2 months ago

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 fedd8de23e1a1f918e42a319c2c5dc5cfe814b5d