Skip to content

Commit 44bb802

Browse files
authored
Merge pull request #2016 from elementary-data/app-111-powered-by-elementary-in-oss-alerts
Add attribution block to alert messages in data monitoring
2 parents c15c28f + ee35b00 commit 44bb802

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

elementary/monitor/data_monitoring/alerts/data_monitoring_alerts.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77

88
from elementary.config.config import Config
99
from elementary.messages.block_builders import TextLineBlock
10-
from elementary.messages.blocks import HeaderBlock, LinesBlock
11-
from elementary.messages.message_body import MessageBody
10+
from elementary.messages.blocks import (
11+
HeaderBlock,
12+
LineBlock,
13+
LinesBlock,
14+
LinkBlock,
15+
TextBlock,
16+
)
17+
from elementary.messages.message_body import MessageBlock, MessageBody
1218
from elementary.messages.messaging_integrations.base_messaging_integration import (
1319
BaseMessagingIntegration,
1420
MessageSendResult,
@@ -57,6 +63,37 @@ def get_health_check_message() -> MessageBody:
5763
)
5864

5965

66+
def _add_elementary_attribution(body: MessageBody) -> MessageBody:
67+
lines = [
68+
LineBlock(
69+
inlines=[
70+
TextBlock(text="Powered by"),
71+
LinkBlock(
72+
text="Elementary",
73+
url="https://www.elementary-data.com/",
74+
),
75+
]
76+
)
77+
]
78+
attribution_block = LinesBlock(
79+
lines=lines,
80+
)
81+
82+
new_blocks: List[MessageBlock] = []
83+
first_block_is_header = body.blocks and isinstance(body.blocks[0], HeaderBlock)
84+
if first_block_is_header:
85+
new_blocks = [body.blocks[0], attribution_block, *body.blocks[1:]]
86+
else:
87+
new_blocks = [*body.blocks, attribution_block]
88+
89+
body_with_attribution = MessageBody(
90+
blocks=new_blocks,
91+
color=body.color,
92+
id=body.id,
93+
)
94+
return body_with_attribution
95+
96+
6097
class DataMonitoringAlerts(DataMonitoring):
6198
alerts_integration: Union[BaseMessagingIntegration, BaseIntegration]
6299

@@ -313,6 +350,7 @@ def _send_alert(
313350
alert_message_body = alert_message_builder.build(
314351
alert=alert,
315352
)
353+
alert_message_body = _add_elementary_attribution(alert_message_body)
316354
try:
317355
self._send_message(
318356
integration=self.alerts_integration,

0 commit comments

Comments
 (0)