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

chore: webhook, comments migration #6523

Open
wants to merge 3 commits into
base: preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apiserver/plane/app/views/webhook/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class WebhookLogsEndpoint(BaseAPIView):
@allow_permission(allowed_roles=[ROLE.ADMIN], level="WORKSPACE")
def get(self, request, slug, webhook_id):
webhook_logs = WebhookLog.objects.filter(
workspace__slug=slug, webhook_id=webhook_id
workspace__slug=slug, webhook=webhook_id
)
serializer = WebhookLogSerializer(webhook_logs, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
8 changes: 4 additions & 4 deletions apiserver/plane/bgtasks/webhook_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def webhook_task(self, webhook, slug, event, event_data, action, current_site):
# Log the webhook request
WebhookLog.objects.create(
workspace_id=str(webhook.workspace_id),
webhook_id=str(webhook.id),
webhook=str(webhook.id),
event_type=str(event),
request_method=str(action),
request_headers=str(headers),
Expand All @@ -153,7 +153,7 @@ def webhook_task(self, webhook, slug, event, event_data, action, current_site):
# Log the failed webhook request
WebhookLog.objects.create(
workspace_id=str(webhook.workspace_id),
webhook_id=str(webhook.id),
webhook=str(webhook.id),
event_type=str(event),
request_method=str(action),
request_headers=str(headers),
Expand Down Expand Up @@ -304,7 +304,7 @@ def webhook_send_task(
# Log the webhook request
WebhookLog.objects.create(
workspace_id=str(webhook.workspace_id),
webhook_id=str(webhook.id),
webhook=str(webhook.id),
event_type=str(event),
request_method=str(action),
request_headers=str(headers),
Expand All @@ -319,7 +319,7 @@ def webhook_send_task(
# Log the failed webhook request
WebhookLog.objects.create(
workspace_id=str(webhook.workspace_id),
webhook_id=str(webhook.id),
webhook=str(webhook.id),
event_type=str(event),
request_method=str(action),
request_headers=str(headers),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.17 on 2025-01-30 16:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('db', '0090_rename_dashboard_deprecateddashboard_and_more'),
]

operations = [
migrations.AddField(
model_name='issuecomment',
name='edited_at',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='profile',
name='is_smooth_cursor_enabled',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='userrecentvisit',
name='entity_name',
field=models.CharField(max_length=30),
),
migrations.AlterField(
model_name='webhooklog',
name='webhook',
field=models.UUIDField(),
)
]
1 change: 1 addition & 0 deletions apiserver/plane/db/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ class IssueComment(ProjectBaseModel):
)
external_source = models.CharField(max_length=255, null=True, blank=True)
external_id = models.CharField(max_length=255, blank=True, null=True)
edited_at = models.DateTimeField(null=True, blank=True)

def save(self, *args, **kwargs):
self.comment_stripped = (
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/db/models/recent_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EntityNameEnum(models.TextChoices):

class UserRecentVisit(WorkspaceBaseModel):
entity_identifier = models.UUIDField(null=True)
entity_name = models.CharField(max_length=30, choices=EntityNameEnum.choices)
entity_name = models.CharField(max_length=30)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
Expand Down
2 changes: 2 additions & 0 deletions apiserver/plane/db/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class Profile(TimeAuditModel):
billing_address = models.JSONField(null=True)
has_billing_address = models.BooleanField(default=False)
company_name = models.CharField(max_length=255, blank=True)

is_smooth_cursor_enabled = models.BooleanField(default=False)
# mobile
is_mobile_onboarded = models.BooleanField(default=False)
mobile_onboarding_step = models.JSONField(default=get_mobile_default_onboarding)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/plane/db/models/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class WebhookLog(BaseModel):
"db.Workspace", on_delete=models.CASCADE, related_name="webhook_logs"
)
# Associated webhook
webhook = models.ForeignKey(Webhook, on_delete=models.CASCADE, related_name="logs")
webhook = models.UUIDField()
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider implications of removing the foreign key relationship.

The change from ForeignKey to UUIDField has several implications:

  1. Loss of database-level referential integrity
  2. Additional queries needed to fetch webhook details
  3. No automatic cascading deletes
  4. Migration strategy for existing data needed

Consider these alternatives:

  1. Keep the foreign key but make it nullable:
- webhook = models.UUIDField()
+ webhook = models.ForeignKey(
+     "Webhook",
+     on_delete=models.SET_NULL,
+     null=True,
+     related_name="logs"
+ )
  1. If webhook deletion tracking is needed, add additional fields:
- webhook = models.UUIDField()
+ webhook = models.ForeignKey(
+     "Webhook",
+     on_delete=models.CASCADE,
+     related_name="logs"
+ )
+ webhook_url = models.URLField(max_length=1024)
+ deleted_webhook_id = models.UUIDField(null=True)
📝 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
webhook = models.UUIDField()
webhook = models.ForeignKey(
"Webhook",
on_delete=models.SET_NULL,
null=True,
related_name="logs"
)
Suggested change
webhook = models.UUIDField()
webhook = models.ForeignKey(
"Webhook",
on_delete=models.CASCADE,
related_name="logs"
)
webhook_url = models.URLField(max_length=1024)
deleted_webhook_id = models.UUIDField(null=True)


# Basic request details
event_type = models.CharField(max_length=255, blank=True, null=True)
Expand All @@ -89,4 +89,4 @@ class Meta:
ordering = ("-created_at",)

def __str__(self):
return f"{self.event_type} {str(self.webhook.url)}"
return f"{self.event_type} {str(self.webhook)}"
Loading