Skip to content

feat: removed created_by from read_only serializer field, and ProjectMemberEndpoint updates#5260

Merged
sriramveeraghanta merged 8 commits intopreviewfrom
feat/api-changes
Jul 30, 2024
Merged

feat: removed created_by from read_only serializer field, and ProjectMemberEndpoint updates#5260
sriramveeraghanta merged 8 commits intopreviewfrom
feat/api-changes

Conversation

@henit-chobisa
Copy link
Member

@henit-chobisa henit-chobisa commented Jul 29, 2024

Tasks

  • Modified WorkspaceMemberEndpoint to ProjectMemberEndpoint for fetching and creating new users
  • Added Parameters for getting the issues based on external_id and external_source
  • Fixed broken logic for migrating one cycle issue to other cycle issue

Summary by CodeRabbit

  • New Features

    • Enhanced API functionality to retrieve issues by external_id and external_source.
    • Updated API endpoints to reflect project-specific member operations.
  • Improvements

    • Streamlined serialization by removing unnecessary fields, potentially boosting performance.
    • Improved validation and logic handling for cycle management to prevent issues being added to completed cycles.
  • Bug Fixes

    • Corrected import errors and ensured consistency in function calls related to issue activities.
  • Refactor

    • Renamed API endpoints to reflect project context, enhancing clarity in operations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2024

Walkthrough

This update enhances the API by streamlining serialization fields and transitioning member-related endpoints to a project-focused context. The created_by and created_at fields are omitted from serialization, while WorkspaceMemberAPIEndpoint is replaced with ProjectMemberAPIEndpoint, necessitating a project_id parameter. Additionally, improvements in issue handling and activity logging refine functionality and clarity across multiple modules.

Changes

File(s) Change Summary
apiserver/plane/api/serializers/issue.py Removed created_by and created_at from serialization fields.
apiserver/plane/api/urls/member.py, apiserver/plane/api/views/member.py Replaced WorkspaceMemberAPIEndpoint with ProjectMemberAPIEndpoint, adding project_id.
apiserver/plane/api/views/__init__.py Updated import from WorkspaceMemberAPIEndpoint to ProjectMemberAPIEndpoint.
apiserver/plane/api/views/cycle.py Enhanced cycle post method for validation and refactored issue handling logic.
apiserver/plane/api/views/issue.py Added retrieval by external_id and external_source; updated created_by handling.
apiserver/plane/bgtasks/issue_activites_task.py Modified create_issue_activity to assign actor_id to the issue_activity object.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Database
    User->>API: Request to create issue
    API->>Database: Validate and save issue
    Database-->>API: Confirmation of issue creation
    API-->>User: Response with issue details
Loading

🐰 In the meadow, changes bloom,
Fields trimmed neat, we make some room.
Members now project-bound, oh so bright,
With activities logged, all feels right!
Hopping through code, we cheer and play,
Celebrating improvements, hip-hip-hooray! 🌼


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

Outside diff range, codebase verification and nitpick comments (4)
apiserver/plane/api/views/member.py (1)

Line range hint 54-147:
Improve readability and reduce redundancy.

The method can be refactored to improve readability and reduce redundancy.

