2
2
3
3
from typing import Any
4
4
5
+ from drf_spectacular .utils import OpenApiParameter , extend_schema
5
6
from rest_framework .exceptions import ParseError , ValidationError
6
7
from rest_framework .request import Request
7
8
from rest_framework .response import Response
12
13
from sentry .api .bases import OrganizationDetectorPermission , OrganizationEndpoint
13
14
from sentry .api .paginator import GenericOffsetPaginator
14
15
from sentry .api .utils import get_date_range_from_params
16
+ from sentry .apidocs .constants import (
17
+ RESPONSE_BAD_REQUEST ,
18
+ RESPONSE_FORBIDDEN ,
19
+ RESPONSE_NOT_FOUND ,
20
+ RESPONSE_UNAUTHORIZED ,
21
+ )
22
+ from sentry .apidocs .parameters import CursorQueryParam , GlobalParams , VisibilityParams
23
+ from sentry .apidocs .utils import inline_sentry_response_serializer
15
24
from sentry .exceptions import InvalidParams
16
25
from sentry .models .group import Group
17
26
from sentry .models .groupopenperiod import OpenPeriod , get_open_periods_for_group
21
30
22
31
23
32
@region_silo_endpoint
33
+ @extend_schema (tags = ["Workflows" ])
24
34
class OrganizationOpenPeriodsEndpoint (OrganizationEndpoint ):
25
35
publish_status = {
26
36
"GET" : ApiPublishStatus .PRIVATE ,
@@ -35,10 +45,10 @@ def get_group_from_detector_id(
35
45
try :
36
46
detector = Detector .objects .select_related ("project" ).get (id = detector_id )
37
47
except (Detector .DoesNotExist , ValueError ):
38
- raise ValidationError ({"detector_id " : "Detector not found" })
48
+ raise ValidationError ({"detectorId " : "Detector not found" })
39
49
40
50
if detector .project .organization_id != organization .id :
41
- raise ValidationError ({"detector_id " : "Detector not found" })
51
+ raise ValidationError ({"detectorId " : "Detector not found" })
42
52
43
53
detector_group = (
44
54
DetectorGroup .objects .filter (detector = detector ).order_by ("-date_added" ).first ()
@@ -50,13 +60,45 @@ def get_group_from_group_id(self, group_id: str, organization: Organization) ->
50
60
try :
51
61
group = Group .objects .select_related ("project" ).get (id = group_id )
52
62
except (Group .DoesNotExist , ValueError ):
53
- raise ValidationError ({"group_id " : "Group not found" })
63
+ raise ValidationError ({"groupId " : "Group not found" })
54
64
55
65
if group .project .organization_id != organization .id :
56
- raise ValidationError ({"group_id " : "Group not found" })
66
+ raise ValidationError ({"groupId " : "Group not found" })
57
67
58
68
return group
59
69
70
+ @extend_schema (
71
+ operation_id = "Fetch Group Open Periods" ,
72
+ parameters = [
73
+ GlobalParams .ORG_ID_OR_SLUG ,
74
+ GlobalParams .START ,
75
+ GlobalParams .END ,
76
+ GlobalParams .STATS_PERIOD ,
77
+ VisibilityParams .PER_PAGE ,
78
+ CursorQueryParam ,
79
+ OpenApiParameter (
80
+ name = "detectorId" ,
81
+ location = "query" ,
82
+ required = False ,
83
+ type = str ,
84
+ description = "ID of the detector which is associated with the issue group." ,
85
+ ),
86
+ OpenApiParameter (
87
+ name = "groupId" ,
88
+ location = "query" ,
89
+ required = False ,
90
+ type = str ,
91
+ description = "ID of the issue group." ,
92
+ ),
93
+ ],
94
+ responses = {
95
+ 200 : inline_sentry_response_serializer ("ListOpenPeriods" , list [OpenPeriod ]),
96
+ 400 : RESPONSE_BAD_REQUEST ,
97
+ 401 : RESPONSE_UNAUTHORIZED ,
98
+ 403 : RESPONSE_FORBIDDEN ,
99
+ 404 : RESPONSE_NOT_FOUND ,
100
+ },
101
+ )
60
102
def get (self , request : Request , organization : Organization ) -> Response :
61
103
"""
62
104
Return a list of open periods for a group, identified by either detector_id or group_id.
@@ -66,13 +108,13 @@ def get(self, request: Request, organization: Organization) -> Response:
66
108
except InvalidParams :
67
109
raise ParseError (detail = "Invalid date range" )
68
110
69
- detector_id_param = request .GET .get ("detector_id " )
70
- group_id_param = request .GET .get ("group_id " )
111
+ detector_id_param = request .GET .get ("detectorId " )
112
+ group_id_param = request .GET .get ("groupId " )
71
113
72
114
if not detector_id_param and not group_id_param :
73
- raise ValidationError ({"detail" : "Must provide either detector_id or group_id " })
115
+ raise ValidationError ({"detail" : "Must provide either detectorId or groupId " })
74
116
if detector_id_param and group_id_param :
75
- raise ValidationError ({"detail" : "Must provide only one of detector_id or group_id " })
117
+ raise ValidationError ({"detail" : "Must provide only one of detectorId or groupId " })
76
118
77
119
target_group : Group | None = (
78
120
self .get_group_from_detector_id (detector_id_param , organization )
0 commit comments