Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyorlando committed Apr 6, 2023
1 parent 6c0842c commit 53b1d07
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@


class AlertBaseRenderer(ABC):

# TODO: update this wording
# potential restricted title/message wording
IS_RESTRICTED_TITLE = "RESTRICTED TITLE TODO TODO" # upgrade to see this
IS_RESTRICTED_MESSAGE = "RESTRICTED MESSAGE TODO TODO"

def __init__(self, alert):
self.alert = alert

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from apps.alerts.incident_appearance.renderers.base_renderer import AlertBaseRenderer, AlertGroupBaseRenderer
from apps.alerts.incident_appearance.templaters import AlertClassicMarkdownTemplater
from common.constants.alert_group_restrictions import IS_RESTRICTED_MESSAGE, IS_RESTRICTED_TITLE
from common.utils import str_or_backup


Expand All @@ -13,8 +14,8 @@ def render(self):
is_restricted = self.alert.group.is_restricted

return {
"title": self.IS_RESTRICTED_TITLE if is_restricted else str_or_backup(templated_alert.title, "Alert"),
"message": self.IS_RESTRICTED_MESSAGE if is_restricted else str_or_backup(templated_alert.message, ""),
"title": IS_RESTRICTED_TITLE if is_restricted else str_or_backup(templated_alert.title, "Alert"),
"message": IS_RESTRICTED_MESSAGE if is_restricted else str_or_backup(templated_alert.message, ""),
"image_url": None if is_restricted else str_or_backup(templated_alert.image_url, None),
"source_link": None if is_restricted else str_or_backup(templated_alert.source_link, None),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from apps.alerts.incident_appearance.renderers.base_renderer import AlertBaseRenderer, AlertGroupBaseRenderer
from apps.alerts.incident_appearance.templaters import AlertWebTemplater
from common.constants.alert_group_restrictions import IS_RESTRICTED_MESSAGE, IS_RESTRICTED_TITLE
from common.utils import str_or_backup


Expand All @@ -13,8 +14,8 @@ def render(self):
is_restricted = self.alert.group.is_restricted

return {
"title": self.IS_RESTRICTED_TITLE if is_restricted else str_or_backup(templated_alert.title, "Alert"),
"message": self.IS_RESTRICTED_MESSAGE if is_restricted else str_or_backup(templated_alert.message, ""),
"title": IS_RESTRICTED_TITLE if is_restricted else str_or_backup(templated_alert.title, "Alert"),
"message": IS_RESTRICTED_MESSAGE if is_restricted else str_or_backup(templated_alert.message, ""),
"image_url": None if is_restricted else str_or_backup(templated_alert.image_url, None),
"source_link": None if is_restricted else str_or_backup(templated_alert.source_link, None),
}
Expand Down
5 changes: 5 additions & 0 deletions engine/apps/api/serializers/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ def get_render_for_web(self, obj):

class AlertRawSerializer(serializers.ModelSerializer):
id = serializers.CharField(read_only=True, source="public_primary_key")
raw_request_data = serializers.SerializerMethodField()

class Meta:
model = Alert
fields = [
"id",
"raw_request_data",
]

def get_raw_request_data(self, obj):
# TODO:
return {} if obj.group.is_restricted else obj.raw_request_data
5 changes: 4 additions & 1 deletion engine/apps/public_api/serializers/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class AlertSerializer(EagerLoadingMixin, serializers.ModelSerializer):
id = serializers.CharField(read_only=True, source="public_primary_key")
alert_group_id = serializers.CharField(read_only=True, source="group.public_primary_key")
payload = serializers.JSONField(read_only=True, source="raw_request_data")
payload = serializers.SerializerMethodField(read_only=True)

SELECT_RELATED = ["group"]

Expand All @@ -19,3 +19,6 @@ class Meta:
"created_at",
"payload",
]

def get_payload(self, obj):
return {} if obj.group.is_restricted else obj.raw_request_data
6 changes: 5 additions & 1 deletion engine/apps/public_api/serializers/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from apps.alerts.models import AlertGroup
from apps.telegram.models.message import TelegramMessage
from common.api_helpers.mixins import EagerLoadingMixin
from common.constants.alert_group_restrictions import IS_RESTRICTED_TITLE


class IncidentSerializer(EagerLoadingMixin, serializers.ModelSerializer):
Expand All @@ -13,7 +14,7 @@ class IncidentSerializer(EagerLoadingMixin, serializers.ModelSerializer):
route_id = serializers.SerializerMethodField()
created_at = serializers.DateTimeField(source="started_at")
alerts_count = serializers.SerializerMethodField()
title = serializers.CharField(source="web_title_cache")
title = serializers.SerializerMethodField()
state = serializers.SerializerMethodField()

SELECT_RELATED = ["channel", "channel_filter", "slack_message", "channel__organization"]
Expand Down Expand Up @@ -41,6 +42,9 @@ class Meta:
"permalinks",
]

def get_title(self, obj):
return IS_RESTRICTED_TITLE if obj.is_restricted else obj.web_title_cache

def get_alerts_count(self, obj):
return len(obj.alerts.all())

Expand Down
2 changes: 2 additions & 0 deletions engine/common/constants/alert_group_restrictions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IS_RESTRICTED_TITLE = "UPGRADE TO SEE MORE"
IS_RESTRICTED_MESSAGE = "UPGRADE TO SEE MORE"

0 comments on commit 53b1d07

Please sign in to comment.