- def post(self, request, slug, project_id):
-     if (
-         request.data.get("email") is None
-         or request.data.get("display_name") is None
-     ):
-         return Response(
-             {
-                 "error": "Expected email, display_name, workspace_slug, project_id, one or more of the fields are missing."
-             },
-             status=status.HTTP_400_BAD_REQUEST,
-         )
- 
-     email = request.data.get("email")
- 
-     try:
-         validate_email(email)
-     except ValidationError:
-         return Response(
-             {"error": "Invalid email provided"},
-             status=status.HTTP_400_BAD_REQUEST,
-         )
- 
-     workspace = Workspace.objects.filter(slug=slug).first()
-     project = Project.objects.filter(pk=project_id).first()
- 
-     if not workspace or not project:
-         return Response(
-             {"error": "Provided workspace or project does not exist"},
-             status=status.HTTP_400_BAD_REQUEST,
-         )
- 
-     user = User.objects.filter(email=email).first()
-     workspace_member = WorkspaceMember.objects.filter(
-         workspace=workspace, member=user
-     ).first() if user else None
-     project_member = ProjectMember.objects.filter(
-         project=project, member=user
-     ).first() if user else None
- 
-     if user and project_member:
-         return Response(
-             {
-                 "error": "User is already part of the workspace and project"
-             },
-             status=status.HTTP_400_BAD_REQUEST,
-         )
- 
-     if not user:
-         user = User.objects.create(
-             email=email,
-             display_name=request.data.get("display_name"),
-             first_name=request.data.get("first_name", ""),
-             last_name=request.data.get("last_name", ""),
-             username=uuid.uuid4().hex,
-             password=make_password(uuid.uuid4().hex),
-             is_password_autoset=True,
-             is_active=False,
-         )
- 
-     if not workspace_member:
-         workspace_member = WorkspaceMember.objects.create(
-             workspace=workspace,
-             member=user,
-             role=request.data.get("role", 10),
-         )
- 
-     if not project_member:
-         project_member = ProjectMember.objects.create(
-             project=project,
-             member=user,
-             role=request.data.get("role", 10),
-         )
- 
-     user_data = UserLiteSerializer(user).data
- 
-     return Response(user_data, status=status.HTTP_201_CREATED)
+ def post(self, request, slug, project_id):
+     required_fields = ["email", "display_name"]
+     if any(field not in request.data for field in required_fields):
+         return Response(
+             {
+                 "error": "Expected email, display_name, workspace_slug, project_id, one or more of the fields are missing."
+             },
+             status=status.HTTP_400_BAD_REQUEST,
+         )
+ 
+     email = request.data.get("email")
+     try:
+         validate_email(email)
+     except ValidationError:
+         return Response(
+             {"error": "Invalid email provided"},
+             status=status.HTTP_400_BAD_REQUEST,
+         )
+ 
+     workspace = Workspace.objects.filter(slug=slug).first()
+     project = Project.objects.filter(pk=project_id).first()
+ 
+     if not workspace or not project:
+         return Response(
+             {"error": "Provided workspace or project does not exist"},
+             status=status.HTTP_400_BAD_REQUEST,
+         )
+ 
+     user = User.objects.filter(email=email).first()
+     if user:
+         workspace_member = WorkspaceMember.objects.filter(
+             workspace=workspace, member=user
+         ).first()
+         project_member = ProjectMember.objects.filter(
+             project=project, member=user
+         ).first()
+         if project_member:
+             return Response(
+                 {
+                     "error": "User is already part of the workspace and project"
+                 },
+                 status=status.HTTP_400_BAD_REQUEST,
+             )
+     else:
+         user = User.objects.create(
+             email=email,
+             display_name=request.data.get("display_name"),
+             first_name=request.data.get("first_name", ""),
+             last_name=request.data.get("last_name", ""),
+             username=uuid.uuid4().hex,
+             password=make_password(uuid.uuid4().hex),
+             is_password_autoset=True,
+             is_active=False,
+         )
+ 
+     if not WorkspaceMember.objects.filter(workspace=workspace, member=user).exists():
+         WorkspaceMember.objects.create(
+             workspace=workspace,
+             member=user,
+             role=request.data.get("role", 10),
+         )
+ 
+     if not ProjectMember.objects.filter(project=project, member=user).exists():
+         ProjectMember.objects.create(
+             project=project,
+             member=user,
+             role=request.data.get("role", 10),
+         )
+ 
+     user_data = UserLiteSerializer(user).data
+     return Response(user_data, status=status.HTTP_201_CREATED)
apiserver/plane/api/serializers/issue.py (1)

433-433: Critical dependencies found for created_by and created_at fields

The created_by and created_at fields are heavily used across various parts of the codebase, including serializers, views, models, migrations, and utility functions. Removing these fields from serialization could have significant implications on the application's functionality and data integrity.

  • Serializers: The fields are included in multiple serializers, which means they are crucial for data representation.
  • Views: They are used in various views, indicating their importance in request handling and response generation.
  • Models: The fields are part of the data models, which suggests they are essential for maintaining data integrity.
  • Migrations: The fields are present in migrations, indicating that they are part of the database schema.
  • Utility Functions: The fields are used in utility functions, which implies they are important for various backend operations.

