Skip to content

Commit

Permalink
ref: fix typing in frontend debug views
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile-sentry committed Sep 6, 2024
1 parent fd1b8da commit a769e96
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 15 deletions.
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,6 @@ module = [
"sentry.web.frontend.auth_logout",
"sentry.web.frontend.auth_organization_login",
"sentry.web.frontend.base",
"sentry.web.frontend.debug.debug_codeowners_auto_sync_failure_email",
"sentry.web.frontend.debug.debug_incident_activity_email",
"sentry.web.frontend.debug.debug_incident_trigger_email",
"sentry.web.frontend.debug.debug_mfa_added_email",
"sentry.web.frontend.debug.debug_mfa_removed_email",
"sentry.web.frontend.debug.debug_organization_integration_request",
"sentry.web.frontend.debug.debug_organization_invite_request",
"sentry.web.frontend.debug.debug_organization_join_request",
"sentry.web.frontend.disabled_member_view",
"sentry.web.frontend.group_plugin_action",
"sentry.web.frontend.idp_email_verification",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sentry.models.organizationmember import OrganizationMember
from sentry.models.project import Project
from sentry.notifications.notifications.codeowners_auto_sync import AutoSyncNotification
from sentry.types.actor import Actor
from sentry.users.models.user import User

from .mail import render_preview_email_for_notification
Expand All @@ -14,7 +15,7 @@ class DebugCodeOwnersAutoSyncFailureView(View):
def get(self, request: HttpRequest) -> HttpResponse:
org = Organization(id=1, slug="petal", name="Petal")
project = Project(id=1, slug="nodejs", name="Node.js", organization=org)
user = User(name="Nisanthan")
user = Actor.from_orm_user(User(name="Nisanthan"))
OrganizationMember(organization=org, user_id=user.id, role="admin")
notification = AutoSyncNotification(project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
from sentry.incidents.tasks import generate_incident_activity_email
from sentry.models.organization import Organization
from sentry.users.models.user import User
from sentry.users.services.user.serial import serialize_rpc_user

from .mail import MailPreview


class DebugIncidentActivityEmailView(View):
def get(self, request: HttpRequest) -> HttpResponse:
organization = Organization(slug="myorg")
user = User(id=1235, name="Hello There")
user = serialize_rpc_user(User(id=1235, name="Hello There"))
incident = Incident(
id=2, identifier=123, organization=organization, title="Something broke"
)
activity = IncidentActivity(
incident=incident, user=user, type=IncidentActivityType.COMMENT.value, comment="hi"
incident=incident,
user_id=user.id,
type=IncidentActivityType.COMMENT.value,
comment="hi",
)
email = generate_incident_activity_email(activity, user)
return MailPreview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_context(self, request, incident_trigger_mock, user_option_mock):
organization=organization,
title="Something broke",
alert_rule=alert_rule,
status=IncidentStatus.CRITICAL,
status=IncidentStatus.CRITICAL.value,
)
trigger = AlertRuleTrigger(alert_rule=alert_rule)

Expand Down
4 changes: 4 additions & 0 deletions src/sentry/web/frontend/debug/debug_mfa_added_email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime

from django.contrib.auth.models import AnonymousUser
from django.http import HttpRequest, HttpResponse
from django.views.generic import View

Expand All @@ -11,6 +12,9 @@

class DebugMfaAddedEmailView(View):
def get(self, request: HttpRequest) -> HttpResponse:
if isinstance(request.user, AnonymousUser):
return HttpResponse(status=401)

authenticator = Authenticator(id=0, type=3, user_id=request.user.id) # u2f

email = generate_security_email(
Expand Down
4 changes: 4 additions & 0 deletions src/sentry/web/frontend/debug/debug_mfa_removed_email.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime

from django.contrib.auth.models import AnonymousUser
from django.http import HttpRequest, HttpResponse
from django.views.generic import View

Expand All @@ -11,6 +12,9 @@

class DebugMfaRemovedEmailView(View):
def get(self, request: HttpRequest) -> HttpResponse:
if isinstance(request.user, AnonymousUser):
return HttpResponse(status=401)

authenticator = Authenticator(id=0, type=3, user_id=request.user.id) # u2f

email = generate_security_email(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sentry.notifications.notifications.organization_request.integration_request import (
IntegrationRequestNotification,
)
from sentry.types.actor import Actor
from sentry.users.models.user import User

from .mail import render_preview_email_for_notification
Expand All @@ -15,7 +16,7 @@ class DebugOrganizationIntegrationRequestEmailView(View):
def get(self, request: HttpRequest) -> HttpResponse:
org = Organization(id=1, slug="default", name="Default")
requester = User(name="Rick Swan")
recipient = User(name="James Bond")
recipient = Actor.from_orm_user(User(name="James Bond"))
recipient_member = OrganizationMember(user_id=recipient.id, organization=org)

notification = IntegrationRequestNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sentry.models.organization import Organization
from sentry.models.organizationmember import OrganizationMember
from sentry.notifications.notifications.organization_request import InviteRequestNotification
from sentry.types.actor import Actor
from sentry.users.models.user import User

from .mail import render_preview_email_for_notification
Expand All @@ -16,7 +17,7 @@ def get(self, request: HttpRequest) -> HttpResponse:
pending_member = OrganizationMember(
email="[email protected]", organization=org, inviter_id=requester.id
)
recipient = User(name="James Bond")
recipient = Actor.from_orm_user(User(name="James Bond"))
recipient_member = OrganizationMember(user_id=recipient.id, organization=org)

notification = InviteRequestNotification(pending_member, requester)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from sentry.models.organization import Organization
from sentry.models.organizationmember import InviteStatus, OrganizationMember
from sentry.notifications.notifications.organization_request import JoinRequestNotification
from sentry.types.actor import Actor
from sentry.users.models.user import User

from .mail import render_preview_email_for_notification
Expand All @@ -19,7 +20,7 @@ def get(self, request: HttpRequest) -> HttpResponse:
user_id=user_to_join.id,
invite_status=InviteStatus.REQUESTED_TO_JOIN.value,
)
recipient = User(name="James Bond")
recipient = Actor.from_orm_user(User(name="James Bond"))
recipient_member = OrganizationMember(user_id=recipient.id, organization=org)

notification = JoinRequestNotification(pending_member, user_to_join)
Expand Down

0 comments on commit a769e96

Please sign in to comment.