mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-18 12:48:07 +00:00
Replace notifications by default (#1084)
This commit is contained in:
@ -57,30 +57,26 @@ class Notification(models.Notification, ORMMixin):
|
||||
notification = notifications[0]
|
||||
return notification
|
||||
|
||||
@classmethod
|
||||
def get_existing(
|
||||
cls, container: Container, config: NotificationTemplate
|
||||
) -> Optional["Notification"]:
|
||||
notifications = Notification.search(query={"container": [container]})
|
||||
for notification in notifications:
|
||||
if notification.config == config:
|
||||
return notification
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def key_fields(cls) -> Tuple[str, str]:
|
||||
return ("notification_id", "container")
|
||||
|
||||
@classmethod
|
||||
def create(
|
||||
cls, container: Container, config: NotificationTemplate
|
||||
cls, container: Container, config: NotificationTemplate, replace_existing: bool
|
||||
) -> Result["Notification"]:
|
||||
if not container_exists(container, StorageType.corpus):
|
||||
return Error(code=ErrorCode.INVALID_REQUEST, errors=["invalid container"])
|
||||
|
||||
existing = cls.get_existing(container, config)
|
||||
if existing is not None:
|
||||
return existing
|
||||
if replace_existing:
|
||||
existing = cls.search(query={"container": [container]})
|
||||
for entry in existing:
|
||||
logging.info(
|
||||
"replacing existing notification: %s",
|
||||
entry.notification_id,
|
||||
container,
|
||||
)
|
||||
entry.delete()
|
||||
|
||||
entry = cls(container=container, config=config)
|
||||
entry.save()
|
||||
|
Reference in New Issue
Block a user