Please re-evaluate the removal of these fields to ensure no critical functionality is affected.

Analysis chain

Verify the impact of removing created_by and created_at fields from serialization.

Ensure that removing these fields does not affect any critical functionality or data representation in the application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `created_by` and `created_at` fields in the codebase.

# Test: Search for the usage of `created_by` and `created_at` fields. Expect: No critical dependencies.
rg --type python -A 5 $'created_by'
rg --type python -A 5 $'created_at'

Length of output: 131


Script:

#!/bin/bash
# Description: Verify the usage of `created_by` and `created_at` fields in the codebase.

# Test: Search for the usage of `created_by` and `created_at` fields. Expect: No critical dependencies.
rg -t py -A 5 'created_by'
rg -t py -A 5 'created_at'

Length of output: 462768

apiserver/plane/api/views/issue.py (1)

42-42: Inconsistent usage of the corrected import statement for issue_activity.

The import statement for issue_activity has been corrected to from plane.bgtasks.issue_activities_task import issue_activity in some places but remains incorrect (from plane.bgtasks.issue_activites_task import issue_activity) in several other files. Please update the import statement in the following files to ensure consistency:

  • apiserver/plane/space/views/inbox.py
  • apiserver/plane/space/views/issue.py
  • apiserver/plane/api/views/module.py
  • apiserver/plane/api/views/inbox.py
  • apiserver/plane/bgtasks/issue_automation_task.py
  • apiserver/plane/app/views/module/issue.py
  • apiserver/plane/app/views/module/base.py
  • apiserver/plane/app/views/issue/draft.py
  • apiserver/plane/app/views/issue/sub_issue.py
  • apiserver/plane/app/views/issue/relation.py
  • apiserver/plane/app/views/issue/reaction.py
  • apiserver/plane/app/views/issue/link.py
  • apiserver/plane/app/views/issue/bulk_operations.py
  • apiserver/plane/app/views/issue/base.py
  • apiserver/plane/app/views/issue/attachment.py
  • apiserver/plane/app/views/issue/archive.py
  • apiserver/plane/app/views/inbox/base.py
  • apiserver/plane/app/views/cycle/issue.py
  • apiserver/plane/app/views/cycle/base.py
  • apiserver/plane/app/views/issue/comment.py
Analysis chain

Verify the consistency of the corrected import statement for issue_activity.

The import statement for issue_activity has been corrected from issue_activites_task to issue_activities_task. Ensure that the corrected import statement is used consistently throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of the corrected import statement for `issue_activity`.

# Test: Search for the usage of the `issue_activity` import statement. Expect: Consistent usage of the corrected import statement.
rg --type python -A 5 $'issue_activity'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify the consistency of the corrected import statement for `issue_activity`.

# Test: Search for the usage of the `issue_activity` import statement. Expect: Consistent usage of the corrected import statement.
rg --type py -A 5 $'issue_activity'

Length of output: 96080

apiserver/plane/api/views/cycle.py (1)

663-663: Remove or replace the print statement for debugging.

The print statement is useful for debugging but should be removed or replaced with proper logging in production code.

-        print("cycle name", cycle.name)
+        # Use proper logging instead of print for production code.
+        logger.debug(f"Cycle name: {cycle.name}")
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35e58e9 and 50aee23.

Files selected for processing (7)
  • apiserver/plane/api/serializers/issue.py (3 hunks)
  • apiserver/plane/api/urls/member.py (1 hunks)
  • apiserver/plane/api/views/init.py (1 hunks)
  • apiserver/plane/api/views/cycle.py (3 hunks)
  • apiserver/plane/api/views/issue.py (7 hunks)
  • apiserver/plane/api/views/member.py (3 hunks)
  • apiserver/plane/bgtasks/issue_activites_task.py (2 hunks)
Additional context used
Ruff
apiserver/plane/api/views/__init__.py

28-28: .member.ProjectMemberAPIEndpoint imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)


30-30: .inbox.InboxIssueAPIEndpoint imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

Additional comments not posted (16)
apiserver/plane/api/urls/member.py (2)

4-4: Import change approved.

The import statement has been correctly updated to import ProjectMemberAPIEndpoint.


