Skip to content

Comments

fix: delete webhook for issues, issue_comments, projects#6539

Merged
sriramveeraghanta merged 3 commits intomakeplane:previewfrom
shuaixr:fix/webhook-delete-action
Feb 3, 2025
Merged

fix: delete webhook for issues, issue_comments, projects#6539
sriramveeraghanta merged 3 commits intomakeplane:previewfrom
shuaixr:fix/webhook-delete-action

Conversation

@shuaixr
Copy link
Contributor

@shuaixr shuaixr commented Feb 1, 2025

Description

This PR fixes three issues:

  1. Delete webhook failure caused by attempting to get deleted model data (dc78854)
  2. event.id being null for issue_comment delete webhook (74b1623)
  3. Project delete not triggering a webhook, despite webhook page indicating it should (f04dc5d)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

References

close #6302

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced deletion logging to capture detailed audit data when projects are removed.
    • Integrated webhook notifications to streamline data communication during project deletions.
    • Improved activity logging for deleted comments to include specific identifiers.
  • Bug Fixes

    • Improved processing of deletion data to ensure that comment removal details are accurately tracked.

@CLAassistant
Copy link

CLAassistant commented Feb 1, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Warning

Rate limit exceeded

@shuaixr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 31 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 25d7bda and f04dc5d.

📒 Files selected for processing (3)
  • apiserver/plane/api/views/project.py (2 hunks)
  • apiserver/plane/app/views/project/base.py (2 hunks)
  • apiserver/plane/bgtasks/issue_activities_task.py (1 hunks)

Walkthrough

The pull request introduces logging for deletion events via webhooks. In two project-related endpoints, a call to webhook_activity.delay is added after deletion. The issue comment deletion task now parses JSON input and logs the deleted comment’s ID. Additionally, the webhook activity task is modified to send a simplified payload when an event’s verb is "deleted," altering the data sent by deletion events.

Changes

Files Change Summary
apiserver/plane/api/views/project.py
apiserver/plane/app/views/project/base.py
Added a new import and call to webhook_activity.delay in deletion methods to log deletion events with parameters such as event type, verb, actor ID, and current site.
apiserver/plane/bgtasks/issue_activities_task.py Modified delete_comment_activity function: now parses requested_data from JSON and includes issue_comment_id in the logged activity for tracking deleted comments.
apiserver/plane/bgtasks/webhook_task.py Updated webhook_activity logic: introduces a conditional to set event_data as {"id": event_id} when verb is "deleted", altering the payload sent for deletion events while preserving retry and logging behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant WebhookService

    Client->>API: Request deletion of project
    API->>API: Delete project record
    API->>WebhookService: Call webhook_activity.delay(event, "deleted", actor, site, ...)
    WebhookService->>WebhookService: If verb=="deleted"
    WebhookService->>WebhookService: Prepare payload: {"id": event_id}
    WebhookService-->>API: Process deletion webhook
Loading
sequenceDiagram
    participant Client
    participant IssueTask

    Client->>IssueTask: Request deletion of comment (with JSON data)
    IssueTask->>IssueTask: Parse JSON from requested_data (if present)
    IssueTask->>IssueTask: Append activity with issue_comment_id
    IssueTask-->>Client: Confirm deletion logging
Loading

Assessment against linked issues

