This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f2790f6c80 Implement extra controls for SLAs (#27557)
f2790f6c80 is described below

commit f2790f6c801ba8d40450463ab0a7030fe4d6f7e3
Author: Jorrick Sleijster <[email protected]>
AuthorDate: Mon Nov 14 15:48:43 2022 +0100

    Implement extra controls for SLAs (#27557)
---
 airflow/www/views.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/airflow/www/views.py b/airflow/www/views.py
index e13b353b2a..b4d7b544c1 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -3932,6 +3932,65 @@ class SlaMissModelView(AirflowModelView):
         "map_index": wwwutils.format_map_index,
     }
 
+    @action('muldelete', 'Delete', "Are you sure you want to delete selected 
records?", single=False)
+    def action_muldelete(self, items):
+        """Multiple delete action."""
+        self.datamodel.delete_all(items)
+        self.update_redirect()
+        return redirect(self.get_redirect())
+
+    @action(
+        "mulnotificationsent",
+        "Set notification sent to true",
+        "Are you sure you want to set all these notifications to sent?",
+        single=False,
+    )
+    def action_mulnotificationsent(self, items: list[SlaMiss]):
+        return self._set_notification_property(items, "notification_sent", 
True)
+
+    @action(
+        "mulnotificationsentfalse",
+        "Set notification sent to false",
+        "Are you sure you want to mark these SLA alerts as notification not 
sent yet?",
+        single=False,
+    )
+    def action_mulnotificationsentfalse(self, items: list[SlaMiss]):
+        return self._set_notification_property(items, "notification_sent", 
False)
+
+    @action(
+        "mulemailsent",
+        "Set email sent to true",
+        "Are you sure you want to mark these SLA alerts as emails were sent?",
+        single=False,
+    )
+    def action_mulemailsent(self, items: list[SlaMiss]):
+        return self._set_notification_property(items, "email_sent", True)
+
+    @action(
+        "mulemailsentfalse",
+        "Set email sent to false",
+        "Are you sure you want to mark these SLA alerts as emails not sent 
yet?",
+        single=False,
+    )
+    def action_mulemailsentfalse(self, items: list[SlaMiss]):
+        return self._set_notification_property(items, "email_sent", False)
+
+    @provide_session
+    def _set_notification_property(self, items: list[SlaMiss], attr: str, 
new_value: bool, session=None):
+        try:
+            count = 0
+            for sla in items:
+                count += 1
+                setattr(sla, attr, new_value)
+                session.merge(sla)
+            session.commit()
+            flash(f"{count} SLAMisses had {attr} set to {new_value}.")
+        except Exception as ex:
+            flash(str(ex), 'error')
+            flash('Failed to set state', 'error')
+        self.update_redirect()
+        return redirect(self.get_default_url())
+
 
 class XComModelView(AirflowModelView):
     """View to show records from XCom table"""

Reply via email to