9-10: URL pattern change approved.

The URL pattern has been correctly updated to include project_id and use ProjectMemberAPIEndpoint.

apiserver/plane/api/views/__init__.py (1)

28-28: Import change approved.

The import statement has been correctly updated to import ProjectMemberAPIEndpoint.

Tools
Ruff

28-28: .member.ProjectMemberAPIEndpoint imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

apiserver/plane/api/views/member.py (3)

26-26: Class rename approved.

The class has been correctly renamed from WorkspaceMemberAPIEndpoint to ProjectMemberAPIEndpoint.


28-28: Method update approved.

The get method has been correctly updated to include project_id and retrieve project members.


54-54: Method update approved.

The post method has been correctly updated to include project_id and assign users to projects.

apiserver/plane/api/views/issue.py (4)

350-351: Ensure correctness of updates to the created_by field for Issue entities.

The changes ensure that the creator's ID is correctly assigned during the creation process. Verify that the created_by field is correctly handled and does not introduce any issues.

Verification successful

The created_by field is correctly handled for Issue entities.

The updates ensure that the creator's ID is correctly assigned during the creation process. The created_by field is consistently used and updated across multiple files, confirming its correct handling.

  • apiserver/plane/api/views/issue.py lines 350-351: Correctly assigns created_by from request.data and saves it.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `created_by` field for `Issue` entities.

# Test: Search for the usage of the `created_by` field in the `post` method. Expect: Correct handling of the `created_by` field.
rg --type python -A 5 $'created_by'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `created_by` field for `Issue` entities.

# Test: Search for the usage of the `created_by` field in the `post` method. Expect: Correct handling of the `created_by` field.
rg --type py -A 5 $'created_by'

Length of output: 252878


816-818: Ensure correctness of updates to the created_by field for IssueComment entities.

The changes ensure that the creator's ID is correctly assigned during the creation process. Verify that the created_by field is correctly handled and does not introduce any issues.

Verification successful

Ensure correctness of updates to the created_by field for IssueComment entities.

The created_by field is correctly assigned and saved during the creation process in the post method of the IssueCommentView class. No issues were found with the handling of the created_by field.

  • apiserver/plane/api/views/issue.py: Lines 816-818
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `created_by` field for `IssueComment` entities.

# Test: Search for the usage of the `created_by` field in the `post` method. Expect: Correct handling of the `created_by` field.
rg --type python -A 5 $'created_by'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `created_by` field for `IssueComment` entities.

# Test: Search for the usage of the `created_by` field in the `post` method. Expect: Correct handling of the `created_by` field.
rg --type py -A 5 'created_by'

Length of output: 252878


155-184: Ensure robustness and correctness of new logic for handling external_id and external_source parameters.

The new logic includes error handling for scenarios where the issue is not found or multiple issues are returned. Ensure that this logic is correctly implemented and does not introduce any security or performance issues.

Verification successful

The new logic for handling external_id and external_source parameters is robust and correctly implemented.

The error handling for scenarios where the issue is not found or multiple issues are returned is appropriate and aligns with common practices. No security or performance issues were identified.

  • The usage of external_id and external_source is consistent across the codebase.
  • The error handling for ObjectDoesNotExist and MultipleObjectsReturned is correctly implemented.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the new logic for handling `external_id` and `external_source` parameters.

# Test: Search for the usage of `external_id` and `external_source` parameters. Expect: No security or performance issues.
rg --type python -A 5 $'external_id'
rg --type python -A 5 $'external_source'

Length of output: 137


Script:

#!/bin/bash
# Description: Verify the correctness of the new logic for handling `external_id` and `external_source` parameters.

# Test: Search for the usage of `external_id` and `external_source` parameters in Python files. Expect: No security or performance issues.
rg 'external_id' -g '*.py' -A 5
rg 'external_source' -g '*.py' -A 5

Length of output: 64196


646-649: Ensure correctness of updates to the created_by field for IssueLink entities.

The changes ensure that the creator's ID is correctly assigned during the creation process. Verify that the created_by field is correctly handled and does not introduce any issues.

apiserver/plane/api/views/cycle.py (4)

677-688: Ensure correctness of refactored logic for handling cycle issues.

