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

Changes for some minor improvements/bugs #2864

Merged
merged 4 commits into from
Feb 24, 2025

Conversation

DraKen0009
Copy link
Contributor

@DraKen0009 DraKen0009 commented Feb 24, 2025

Proposed Changes

  • Add a filter on organisation user to filter based on first name and last name , for filtering through names (Isn't required , but I got confused with other issue so added filter for name , can be removed)
  • Fixed ordering of resource comments
  • Added validation on valueset name for empty strings
  • Removed mention of load_dummy_data from docs since it's deprecated
  • updated /app to ${pwd} , it was giving error when running this script locally

@ohcnetwork/care-backend-maintainers @ohcnetwork/care-backend-admins

Summary by CodeRabbit

  • New Features
    • Restored the ability to filter organization users by username.
    • Updated comment ordering to display the most recent responses first.
    • Added stricter name input validation to prevent empty entries.
  • Documentation
    • Removed outdated instructions for loading sample data.
  • Chores
    • Adjusted background process configuration to dynamically use the current working directory.

Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

📝 Walkthrough

Walkthrough

This pull request updates several components. The username filter in the OrganizationUserFilter is reinstated to allow filtering by user names. The ResourceRequestCommentViewSet now orders comments by creation date in descending order. A new validate_name method in ValueSetSpec ensures that name fields are not empty. Additionally, the instructions for loading dummy data have been removed from the documentation, and the Celery development script now dynamically sets its working directory. It’s as if someone finally remembered to tidy up these loose ends.

Changes

File Change Summary
care/emr/api/viewsets/organization.py Reinstated username filter in OrganizationUserFilter (CharFilter using icontains lookup); phone_number filter remains unchanged.
care/emr/api/viewsets/resource_request.py Updated get_queryset in ResourceRequestCommentViewSet to include order_by("-created_date") for descending comment order.
care/emr/resources/valueset/spec.py Added validate_name method to ValueSetSpec for validating that the name field is not empty or purely whitespace.
docs/local-setup/configuration.rst Removed instructions for loading dummy data ($ python manage.py load_dummy_data), streamlining the documentation.
scripts/celery-dev.sh Changed the --workdir option from a static "/app" to dynamic $(pwd), making the working directory context-sensitive.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant VC as ResourceRequestCommentViewSet
    participant DB as Database

    U->>VC: Request comments
    VC->>DB: Query comments filtered by resource request
    DB-->>VC: Return matching comments
    VC->>VC: Order comments by created_date (desc)
    VC-->>U: Return ordered comments
Loading
sequenceDiagram
    participant C as Client
    participant V as ValueSetSpec

    C->>V: Submit name for validation
    alt Name is empty or whitespace
        V-->>C: Raise ValueError ("Name cannot be empty")
    else Valid name
        V-->>C: Return stripped name
    end
Loading

Possibly related PRs

Suggested reviewers

  • vigneshhari
  • rithviknishad

Poem

In the realm of code where errors once reigned,
A lost filter returns, no longer constrained.
Queries now dance in descending delight,
And names are trimmed to set things right.
Dummy data tips have bid their adieu—
A small, tidy fix (finally) coming through!


📜 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 ffaec28 and 8845990.

📒 Files selected for processing (5)
  • care/emr/api/viewsets/organization.py (1 hunks)
  • care/emr/api/viewsets/resource_request.py (1 hunks)
  • care/emr/resources/valueset/spec.py (1 hunks)
  • docs/local-setup/configuration.rst (0 hunks)
  • scripts/celery-dev.sh (1 hunks)
💤 Files with no reviewable changes (1)
  • docs/local-setup/configuration.rst
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test / Test
🔇 Additional comments (4)
scripts/celery-dev.sh (1)

16-16:

✅ Verification successful

Verify the working directory assumption.

While using $(pwd) is more flexible than a hardcoded path, it assumes the script will be run from the correct directory. You might want to ensure this assumption holds true.


🏁 Script executed:

#!/bin/bash
# Description: Check if the script is typically run from the expected directory
# by looking for common project files in the current directory

echo "Checking for typical project files in the working directory..."
for file in "manage.py" "config/celery_app.py"; do
  if [ ! -f "$file" ]; then
    echo "Warning: Expected file $file not found in $(pwd)"
  fi
done

Length of output: 297


Working directory assumption validated; no further action required.

The test script confirms that the expected project files (e.g., manage.py and config/celery_app.py) are found when the script is run, so using $(pwd) here is appropriate. However, as a gentle reminder for future clarity, consider explicitly documenting that the script assumes execution from the project root.

care/emr/resources/valueset/spec.py (1)

32-37: LGTM! Nice validation addition.

The validation ensures non-empty names and properly handles whitespace. The error message is clear and helpful.

care/emr/api/viewsets/organization.py (1)

205-205: Consider using DRF's search filter instead.

A previous reviewer suggested using DRF's built-in search filter functionality. It might be worth considering that approach instead of adding a custom filter.

care/emr/api/viewsets/resource_request.py (1)

112-116: LGTM! Good ordering improvement.

The descending order by creation date is a sensible default that ensures consistent display of comments, with newest first.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

codecov bot commented Feb 24, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 56.14%. Comparing base (ffaec28) to head (8845990).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
care/emr/resources/valueset/spec.py 50.00% 3 Missing ⚠️
care/emr/api/viewsets/resource_request.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2864      +/-   ##
===========================================
- Coverage    56.14%   56.14%   -0.01%     
===========================================
  Files          215      215              
  Lines        10289    10295       +6     
  Branches      1053     1054       +1     
===========================================
+ Hits          5777     5780       +3     
- Misses        4496     4499       +3     
  Partials        16       16              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -199,10 +200,24 @@ def mine(self, request, *args, **kwargs):


class OrganizationUserFilter(filters.FilterSet):
username = filters.CharFilter(field_name="user__username", lookup_expr="icontains")
name = filters.CharFilter(method="filter_name")
Copy link
Member

Choose a reason for hiding this comment

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

Lets just use the search filter that DRF provides

@DraKen0009 DraKen0009 marked this pull request as ready for review February 24, 2025 09:38
@DraKen0009 DraKen0009 requested a review from a team as a code owner February 24, 2025 09:38
@vigneshhari vigneshhari merged commit 67d8265 into develop Feb 24, 2025
8 checks passed
@vigneshhari vigneshhari deleted the prafful/bugs/resource-comment-ordering branch February 24, 2025 09:43
Jacobjeevan pushed a commit to Jacobjeevan/care that referenced this pull request Feb 27, 2025
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