5
5
import uuid
6
6
from datetime import datetime , timedelta
7
7
8
- from django .core .exceptions import ValidationError
8
+ from django .core .exceptions import PermissionDenied , ValidationError
9
9
from django .core .validators import validate_email
10
10
from django .db import IntegrityError , router
11
11
from django .utils import timezone
12
12
13
13
from sentry import eventstore , options
14
+ from sentry .api .exceptions import BadRequest
14
15
from sentry .constants import DataCategory
15
16
from sentry .eventstore .models import Event , GroupEvent
16
17
from sentry .feedback .lib .types import UserReportDict
@@ -61,9 +62,14 @@ def save_userreport(
61
62
category = DataCategory .USER_REPORT_V2 ,
62
63
quantity = 1 ,
63
64
)
65
+ if (
66
+ source == FeedbackCreationSource .USER_REPORT_DJANGO_ENDPOINT
67
+ or source == FeedbackCreationSource .CRASH_REPORT_EMBED_FORM
68
+ ):
69
+ raise PermissionDenied ()
64
70
return None
65
71
66
- should_filter , metrics_reason , outcomes_reason = validate_user_report (
72
+ should_filter , metrics_reason , display_reason = validate_user_report (
67
73
report , project .id , source = source
68
74
)
69
75
if should_filter :
@@ -76,12 +82,17 @@ def save_userreport(
76
82
project_id = project .id ,
77
83
key_id = None ,
78
84
outcome = Outcome .INVALID ,
79
- reason = outcomes_reason ,
85
+ reason = display_reason ,
80
86
timestamp = start_time ,
81
87
event_id = None , # Note report["event_id"] is id of the associated event, not the report itself.
82
88
category = DataCategory .USER_REPORT_V2 ,
83
89
quantity = 1 ,
84
90
)
91
+ if (
92
+ source == FeedbackCreationSource .USER_REPORT_DJANGO_ENDPOINT
93
+ or source == FeedbackCreationSource .CRASH_REPORT_EMBED_FORM
94
+ ):
95
+ raise BadRequest (display_reason )
85
96
return None
86
97
87
98
# XXX(dcramer): enforce case insensitivity by coercing this to a lowercase string
@@ -207,7 +218,7 @@ def validate_user_report(
207
218
208
219
Reformatting: strips whitespace from comments and dashes from event_id.
209
220
210
- Returns a tuple of (should_filter, metrics_reason, outcomes_reason ). XXX: ensure metrics and outcome reasons have bounded cardinality.
221
+ Returns a tuple of (should_filter, metrics_reason, display_reason ). XXX: ensure metrics and outcome reasons have bounded cardinality.
211
222
212
223
At the moment we do not raise validation errors.
213
224
"""
0 commit comments