The refactored logic includes a negation query to exclude issues already associated with the current cycle and separates existing and new issues for better tracking. Verify that the refactored logic is correctly implemented and does not introduce any issues.

Verification successful

The refactored logic for handling cycle issues is correctly implemented and does not introduce any issues.

The logic correctly excludes issues already associated with the current cycle and separates existing and new issues for better tracking.

  • apiserver/plane/api/views/cycle.py lines 677-688
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the refactored logic for handling cycle issues.

# Test: Search for the usage of the refactored logic for handling cycle issues. Expect: Correct implementation of the refactored logic.
rg --type python -A 5 $'cycle_id'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the correctness of the refactored logic for handling cycle issues.

# Test: Search for the usage of the refactored logic for handling cycle issues. Expect: Correct implementation of the refactored logic.
rg -t py -A 5 'cycle_id'

Length of output: 71908


665-674: Ensure correctness of enhanced validation for the cycle's end date.

The enhanced validation prevents the addition of new issues if the cycle has already been completed. Verify that the validation is correctly implemented and does not introduce any issues.

Verification successful

The previous script failed due to an unrecognized file type. The rg command should use py instead of python for the file type. Let's correct this and rerun the script to verify the usage of the cycle's end date validation.


The enhanced validation for the cycle's end date is correctly implemented.

The validation logic prevents the addition of new issues if the cycle has already been completed. The implementation is consistent and correctly applied across the codebase.

  • apiserver/plane/api/views/cycle.py: Lines 665-674
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the enhanced validation for the cycle's end date.

# Test: Search for the usage of the cycle's end date validation. Expect: Correct implementation of the validation.
rg --type python -A 5 $'end_date'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the correctness of the enhanced validation for the cycle's end date.

# Test: Search for the usage of the cycle's end date validation. Expect: Correct implementation of the validation.
rg --type py -A 5 $'end_date'

Length of output: 28568


740-740: Ensure correctness of updates to the created_cycle_issues field.

The created_cycle_issues field has been updated to reflect the new structure of created records. Verify that the updates to the created_cycle_issues field are correctly implemented.

Verification successful

Ensure correctness of updates to the created_cycle_issues field.

The created_cycle_issues field has been updated to reflect the new structure of created records. The updates to the created_cycle_issues field are correctly implemented.

  • Files and lines to verify:
    • apiserver/plane/api/views/cycle.py
    • apiserver/plane/bgtasks/issue_activites_task.py
    • apiserver/plane/app/views/cycle/issue.py
    • apiserver/plane/app/views/cycle/base.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `created_cycle_issues` field.

# Test: Search for the usage of the `created_cycle_issues` field. Expect: Correct implementation of the updates.
rg --type python -A 5 $'created_cycle_issues'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `created_cycle_issues` field.

# Test: Search for the usage of the `created_cycle_issues` field. Expect: Correct implementation of the updates.
rg -t py -A 5 'created_cycle_issues'

Length of output: 2325


732-746: Ensure correctness of updates to the issue_activity.delay function.

The invocation of the issue_activity.delay function has been updated to reflect the new structures of created and updated records. Verify that the updates to the issue_activity.delay function are correctly implemented.

Verification successful

Ensure correctness of updates to the issue_activity.delay function.

The invocation of the issue_activity.delay function has been updated to reflect the new structures of created and updated records. The extensive usage of this function across multiple files with consistent parameters confirms that the updates are correctly implemented.

  • apiserver/plane/api/views/cycle.py (lines 732-746)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `issue_activity.delay` function.

# Test: Search for the usage of the `issue_activity.delay` function. Expect: Correct implementation of the updates.
rg --type python -A 5 $'issue_activity.delay'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the correctness of updates to the `issue_activity.delay` function.

# Test: Search for the usage of the `issue_activity.delay` function. Expect: Correct implementation of the updates.
rg -t py -A 5 'issue_activity.delay'

Length of output: 36112

apiserver/plane/bgtasks/issue_activites_task.py (2)

596-597: LGTM!

The addition of actor_id assignment ensures better attribution of actions to users.


1777-1777: LGTM!

The changes in create_issue_activity will enhance the tracking of issue activities.

