Skip to content

fix bug opening a project after trying to S&R it#1674

Merged
hahn-kev merged 2 commits into
developfrom
bug/unable-to-open-project
May 20, 2025
Merged

fix bug opening a project after trying to S&R it#1674
hahn-kev merged 2 commits into
developfrom
bug/unable-to-open-project

Conversation

@hahn-kev

@hahn-kev hahn-kev commented May 19, 2025

Copy link
Copy Markdown
Collaborator

fixes a bug reported by a user.

to reproduce:

  1. try to S&R a project code which doesn't exist
  2. create said project code, there will be an error trying to open the project page.

The problem is that step 1 caused the project code to be associated with an empty guid (because it doesn't exist) and cache that association, when the new project was created that cache was not invalidated, then when asking for permission to view the project it was rejected because the user didn't have permission to view a project of empty guid.

I've added code to invalidate the code to id cache one project creation, in addition I've changed the signature of the project code lookup to return Guid? so the caller is forced to explicitly handle the null case, rather than just getting Guid.Empty

@hahn-kev hahn-kev added the bug Something isn't working label May 19, 2025
@coderabbitai

coderabbitai Bot commented May 19, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This update refactors project ID handling across multiple backend components to consistently use nullable GUIDs, improving null safety and error handling. Several method signatures are updated to accept or return nullable GUIDs, and permission checks now require explicit null checks. Cache invalidation and project reset logic are also adjusted for improved consistency.

Changes

Files/Paths Change Summary
backend/LexBoxApi/Controllers/CrdtController.cs,
backend/LexBoxApi/Controllers/IntegrationController.cs
Changed project ID checks from default to explicit null checks and updated return statements to unwrap nullable GUIDs before use.
backend/LexBoxApi/GraphQL/LexQueries.cs Updated permission assertion in ProjectByCode to use project ID instead of project code for authorization.
backend/LexBoxApi/GraphQL/ProjectMutations.cs Standardized nullable project ID handling: null checks precede permission assertions and service calls, and nullable project IDs are unwrapped before use in multiple mutation methods.
backend/LexBoxApi/Services/PermissionService.cs Added explicit null checks after project ID lookups in permission methods; updated AssertCanViewProject(Guid) to accept an optional override user parameter.
backend/LexBoxApi/Services/ProjectService.cs Changed LookupProjectId to return Guid? instead of Guid, updated cache and database logic accordingly; improved cache invalidation and error handling in project creation and reset operations.
backend/LexCore/ServiceInterfaces/IPermissionService.cs Updated AssertCanViewProject(Guid) interface method to accept an optional LexAuthUser? overrideUser parameter.

Poem

In the warren of GUIDs, a rabbit did hop,
Checking for nulls, lest the backend should stop.
With caches invalidated and permissions in view,
Each project code lookup now safely comes through.
No more defaults—just nullable cheer,
Hopping through code, the bugs disappear! 🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@hahn-kev hahn-kev changed the title expose assert can view project id, override user fix bug opening a project after trying to S&R it May 19, 2025
@github-actions

Copy link
Copy Markdown
Contributor

C# Unit Tests

116 tests  ±0   116 ✅ ±0   10s ⏱️ -1s
 17 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 313bef1. ± Comparison against base commit c5503ef.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
backend/LexBoxApi/GraphQL/ProjectMutations.cs (1)

363-368: Also unwrap for the FindAsync call (optional clarity)

FindAsync(projectId) will compile, but passing the non-nullable projectId.Value makes the intent clearer and avoids boxing a Nullable<Guid>.
This is a nit – feel free to ignore if you prefer the current style.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c5503ef and 313bef1.

📒 Files selected for processing (7)
  • backend/LexBoxApi/Controllers/CrdtController.cs (1 hunks)
  • backend/LexBoxApi/Controllers/IntegrationController.cs (1 hunks)
  • backend/LexBoxApi/GraphQL/LexQueries.cs (1 hunks)
  • backend/LexBoxApi/GraphQL/ProjectMutations.cs (5 hunks)
  • backend/LexBoxApi/Services/PermissionService.cs (4 hunks)
  • backend/LexBoxApi/Services/ProjectService.cs (3 hunks)
  • backend/LexCore/ServiceInterfaces/IPermissionService.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build FwHeadless / publish-fw-headless
  • GitHub Check: Build API / publish-api
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (8)
backend/LexBoxApi/Controllers/CrdtController.cs (1)

93-98: Good update to handle nullable project ID correctly.

This change properly handles the new nullable return type from LookupProjectId. Using is null check and .Value unwrapping improves safety by explicitly handling the case where a project code doesn't exist.

backend/LexCore/ServiceInterfaces/IPermissionService.cs (1)

14-14: Appropriate interface update to support user override.

The addition of the optional overrideUser parameter creates consistency with other methods in the interface and allows for permission checks with an explicitly provided user context.

backend/LexBoxApi/GraphQL/LexQueries.cs (1)

161-161: Improved permission check using project ID instead of code.

This change correctly uses the project's ID for the permission check rather than the project code. This is more consistent and avoids potential issues with the project code to ID mapping.

backend/LexBoxApi/Controllers/IntegrationController.cs (1)

62-63: Good update to handle nullable project ID correctly.

This change properly handles the new nullable return type from LookupProjectId. Using explicit null checking and unwrapping the value only when non-null prevents potential null reference exceptions.

backend/LexBoxApi/Services/PermissionService.cs (2)

86-89: New overload looks good

Adding overrideUser to AssertCanViewProject(Guid …) aligns the signature with the other Assert helpers and removes the previous need to duplicate logic. 👍


43-46: Good defensive null-handling

Early-returning false when LookupProjectId yields null prevents unnecessary permission checks and possible NullReferenceExceptions. Thanks for tightening this up.

Also applies to: 95-98, 132-135, 190-193

backend/LexBoxApi/Services/ProjectService.cs (2)

60-66: Cache invalidation on creation – nice catch

Calling InvalidateProjectCodeCache right after the repo is initialised ensures stale entries are purged the moment a project is created, fixing the original bug scenario.
Implementation is concise and in the correct transactional scope.


140-150: Nullable return & null-caching strategy look solid

Switching LookupProjectId to Guid? and explicitly caching null avoids repeated DB hits while still allowing later invalidation (handled above). Implementation matches the call-sites. Well done.

Comment thread backend/LexBoxApi/GraphQL/ProjectMutations.cs

@myieye myieye left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me 👍

@hahn-kev hahn-kev merged commit 7040f15 into develop May 20, 2025
13 of 14 checks passed
@hahn-kev hahn-kev deleted the bug/unable-to-open-project branch May 20, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants