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

[WEB-2092] chore: favorite delete changes #5302

Merged
merged 4 commits into from
Aug 5, 2024

Conversation

NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Aug 5, 2024

chore:

  • This pull request removes the error when favoriting an entity (such as a project, cycle, module, or view page) and ensures it is removed from the favorites list once it is deleted.
  • It also displays a 404 Not Found error when the module is deleted.
  • Once the deploy board is published and the entity has been deleted, then the already published url should throw 404 not found.

Issue Link: WEB-2092

Summary by CodeRabbit

  • New Features

    • Enhanced deletion process for cycles, modules, projects, pages, and views by ensuring that associated user favorites are also removed when these entities are deleted.
    • Improved error handling for module retrieval by returning a 404 error if the module does not exist.
  • Bug Fixes

    • Fixed data integrity issues related to user favorites by synchronizing deletions across multiple views.
  • Chores

    • Cleaned up orphaned records in the database during deletion operations for various entities.

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Walkthrough

The recent changes enhance the application by ensuring that user favorites are efficiently managed during the deletion of various entities such as cycles, modules, projects, pages, and views. Each relevant deletion method now includes logic to remove associated user favorites from the UserFavorite model, maintaining data integrity and improving user experience. This cohesive approach prevents orphaned records and ensures that user preferences are consistently updated across the application.

Changes

Files Change Summary
apiserver/.../cycle.py, apiserver/.../module.py, apiserver/.../project.py, apiserver/.../cycle/base.py, apiserver/.../module/base.py Added logic to delete user favorite entries from UserFavorite model when associated entities (cycles, modules, projects) are deleted.
apiserver/.../page/base.py Enhanced destroy method to delete user favorite entries when a page is deleted.
apiserver/.../view/base.py Extended destroy methods to remove user favorites related to views upon deletion.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant UserFavorite
    participant Entity

    User->>API: Request to delete Entity
    API->>UserFavorite: Retrieve UserFavorite for Entity
    alt UserFavorite found
        API->>UserFavorite: Delete UserFavorite
    end
    API->>Entity: Delete Entity
    API-->>User: Respond with success
Loading

🐰 In the fields where bunnies play,
User favorites now clear away.
When cycles and modules bid goodbye,
Preferences follow, and we all sigh.
So hop with joy, let records stay neat,
For a cleaner database is truly a treat! 🌼


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>.
    • 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.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dd806df and 8746959.

Files selected for processing (7)
  • apiserver/plane/api/views/cycle.py (2 hunks)
  • apiserver/plane/api/views/module.py (2 hunks)
  • apiserver/plane/api/views/project.py (2 hunks)
  • apiserver/plane/app/views/cycle/base.py (1 hunks)
  • apiserver/plane/app/views/module/base.py (2 hunks)
  • apiserver/plane/app/views/page/base.py (2 hunks)
  • apiserver/plane/app/views/view/base.py (3 hunks)
Additional comments not posted (5)
apiserver/plane/api/views/project.py (1)

360-366: LGTM! But verify the UserFavorite object deletion.

The code changes are approved.

However, ensure that the UserFavorite object deletion logic is correct and there are no potential issues.

Verification successful

The UserFavorite object deletion logic is correct and consistent across the codebase.

The UserFavorite.objects.get followed by delete() pattern is used in multiple files, including the target file apiserver/plane/api/views/project.py, indicating that the logic is sound and follows a consistent approach.

  • apiserver/plane/api/views/project.py
  • apiserver/plane/api/views/cycle.py
  • apiserver/plane/api/views/module.py
  • apiserver/plane/app/views/page/base.py
  • apiserver/plane/app/views/workspace/favorite.py
  • apiserver/plane/app/views/view/base.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `UserFavorite` object deletion logic.

# Test: Search for the `UserFavorite` object deletion logic. Expect: Correct deletion logic.
rg --type python -A 5 $'UserFavorite.objects.get'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify the `UserFavorite` object deletion logic.

# Test: Search for the `UserFavorite` object deletion logic. Expect: Correct deletion logic.
rg --type py -A 5 'UserFavorite.objects.get'

Length of output: 6370

apiserver/plane/app/views/view/base.py (2)

145-152: LGTM! But verify the UserFavorite object deletion.

The code changes are approved.

However, ensure that the UserFavorite object deletion logic is correct and there are no potential issues.

Verification successful

Verified: The UserFavorite object deletion logic is consistent and correct.

The code changes are approved, and the deletion logic follows the same pattern used across the codebase.

  • apiserver/plane/app/views/view/base.py lines 145-152
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `UserFavorite` object deletion logic.

# Test: Search for the `UserFavorite` object deletion logic. Expect: Correct deletion logic.
rg --type python -A 5 $'UserFavorite.objects.get'

Length of output: 79


Script:

#!/bin/bash
# Description: Verify the `UserFavorite` object deletion logic.

# Test: Search for the `UserFavorite` object deletion logic. Expect: Correct deletion logic.
rg --type-add 'py:*.py' -t py -A 5 $'UserFavorite.objects.get'