Comment on lines 39 to 40
project_members = ProjectMember.objects.filter(
project_id=project_id, workspace_id=workspace.id
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize query performance.

The query can be optimized by using select_related to reduce the number of database hits.

- project_members = ProjectMember.objects.filter(
-     project_id=project_id, workspace_id=workspace.id
- )
+ project_members = ProjectMember.objects.filter(
+     project_id=project_id, workspace_id=workspace.id
+ ).select_related('member')
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
project_members = ProjectMember.objects.filter(
project_id=project_id, workspace_id=workspace.id
project_members = ProjectMember.objects.filter(
project_id=project_id, workspace_id=workspace.id
).select_related('member')

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

Outside diff range, codebase verification and nitpick comments (1)
apiserver/plane/api/views/issue.py (1)

155-172: Error handling for issue retrieval is missing.

The get method does not handle scenarios where the issue is not found (ObjectDoesNotExist) or when multiple issues are returned (MultipleObjectsReturned). Please add appropriate error handling to ensure robustness.

  • apiserver/plane/api/views/issue.py
Analysis chain

Verify error handling for issue retrieval.

Ensure that error handling is in place for scenarios where the issue is not found (ObjectDoesNotExist) or when multiple issues are returned (MultipleObjectsReturned).

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify error handling for issue retrieval.

# Test: Search for error handling in the `get` method. Expect: Error handling for ObjectDoesNotExist and MultipleObjectsReturned.
rg --type python -A 5 'def get(self, request, slug, project_id, pk=None)' | grep -E 'ObjectDoesNotExist|MultipleObjectsReturned'

Length of output: 161


Script:

#!/bin/bash
# Description: Verify error handling for issue retrieval.

# Test: Search for error handling in the `get` method. Expect: Error handling for ObjectDoesNotExist and MultipleObjectsReturned.
rg --type py -A 5 'def get(self, request, slug, project_id, pk=None)' | grep -E 'ObjectDoesNotExist|MultipleObjectsReturned'

Length of output: 126


Script:

#!/bin/bash
# Description: Verify error handling for issue retrieval.

# Test: Search for error handling in the entire file. Expect: Error handling for ObjectDoesNotExist and MultipleObjectsReturned.
rg 'ObjectDoesNotExist|MultipleObjectsReturned' apiserver/plane/api/views/issue.py

Length of output: 163

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50aee23 and dcec0e2.

Files selected for processing (2)
  • apiserver/plane/api/views/cycle.py (3 hunks)
  • apiserver/plane/api/views/issue.py (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apiserver/plane/api/views/cycle.py
Additional context used
Ruff
apiserver/plane/api/views/issue.py

7-7: django.core.exceptions.ObjectDoesNotExist imported but unused

Remove unused import

(F401)


7-7: django.core.exceptions.MultipleObjectsReturned imported but unused

Remove unused import

(F401)

Additional comments not posted (5)
apiserver/plane/api/views/issue.py (5)

338-339: LGTM!

The changes ensure that the created_by field is correctly assigned during the creation process.


633-638: LGTM!

The code correctly fetches the issue to retrieve the created_by ID for logging purposes.


800-807: LGTM!

The changes ensure that the created_by field is correctly assigned during the creation process.


7-7: Remove unused imports.

The ObjectDoesNotExist and MultipleObjectsReturned imports are not used in the get method.

Tools
Ruff

7-7: django.core.exceptions.ObjectDoesNotExist imported but unused

Remove unused import

(F401)


7-7: django.core.exceptions.MultipleObjectsReturned imported but unused

Remove unused import

(F401)


155-172: Verify error handling for issue retrieval.

Ensure that error handling is in place for scenarios where the issue is not found (ObjectDoesNotExist) or when multiple issues are returned (MultipleObjectsReturned).

from django.core.serializers.json import DjangoJSONEncoder

# Django imports
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
Copy link
Contributor

@coderabbitai coderabbitai bot Jul 29, 2024

Choose a reason for hiding this comment

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

Remove unused imports.

The ObjectDoesNotExist and MultipleObjectsReturned imports are not used in the code.

- from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
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
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
Tools
Ruff

7-7: django.core.exceptions.ObjectDoesNotExist imported but unused

Remove unused import

(F401)


7-7: django.core.exceptions.MultipleObjectsReturned imported but unused

Remove unused import

(F401)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

@sriramveeraghanta sriramveeraghanta changed the title feat: removed created_by from read_only serializer field, and updated WorkspaceMemberEndpoint to ProjectMemberEndpoint feat: removed created_by from read_only serializer field, and ProjectMemberEndpoint updates Jul 29, 2024
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, codebase verification and nitpick comments (1)
apiserver/plane/api/views/member.py (1)

44-44: Improve Readability

Consider adding a comment to explain the purpose of filtering users by project_members.

+ # Filter users by project members
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dcec0e2 and a033e55.

Files selected for processing (2)
  • apiserver/plane/api/views/issue.py (6 hunks)
  • apiserver/plane/api/views/member.py (4 hunks)
Additional comments not posted (7)
apiserver/plane/api/views/member.py (4)

26-26: Class Name Change

The class name has been updated to ProjectMemberAPIEndpoint, reflecting the transition from workspace to project context.


28-28: Method Signature Update

The get method now includes the project_id parameter, ensuring project-specific member retrieval.


52-52: Method Signature Update

The post method now includes the project_id parameter, ensuring project-specific user assignment.


78-78: Remove Redundant Check

The check for both workspace and project can be simplified.

- if not all([workspace, project]):
+ if not workspace or not project:

Likely invalid or redundant comment.

apiserver/plane/api/views/issue.py (3)

154-156: New Parameters for Issue Retrieval

The get method now includes parameters for external_id and external_source, enhancing the API's robustness.


337-338: Update created_by Field

The post method now updates the created_by field, ensuring accurate tracking of the issue creator.


799-805: Update created_by Field

The post method now updates the created_by field for issue comments, ensuring accurate tracking of the comment creator.

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 a033e55 and a0c21b3.

Files selected for processing (3)
  • apiserver/plane/api/views/cycle.py (1 hunks)
  • apiserver/plane/api/views/issue.py (4 hunks)
  • apiserver/plane/api/views/member.py (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • apiserver/plane/api/views/cycle.py
  • apiserver/plane/api/views/member.py
Additional comments not posted (4)
apiserver/plane/api/views/issue.py (4)

157-171: Handle Non-Existent Issues Gracefully

Consider handling the case where the issue with the given external_id and external_source does not exist.

- issue = Issue.objects.get(
-     external_id=external_id,
-     external_source=external_source,
-     workspace__slug=slug,
-     project_id=project_id,
- )
- return Response(
-     IssueSerializer(
-         issue,
-         fields=self.fields,
-         expand=self.expand,
-     ).data,
-     status=status.HTTP_200_OK,
- )
+ try:
+     issue = Issue.objects.get(
+         external_id=external_id,
+         external_source=external_source,
+         workspace__slug=slug,
+         project_id=project_id,
+     )
+     return Response(
+         IssueSerializer(
+             issue,
+             fields=self.fields,
+             expand=self.expand,
+         ).data,
+         status=status.HTTP_200_OK,
+     )
+ except Issue.DoesNotExist:
+     return Response(
+         {"error": "Issue not found"},
+         status=status.HTTP_404_NOT_FOUND,
+     )

337-341: Verify the correctness of setting created_at and created_by.

Ensure that created_at and created_by fields are correctly set for the Issue.

- issue.created_at = request.data.get("created_at", timezone.now())
- issue.created_by_id = request.data.get(
-     "created_by", request.user.id
- )
- issue.save(update_fields=["created_at", "created_by"])

637-640: Verify the correctness of setting created_by.

Ensure that created_by field is correctly set for the IssueLink.

- link.created_by_id = request.data.get(
-     "created_by", request.user.id
- )
- link.save(update_fields=["created_by"])

806-812: Verify the correctness of setting created_at and created_by.

Ensure that created_at and created_by fields are correctly set for the IssueComment.

- issue_comment.created_at = request.data.get(
-     "created_at", timezone.now()
- )
- issue_comment.created_by_id = request.data.get(
-     "created_by", request.user.id
- )
- issue_comment.save(update_fields=["created_at", "created_by"])

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.

3 participants