FEAT - TASKER INCIDENT DIAGNOSTICS: compare UI primary and replica
This commit is contained in:
@@ -2,7 +2,7 @@ import re
|
||||
from html import escape
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.db import IntegrityError, connections, transaction
|
||||
from django.db.models import Count, Q
|
||||
from django.http import JsonResponse
|
||||
from django.utils import timezone
|
||||
@@ -165,6 +165,75 @@ def serialize_deleted_comment(comment, deletion_activity=None, include_body=Fals
|
||||
return serialized
|
||||
|
||||
|
||||
def comment_history_route_snapshot(project, issue_ids, owner_user_id, database_alias):
|
||||
active_comments = IssueComment.all_objects.using(database_alias).filter(
|
||||
project_id=project.id,
|
||||
issue_id__in=issue_ids,
|
||||
deleted_at__isnull=True,
|
||||
)
|
||||
ui_history_comments = IssueComment.objects.using(database_alias).filter(
|
||||
project_id=project.id,
|
||||
issue_id__in=issue_ids,
|
||||
project__project_projectmember__member_id=owner_user_id,
|
||||
project__project_projectmember__is_active=True,
|
||||
project__archived_at__isnull=True,
|
||||
workspace__slug=project.workspace.slug,
|
||||
)
|
||||
project_membership = (
|
||||
ProjectMember.all_objects.using(database_alias)
|
||||
.filter(
|
||||
project_id=project.id,
|
||||
member_id=owner_user_id,
|
||||
is_active=True,
|
||||
deleted_at__isnull=True,
|
||||
)
|
||||
.values("id", "role")
|
||||
.first()
|
||||
)
|
||||
return {
|
||||
"database_alias": database_alias,
|
||||
"active_comment_count": active_comments.count(),
|
||||
"ui_history_comment_count": ui_history_comments.count(),
|
||||
"active_project_membership": (
|
||||
{
|
||||
"id": str(project_membership["id"]),
|
||||
"role": project_membership["role"],
|
||||
}
|
||||
if project_membership is not None
|
||||
else None
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def comment_history_route_diagnostics(request, project, issue_ids):
|
||||
identity = get_agent_identity(request)
|
||||
owner_user_id = identity["owner_user_id"] if identity is not None else None
|
||||
if not owner_user_id:
|
||||
return {"ok": False, "error": "agent_owner_not_found"}
|
||||
|
||||
diagnostics = {
|
||||
"ok": True,
|
||||
"owner_user_id": owner_user_id,
|
||||
"primary": comment_history_route_snapshot(project, issue_ids, owner_user_id, "default"),
|
||||
"replica_configured": "replica" in connections.databases,
|
||||
"replica": None,
|
||||
}
|
||||
if diagnostics["replica_configured"]:
|
||||
try:
|
||||
diagnostics["replica"] = comment_history_route_snapshot(
|
||||
project,
|
||||
issue_ids,
|
||||
owner_user_id,
|
||||
"replica",
|
||||
)
|
||||
except Exception as error:
|
||||
diagnostics["replica"] = {
|
||||
"database_alias": "replica",
|
||||
"error": type(error).__name__,
|
||||
}
|
||||
return diagnostics
|
||||
|
||||
|
||||
def parse_comment_audit_integer(request, name, default, minimum, maximum):
|
||||
raw_value = request.GET.get(name)
|
||||
if raw_value in (None, ""):
|
||||
@@ -1195,6 +1264,11 @@ class NodeDCAgentProjectCommentAuditEndpoint(View):
|
||||
"limit": limit,
|
||||
"has_more": offset + len(deleted_page) < deleted_count,
|
||||
},
|
||||
"ui_history_route": comment_history_route_diagnostics(
|
||||
request,
|
||||
project,
|
||||
issue_ids,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
+21
-1
@@ -6,7 +6,16 @@ from django.utils import timezone
|
||||
|
||||
from plane.authentication.views import nodedc_agent_adapter
|
||||
from plane.authentication.views.nodedc_agent_adapter import NodeDCAgentProjectCommentAuditEndpoint
|
||||
from plane.db.models import Issue, IssueActivity, IssueComment, Project, State, Workspace, WorkspaceMember
|
||||
from plane.db.models import (
|
||||
Issue,
|
||||
IssueActivity,
|
||||
IssueComment,
|
||||
Project,
|
||||
ProjectMember,
|
||||
State,
|
||||
Workspace,
|
||||
WorkspaceMember,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -24,6 +33,7 @@ def test_comment_audit_reports_active_and_soft_deleted_comments(monkeypatch, cre
|
||||
workspace=workspace,
|
||||
created_by=create_user,
|
||||
)
|
||||
ProjectMember.objects.create(project=project, member=create_user, role=20, is_active=True)
|
||||
state = State.objects.create(
|
||||
name="Todo",
|
||||
project=project,
|
||||
@@ -102,6 +112,16 @@ def test_comment_audit_reports_active_and_soft_deleted_comments(monkeypatch, cre
|
||||
assert payload["inventory"]["deleted_comments"][0]["body"] == "<p>recover me</p>"
|
||||
assert payload["inventory"]["deleted_comments"][0]["deletion_activity"]["id"] == str(deletion_activity.id)
|
||||
assert payload["inventory"]["deleted_comments"][0]["deletion_activity"]["actor_id"] == str(create_user.id)
|
||||
assert payload["ui_history_route"]["ok"] is True
|
||||
assert payload["ui_history_route"]["primary"] == {
|
||||
"database_alias": "default",
|
||||
"active_comment_count": 1,
|
||||
"ui_history_comment_count": 1,
|
||||
"active_project_membership": {
|
||||
"id": str(ProjectMember.objects.get(project=project, member=create_user).id),
|
||||
"role": 20,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
Reference in New Issue
Block a user