Length of output: 6387


449-463: LGTM! But verify the UserFavorite and DeployBoard object deletion.

The code changes are approved.

However, ensure that the UserFavorite and DeployBoard object deletion logic is correct and there are no potential issues.

Verification successful

The UserFavorite and DeployBoard object deletion logic is correct.

The code changes are approved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `UserFavorite` and `DeployBoard` object deletion logic.

# Test: Search for the `UserFavorite` and `DeployBoard` object deletion logic. Expect: Correct deletion logic.
rg --type python -A 5 $'UserFavorite.objects.filter'
rg --type python -A 5 $'DeployBoard.objects.get'

Length of output: 161


Script:

#!/bin/bash
# Description: Verify the `UserFavorite` and `DeployBoard` object deletion logic.

# Test: Search for the `UserFavorite` and `DeployBoard` object deletion logic. Expect: Correct deletion logic.
rg --type py -A 5 $'UserFavorite.objects.filter'
rg --type py -A 5 $'DeployBoard.objects.get'

Length of output: 17743

apiserver/plane/app/views/page/base.py (1)

363-376: LGTM! But verify the DeployBoard and UserFavorite object deletion.

The code changes are approved.

However, ensure that the DeployBoard and UserFavorite object deletion logic is correct and there are no potential issues.

Verification successful

The DeployBoard and UserFavorite object deletion logic is correctly implemented.

The code changes are approved.

  • DeployBoard deletion logic: apiserver/plane/app/views/page/base.py
  • UserFavorite deletion logic: apiserver/plane/app/views/page/base.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the `DeployBoard` and `UserFavorite` object deletion logic.

# Test: Search for the `DeployBoard` and `UserFavorite` object deletion logic. Expect: Correct deletion logic.
rg --type python -A 5 $'DeployBoard.objects.get'
rg --type python -A 5 $'UserFavorite.objects.get'

Length of output: 158


Script:

#!/bin/bash
# Description: Verify the `DeployBoard` and `UserFavorite` object deletion logic.

# Test: Search for the `DeployBoard` and `UserFavorite` object deletion logic. Expect: Correct deletion logic.
rg --type py -A 5 $'DeployBoard.objects.get'
rg --type py -A 5 $'UserFavorite.objects.get'

Length of output: 18110

apiserver/plane/app/views/module/base.py (1)

447-451: LGTM!

The changes improve error handling by returning a 404 error when a module is not found.

Comment on lines 1089 to 1095
# Delete the user favorite cycle
UserFavorite.objects.get(
user=request.user,
entity_type="cycle",
entity_identifier=pk,
project_id=project_id,
).delete()
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the existence of the favorite entry before deletion.

The code assumes that a favorite entry always exists for the user, which might not be the case. This can raise an exception if the entry is not found. Consider using filter().delete() to avoid potential exceptions.

-  UserFavorite.objects.get(
-      user=request.user,
-      entity_type="cycle",
-      entity_identifier=pk,
-      project_id=project_id,
-  ).delete()
+  UserFavorite.objects.filter(
+      user=request.user,
+      entity_type="cycle",
+      entity_identifier=pk,
+      project_id=project_id,
+  ).delete()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Delete the user favorite cycle
UserFavorite.objects.get(
user=request.user,
entity_type="cycle",
entity_identifier=pk,
project_id=project_id,
).delete()
# Delete the user favorite cycle
UserFavorite.objects.filter(
user=request.user,
entity_type="cycle",
entity_identifier=pk,
project_id=project_id,
).delete()

