diff --git a/dojo/api_v2/serializers.py b/dojo/api_v2/serializers.py index 6e100f43b57..8f270b8cdd0 100644 --- a/dojo/api_v2/serializers.py +++ b/dojo/api_v2/serializers.py @@ -2697,6 +2697,11 @@ class ReportGenerateSerializer(serializers.Serializer): ) +class EngagementUpdateJiraEpicSerializer(serializers.Serializer): + epic_name = serializers.CharField(required=False, max_length=200) + epic_priority = serializers.CharField(required=False, allow_null=True) + + class TagSerializer(serializers.Serializer): tags = TagListSerializerField(required=True) diff --git a/dojo/api_v2/views.py b/dojo/api_v2/views.py index 52978f3b241..e6dd30dab4d 100644 --- a/dojo/api_v2/views.py +++ b/dojo/api_v2/views.py @@ -639,6 +639,36 @@ def download_file(self, request, file_id, pk=None): # send file return generate_file_response(file_object) + @extend_schema( + request=serializers.EngagementUpdateJiraEpicSerializer, + responses={status.HTTP_200_OK: serializers.EngagementUpdateJiraEpicSerializer}, + ) + @action( + detail=True, methods=["post"], permission_classes=[IsAuthenticated], + ) + def update_jira_epic(self, request, pk=None): + engagement = self.get_object() + try: + + if engagement.has_jira_issue: + jira_helper.update_epic(engagement, **request.data) + response = Response( + {"info": "Jira Epic update query sent"}, + status=status.HTTP_200_OK, + ) + else: + jira_helper.add_epic(engagement, **request.data) + response = Response( + {"info": "Jira Epic create query sent"}, + status=status.HTTP_200_OK, + ) + return response + except ValidationError: + return Response( + {"error": "Bad Request!"}, + status=status.HTTP_400_BAD_REQUEST, + ) + # @extend_schema_view(**schema_with_prefetch()) # Nested models with prefetch make the response schema too long for Swagger UI diff --git a/dojo/jira_link/helper.py b/dojo/jira_link/helper.py index df21ad766ff..83e9f0c28f1 100644 --- a/dojo/jira_link/helper.py +++ b/dojo/jira_link/helper.py @@ -1289,7 +1289,14 @@ def update_epic(engagement, **kwargs): if not epic_name: epic_name = engagement.name - issue.update(summary=epic_name, description=epic_name) + epic_priority = kwargs.get("epic_priority", None) + + jira_issue_update_kwargs = { + "summary": epic_name, + "description": epic_name, + "priority": {"name": epic_priority}, + } + issue.update(**jira_issue_update_kwargs) return True except JIRAError as e: logger.exception(e)