Objective (from #6302) Addressed Explanation
Webhook firing on deletion of issues [#6302] Deletion endpoints for issues are not explicitly updated; changes target projects and comment deletions.

Possibly related PRs

Suggested labels

🐛bug, 📡api, ⚙️backend

Suggested reviewers

  • pablohashescobar
  • sriramveeraghanta

Poem

I’m a rabbit coding through the night,
Logging deletions with newfound delight.
Webhooks now chirp as projects go away,
And comments leave a trail in their sway.
Hop along with our changes, oh what a sight!
🐰✨
Happy hops and clean code!


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

🧹 Nitpick comments (1)
apiserver/plane/app/views/project/base.py (1)

465-477: Consider moving the webhook call after cleanup operations.

While the webhook activity logging is correct, it should ideally be placed after all cleanup operations (DeployBoard and UserFavorite deletions) to ensure the webhook represents the complete deletion process.

Apply this diff to reorder the operations:

            project = Project.objects.get(pk=pk)
            project.delete()
-            webhook_activity.delay(
-                event="project",
-                verb="deleted",
-                field=None,
-                old_value=None,
-                new_value=None,
-                actor_id=request.user.id,
-                slug=slug,
-                current_site=request.META.get("HTTP_ORIGIN"),
-                event_id=project.id,
-                old_identifier=None,
-                new_identifier=None,
-            )
            # Delete the project members
            DeployBoard.objects.filter(project_id=pk, workspace__slug=slug).delete()

            # Delete the user favorite
            UserFavorite.objects.filter(project_id=pk, workspace__slug=slug).delete()

+            webhook_activity.delay(
+                event="project",
+                verb="deleted",
+                field=None,
+                old_value=None,
+                new_value=None,
+                actor_id=request.user.id,
+                slug=slug,
+                current_site=request.META.get("HTTP_ORIGIN"),
+                event_id=project.id,
+                old_identifier=None,
+                new_identifier=None,
+            )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9f4dd77 and 21b97ac.

📒 Files selected for processing (4)
  • apiserver/plane/api/views/project.py (2 hunks)
  • apiserver/plane/app/views/project/base.py (2 hunks)
  • apiserver/plane/bgtasks/issue_activities_task.py (1 hunks)
  • apiserver/plane/bgtasks/webhook_task.py (1 hunks)
🔇 Additional comments (3)
apiserver/plane/api/views/project.py (1)

329-341: LGTM! Webhook activity is properly logged after project deletion.

The webhook_activity call is correctly placed after the project deletion and includes all necessary parameters for tracking the deletion event.

apiserver/plane/bgtasks/webhook_task.py (1)

390-394: LGTM! Simplified event data for deletion events.

The conditional event_data construction prevents attempts to access deleted model data by sending only the ID for deletion events. This is a robust solution that avoids potential errors when the model data is no longer available.

apiserver/plane/bgtasks/issue_activities_task.py (1)

741-741: LGTM! Properly tracking deleted comment IDs.

The changes ensure that comment deletion activities include the comment ID, which helps maintain a proper audit trail of deleted comments. The JSON parsing is correctly added to access the comment_id from the requested data.

Also applies to: 744-744

The deletion webhook was not firing because it attempted to retrieve
data after deletion, causing a failure.

According to the webhook documentation https://developers.plane.so/webhooks/intro-webhooks, the delete event should only contain
id, so the fix aligns with this expected behavior.
@shuaixr shuaixr force-pushed the fix/webhook-delete-action branch 2 times, most recently from 25d7bda to 26e2692 Compare February 1, 2025 11:40
@shuaixr shuaixr force-pushed the fix/webhook-delete-action branch from 26e2692 to f04dc5d Compare February 1, 2025 11:41
@sriramveeraghanta sriramveeraghanta merged commit a03a41e into makeplane:preview Feb 3, 2025
2 of 3 checks passed
@shuaixr shuaixr deleted the fix/webhook-delete-action branch February 3, 2025 23:56
ea-open-source pushed a commit to EastAgile/plane that referenced this pull request Feb 19, 2025
)

* fix: prevent error when triggering deletion webhook

The deletion webhook was not firing because it attempted to retrieve
data after deletion, causing a failure.

According to the webhook documentation https://developers.plane.so/webhooks/intro-webhooks, the delete event should only contain
id, so the fix aligns with this expected behavior.

* fix: make delete_comment_activity include comment_id

The delete issues comment webhook requires comment_id

* fix: trigger webhook on project delete
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.

[bug]: Webhook not firing on Issue deletion

4 participants