Skip to content

Conversation

AlexVelezLl
Copy link
Member

@AlexVelezLl AlexVelezLl commented May 26, 2025

Summary

Overrides get_queryset in FacilityUserModelManager to exclude soft deleted users

References

Closes #13377.

Reviewer guidance

  • Manually set a date_deleted value to any user in the db.
  • Check that this user is never shown in any page.

Summary by CodeRabbit

  • Bug Fixes
    • Users marked as deleted are now automatically excluded from user lists and queries, ensuring only active users are shown.

@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... SIZE: very small labels May 26, 2025
@AlexVelezLl AlexVelezLl requested a review from nucleogenesis May 26, 2025 16:48
Copy link
Contributor

coderabbitai bot commented May 26, 2025

"""

Walkthrough

A get_queryset method was added to the FacilityUserModelManager in kolibri/core/auth/models.py, ensuring that all queries through this manager automatically exclude FacilityUser instances where date_deleted is not null, effectively filtering out soft-deleted users. A corresponding test was added to verify this behavior.

Changes

File(s) Change Summary
kolibri/core/auth/models.py Added get_queryset override in FacilityUserModelManager to exclude users with date_deleted not null
kolibri/core/auth/test/test_models.py Added test test_no_soft_deleted_users_are_returned to verify soft-deleted users are excluded from default queryset

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FacilityUserModelManager
    participant Database

    Client->>FacilityUserModelManager: Query FacilityUser.objects
    FacilityUserModelManager->>Database: SELECT * FROM FacilityUser WHERE date_deleted IS NULL
    Database-->>FacilityUserModelManager: Return filtered users
    FacilityUserModelManager-->>Client: Return queryset (excluding soft-deleted users)
Loading

Assessment against linked issues

Objective Addressed Explanation
Override FacilityUserModelManager#get_queryset to exclude users with non-null deletion_date field (#13377)
Cover that the changes exclude soft-deleted users with a unit test (#13377)

Possibly related issues

Possibly related PRs

Suggested labels

SIZE: small

Suggested reviewers

  • rtibbles
  • nucleogenesis

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44de259 and b073aca.

📒 Files selected for processing (1)
  • kolibri/core/auth/test/test_models.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: No zombies
  • GitHub Check: Python unit tests for EOL Python versions (3.7)
  • GitHub Check: Python unit tests on Windows Server (3.8)
  • GitHub Check: Python unit tests for currently supported Python versions (3.9)
  • GitHub Check: Python postgres unit tests
  • GitHub Check: Python unit tests for currently supported Python versions (3.13)
  • GitHub Check: Python unit tests for currently supported Python versions (3.12)
  • GitHub Check: Python unit tests for EOL Python versions (3.6)
  • GitHub Check: Python unit tests on Mac OS (3.10)
  • GitHub Check: Python unit tests for currently supported Python versions (3.11)
  • GitHub Check: Python unit tests for currently supported Python versions (3.10)
  • GitHub Check: Python unit tests for EOL Python versions (3.8)
  • GitHub Check: All file linting
  • GitHub Check: Build WHL file / Build WHL
🔇 Additional comments (2)
kolibri/core/auth/test/test_models.py (2)

26-26: LGTM! Import addition is appropriate.

The import of local_now is correctly added to support setting the date_deleted timestamp in the test.


702-715: Excellent test implementation for soft delete functionality.

This test properly validates that the FacilityUserModelManager's overridden get_queryset method correctly filters out soft-deleted users. The test:

  • Creates one user with a date_deleted timestamp (soft deleted)
  • Creates one active user without date_deleted
  • Verifies that FacilityUser.objects.all() returns only the active user

The test follows good practices with proper isolation and clear assertions.

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

Copy link
Contributor

github-actions bot commented May 26, 2025

Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

Thanks Alex this looks good. I should have thought of this when I wrote the issue - but I think it'd be good to add a test to the test_models.py FacilityUserTestCase that validates that FacilityUser.objects.all() doesn't return a soft-deleted user.

@AlexVelezLl
Copy link
Member Author

Thanks @nucleogenesis! I have added a test for this :).

@AlexVelezLl AlexVelezLl requested a review from nucleogenesis May 29, 2025 14:13
Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

Thanks Alex, test looks good to me!

@AlexVelezLl AlexVelezLl merged commit 88a077a into learningequality:develop May 29, 2025
52 checks passed
@AlexVelezLl AlexVelezLl deleted the exclude-soft-deleted-users branch May 29, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DEV: backend Python, databases, networking, filesystem... SIZE: small SIZE: very small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FacilityUser: Exclude soft-deleted users from objects manager
2 participants