Comment on lines 311 to 315
UserFavorite.objects.get(
user=request.user,
entity_type="module",
entity_identifier=pk,
project_id=project_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for UserFavorite.objects.get.

The UserFavorite.objects.get call should be wrapped in a try-except block to handle potential DoesNotExist exceptions.

-        UserFavorite.objects.get(
-            user=request.user,
-            entity_type="module",
-            entity_identifier=pk,
-            project_id=project_id,
-        ).delete()
+        try:
+            user_favorite = UserFavorite.objects.get(
+                user=request.user,
+                entity_type="module",
+                entity_identifier=pk,
+                project_id=project_id,
+            )
+            user_favorite.delete()
+        except UserFavorite.DoesNotExist:
+            pass  # or handle the exception as needed
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
UserFavorite.objects.get(
user=request.user,
entity_type="module",
entity_identifier=pk,
project_id=project_id,
try:
user_favorite = UserFavorite.objects.get(
user=request.user,
entity_type="module",
entity_identifier=pk,
project_id=project_id,
)
user_favorite.delete()
except UserFavorite.DoesNotExist:
pass # or handle the exception as needed

Comment on lines 788 to 792
UserFavorite.objects.get(
user=request.user,
entity_type="module",
entity_identifier=pk,
project_id=project_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for UserFavorite.objects.get.

The UserFavorite.objects.get call should be wrapped in a try-except block to handle potential DoesNotExist exceptions.

-        UserFavorite.objects.get(
-            user=request.user,
-            entity_type="module",
-            entity_identifier=pk,
-            project_id=project_id,
-        ).delete()
+        try:
+            user_favorite = UserFavorite.objects.get(
+                user=request.user,
+                entity_type="module",
+                entity_identifier=pk,
+                project_id=project_id,
+            )
+            user_favorite.delete()
+        except UserFavorite.DoesNotExist:
+            pass  # or handle the exception as needed
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
UserFavorite.objects.get(
user=request.user,
entity_type="module",
entity_identifier=pk,
project_id=project_id,
try:
user_favorite = UserFavorite.objects.get(
user=request.user,
entity_type="module",
entity_identifier=pk,
project_id=project_id,
)
user_favorite.delete()
except UserFavorite.DoesNotExist:
pass # or handle the exception as needed

Comment on lines 413 to 418
UserFavorite.objects.get(
user=request.user,
entity_type="cycle",
entity_identifier=pk,
project_id=project_id,
).delete()
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for UserFavorite.objects.get.

The UserFavorite.objects.get call should be wrapped in a try-except block to handle potential DoesNotExist exceptions.

-        UserFavorite.objects.get(
-            user=request.user,
-            entity_type="cycle",
-            entity_identifier=pk,
-            project_id=project_id,
-        ).delete()
+        try:
+            user_favorite = UserFavorite.objects.get(
+                user=request.user,
+                entity_type="cycle",
+                entity_identifier=pk,
+                project_id=project_id,
+            )
+            user_favorite.delete()
+        except UserFavorite.DoesNotExist:
+            pass  # or handle the exception as needed
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
UserFavorite.objects.get(
user=request.user,
entity_type="cycle",
entity_identifier=pk,
project_id=project_id,
).delete()
try:
user_favorite = UserFavorite.objects.get(
user=request.user,
entity_type="cycle",
entity_identifier=pk,
project_id=project_id,
)
user_favorite.delete()
except UserFavorite.DoesNotExist:
pass # or handle the exception as needed

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8746959 and 76387b5.

Files selected for processing (2)
  • apiserver/plane/app/views/page/base.py (1 hunks)
  • apiserver/plane/app/views/view/base.py (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apiserver/plane/app/views/page/base.py
  • apiserver/plane/app/views/view/base.py

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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76387b5 and 4edd543.

Files selected for processing (7)
  • apiserver/plane/api/views/cycle.py (2 hunks)
  • apiserver/plane/api/views/module.py (2 hunks)
  • apiserver/plane/api/views/project.py (2 hunks)
  • apiserver/plane/app/views/cycle/base.py (1 hunks)
  • apiserver/plane/app/views/module/base.py (2 hunks)
  • apiserver/plane/app/views/page/base.py (1 hunks)
  • apiserver/plane/app/views/view/base.py (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • apiserver/plane/api/views/cycle.py
  • apiserver/plane/api/views/module.py
  • apiserver/plane/api/views/project.py
  • apiserver/plane/app/views/cycle/base.py
  • apiserver/plane/app/views/module/base.py
Additional comments not posted (3)
apiserver/plane/app/views/view/base.py (2)

447-453: LGTM! Verify the integration.

The logic for deleting the user favorite view is correctly implemented.

Ensure that this integration works correctly across the application.


144-150: LGTM! Verify the integration.

The logic for deleting the user favorite view is correctly implemented.

Ensure that this integration works correctly across the application.

apiserver/plane/app/views/page/base.py (1)

362-368: LGTM! Verify the integration.

The logic for deleting the user favorite page is correctly implemented.

Ensure that this integration works correctly across the application.

Verification successful

The integration of the destroy method in PageViewSet is correctly set up.

The destroy method is referenced in the URL configuration file (apiserver/plane/app/urls/page.py), indicating that the user favorite page deletion logic is properly integrated.

  • apiserver/plane/app/views/page/base.py: destroy method implementation.
  • apiserver/plane/app/urls/page.py: References to PageViewSet and its destroy method.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify integration of the user favorite page deletion when a page is deleted.

# Test: Search for the usage of the `destroy` method in `PageViewSet`.
rg --type python -A 5 $'def destroy(self, request, slug, project_id, pk)' | rg 'PageViewSet'

Length of output: 122


Script:

#!/bin/bash
# Description: Verify integration of the user favorite page deletion when a page is deleted.

# Test: Search for the usage of the `destroy` method in `PageViewSet`.
rg --type py -A 5 $'def destroy(self, request, slug, project_id, pk)' | rg 'PageViewSet'

Length of output: 87


Script:

#!/bin/bash
# Description: Verify integration of the user favorite page deletion when a page is deleted.

# Search for all references to the `destroy` method in the codebase.
rg --type py 'destroy'

# Search for all references to the `PageViewSet` class in the codebase.
rg --type py 'PageViewSet'

Length of output: 8032

@sriramveeraghanta sriramveeraghanta merged commit 07574b4 into preview Aug 5, 2024
13 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore/favorite-deletes branch August 5, 2024 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants