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 my account rules #4717

Merged
merged 4 commits into from
Nov 19, 2024
Merged

fix my account rules #4717

merged 4 commits into from
Nov 19, 2024

Conversation

valentinyanakiev
Copy link
Member

@valentinyanakiev valentinyanakiev commented Nov 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new credential definitions for enhanced user authorization in resource creation.
  • Improvements

    • License validation process is now asynchronous, improving control flow during space and resource creation.
  • Bug Fixes

    • Temporarily suspended entitlement filtering in license usage reporting, which may affect accuracy of space type counts.

Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

Walkthrough

The pull request introduces several key changes across three files, focusing on enhancing asynchronous handling of license validation, updating authorization rules with new credential definitions, and modifying filtering logic for entitlement usage. The validateSoftLicenseLimitOrFail method is now asynchronous, affecting multiple mutation methods. In the AccountAuthorizationService, new credentials are added to replace existing ones in authorization rules. The LicenseEntitlementUsageService sees a renaming of a parameter and a temporary suspension of entitlement filtering in one of its methods, impacting the accuracy of space type counts.

Changes

File Path Change Summary
src/domain/space/account/account.resolver.mutations.ts - Converted validateSoftLicenseLimitOrFail to an asynchronous method.
- Updated calls in createSpace, createInnovationHub, createVirtualContributor, createInnovationPack to await the method.
src/domain/space/account/account.service.authorization.ts - Added new credentials: vcCampaignCredential and betaTesterCredential.
- Updated authorization rules for CREATE_SPACE, CREATE_VIRTUAL_CONTRIBUTOR, and CREATE_INNOVATION_PACK to use new credentials.
src/services/infrastructure/license-entitlement-usage/license.entitlement.usage.service.ts - Renamed parameter entitlementType to _entitlementType in getAccountSpacesTypeCount.
- Commented out filtering logic, assigning all spaces to matchingSpaces.

Possibly related PRs

  • Look up correct entitlement for VC creation #4707: The changes in this PR involve updating the entitlement type for assigning roles to virtual contributors, which is directly related to the license validation process in the main PR's validateSoftLicenseLimitOrFail method. Both PRs deal with license entitlements and their implications on role assignments and resource creation.

Suggested reviewers

  • Comoque1
  • ccanos

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.

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
Contributor

@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 (2)
src/domain/space/account/account.service.authorization.ts (1)

295-298: Significant change in authorization strategy

The authorization for creating resources is being shifted from host-based (using hostCredentials) to feature-based (using vcCampaignCredential and betaTesterCredential). This is a fundamental change that affects who can create resources under an account.

Consider documenting this change in architecture decision records (ADR) to track the rationale behind this authorization strategy shift.

src/domain/space/account/account.resolver.mutations.ts (1)

Line range hint 591-599: Enhance error message clarity

The error message could be more user-friendly by providing clearer guidance.

-      throw new ValidationException(
-        `Unable to create ${licenseType} on account: ${account.id}. Entitlement limit of ${entitlementLimit} of type ${licenseType} reached`,
-        LogContext.ACCOUNT
-      );
+      throw new ValidationException(
+        `License limit reached: Cannot create ${licenseType} on this account. You have reached the maximum limit of ${entitlementLimit} ${licenseType}s. Please upgrade your license to add more.`,
+        LogContext.ACCOUNT
+      );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3be9f07 and 9d5c20e.

📒 Files selected for processing (3)
  • src/domain/space/account/account.resolver.mutations.ts (6 hunks)
  • src/domain/space/account/account.service.authorization.ts (2 hunks)
  • src/services/infrastructure/license-entitlement-usage/license.entitlement.usage.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/domain/space/account/account.resolver.mutations.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

src/domain/space/account/account.service.authorization.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

src/services/infrastructure/license-entitlement-usage/license.entitlement.usage.service.ts (1)

Pattern src/**/*.{ts,js}: Review the TypeScript/JavaScript code for NestJS best practices, dependency injection, module structure, and potential bugs. Ensure that the code adheres to TypeScript's typing system and modern standards.

🔇 Additional comments (7)
src/domain/space/account/account.service.authorization.ts (2)

302-302: Verify impact on existing users and add tests

The authorization rules for creating spaces, virtual contributors, and innovation packs now require either VC campaign or beta tester credentials. This change might affect existing users who previously had access through host credentials.

#!/bin/bash
# Search for existing tests covering these authorization rules
rg -l "createSpace|createVC|createInnovationPack" --type ts --glob "**/*.spec.ts"

# Search for existing usages that might be affected
rg "CREATE_SPACE|CREATE_VIRTUAL_CONTRIBUTOR|CREATE_INNOVATION_PACK" --type ts

Would you like me to help generate test cases to verify:

  1. Access is granted with VC campaign credentials
  2. Access is granted with beta tester credentials
  3. Access is denied without these credentials
  4. Existing host credentials no longer grant access

Also applies to: 310-310, 319-319


285-293: Verify the empty resourceID in credential definitions

The resourceID is set to an empty string for both credentials. While this might be intentional for platform-wide credentials, please verify this is the expected behavior.

✅ Verification successful

Let me try another search pattern to specifically look for credential definitions.


Let me try one more search with a simpler pattern to find credential definitions.


Based on the extensive search results, I can see that empty resourceID is commonly used for platform-wide credentials throughout the codebase. Specifically:

  1. The BETA_TESTER and VC_CAMPAIGN credentials are used in platform-wide authorization rules, similar to other global credentials like GLOBAL_ADMIN, GLOBAL_SUPPORT, etc.
  2. Other instances of platform-wide credentials (e.g., GLOBAL_REGISTERED, GLOBAL_ADMIN, GLOBAL_SUPPORT) consistently use empty resourceID.
  3. Only role-specific credentials (like SPACE_MEMBER, ORGANIZATION_ADMIN) require a specific resourceID.

Empty resourceID is correct for platform-wide credentials

The empty resourceID in both vcCampaignCredential and betaTesterCredential is intentional and follows the established pattern for platform-wide authorization credentials in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other credential definitions to verify the pattern
rg -A 2 "type:\s*AuthorizationCredential.*,\s*resourceID:" --type ts

Length of output: 2757


Script:

#!/bin/bash
# Search for credential definitions with type and resourceID
rg "type:\s*AuthorizationCredential\.[A-Z_]+,\s*resourceID:" -B 2 -A 2 --type ts

Length of output: 82


Script:

#!/bin/bash
# Search for ICredentialDefinition usage
rg "ICredentialDefinition" -B 2 -A 5 --type ts

# Also search for AuthorizationCredential enum usage
rg "AuthorizationCredential\." -B 2 -A 2 --type ts

Length of output: 118641

src/domain/space/account/account.resolver.mutations.ts (5)

88-91: LGTM! Proper async handling of license validation

The validation call is correctly awaited and the parameters are properly passed.


Line range hint 152-156: LGTM! Proper async handling of license validation

The validation call is correctly awaited and the parameters are properly passed.


Line range hint 195-199: LGTM! Proper async handling of license validation

The validation call is correctly awaited and the parameters are properly passed.


Line range hint 255-259: LGTM! Proper async handling of license validation

The validation call is correctly awaited and the parameters are properly passed.


584-591: Verify platform admin bypass behavior

The platform admin check bypasses the license entitlement validation. This is a critical path that should be thoroughly tested.

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.

2 participants