forked from Uninett/Argus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move saving ticket url and making change event to incident method * Update bulk ticket url to make change events * Refactor autoticket plugin-loading and client creation into utility functions
- Loading branch information
Showing
6 changed files
with
109 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Refactored ticket creation code so the actual changing of the incident happens | ||
only in one place. Also moved the actual autocreation magic to utility | ||
functions (sans error-handling since that is response-type dependent). Made | ||
bulk changes of tickets actually create the ChangeEvents so that it behaves | ||
like other bulk actions and make it possible to get notified of changed ticket | ||
urls. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
from urllib.parse import urljoin | ||
|
||
from django.conf import settings | ||
|
||
from argus.incident.ticket.base import ( | ||
TicketSettingsException, | ||
) | ||
from argus.util.utils import import_class_from_dotted_path | ||
|
||
from ..serializers import IncidentSerializer | ||
|
||
if TYPE_CHECKING: | ||
from argus.incident.models import Incident | ||
from django.contrib.auth import get_user_model | ||
|
||
User = get_user_model() | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
SETTING_NAME = "TICKET_PLUGIN" | ||
|
||
|
||
__all__ = [ | ||
"SETTING_NAME", | ||
"get_autocreate_ticket_plugin", | ||
"serialize_incident_for_ticket_autocreation", | ||
] | ||
|
||
|
||
def get_autocreate_ticket_plugin(): | ||
plugin = getattr(settings, SETTING_NAME, None) | ||
|
||
if not plugin: | ||
raise TicketSettingsException( | ||
f'No path to ticket plugin can be found in the settings. Please update the setting "{SETTING_NAME}".' | ||
) | ||
|
||
try: | ||
ticket_class = import_class_from_dotted_path(plugin) | ||
except Exception as e: | ||
LOG.exception("Could not import ticket plugin from path %s", plugin) | ||
raise TicketSettingsException(f"Ticket plugin is incorrectly configured: {e}") | ||
else: | ||
return ticket_class | ||
|
||
|
||
def serialize_incident_for_ticket_autocreation(incident: Incident, actor: User): | ||
serialized_incident = IncidentSerializer(incident).data | ||
# TODO: ensure argus_url ends with "/" on HTMx frontend | ||
serialized_incident["argus_url"] = urljoin( | ||
getattr(settings, "FRONTEND_URL", ""), | ||
f"incidents/{incident.pk}", | ||
) | ||
serialized_incident["user"] = actor.get_full_name() | ||
return serialized_incident |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters