diff --git a/tests/test_views.py b/tests/test_views.py index b59355d..cc87361 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -371,7 +371,8 @@ def test_get_active_channels(client, mocker, requests_mock): assert response.json() == [ { "channel_login": "foo_bar", - "deck_url": deck_url + "deck_url": deck_url, + "affiliate_utm": None, } ] @@ -440,7 +441,8 @@ def test_get_active_channels_with_cached_deck(client, mocker, requests_mock): assert response.json() == [ { "channel_login": "foo_bar", - "deck_url": deck_url + "deck_url": deck_url, + "affiliate_utm": None, } ] mock_get_shortid_from_deck_list.assert_not_called() @@ -493,7 +495,8 @@ def test_get_active_channels_for_bgs_game(client, mocker, requests_mock): assert response.json() == [ { "channel_login": "foo_bar", - "deck_url": None + "deck_url": None, + "affiliate_utm": None, } ] diff --git a/twitch_hdt_ebs/serializers.py b/twitch_hdt_ebs/serializers.py index e531310..65d71d2 100644 --- a/twitch_hdt_ebs/serializers.py +++ b/twitch_hdt_ebs/serializers.py @@ -42,6 +42,7 @@ class ConfigSerializer(serializers.Serializer): max_value=50, ) promote_on_hsreplaynet = serializers.BooleanField(default=True) + affiliate_utm = serializers.CharField(required=False) def validate_hidden(self, value): if value == "": diff --git a/twitch_hdt_ebs/views.py b/twitch_hdt_ebs/views.py index 582b406..d7d68a8 100644 --- a/twitch_hdt_ebs/views.py +++ b/twitch_hdt_ebs/views.py @@ -151,14 +151,14 @@ def post(self, request, format=None) -> Response: serializer = self.serializer_class(data=request.data) serializer.is_valid(raise_exception=True) + config = ConfigSerializer(instance=request.user.settings.get("twitch_ebs", {})) + data = serializer.validated_data["data"] if serializer.validated_data["type"] == "game_start": - self.cache_deck_data(data, serializer.validated_data["version"]) + self.cache_deck_data(data, serializer.validated_data["version"], config) else: self.heartbeat_deck_data() - config = ConfigSerializer(instance=request.user.settings.get("twitch_ebs", {})) - pubsub_data = { "type": serializer.validated_data["type"], "data": serializer.validated_data["data"], @@ -185,7 +185,7 @@ def post(self, request, format=None) -> Response: } ) - def cache_deck_data(self, data, version: int) -> bool: + def cache_deck_data(self, data, version: int, config: dict) -> bool: if version < 3: # Discard old HDT versions return False @@ -213,6 +213,7 @@ def cache_deck_data(self, data, version: int) -> bool: "legend_rank": data.get("legend_rank", 0), "game_type": data.get("game_type", 0), "twitch_user_id": self.request.twitch_user_id, + "affiliate_utm": config["affiliate_utm"], }, timeout=120) return True @@ -443,7 +444,8 @@ def get(self, request): data.append({ "channel_login": channel_login, - "deck_url": deck_url + "deck_url": deck_url, + "affiliate_utm": details.get("affiliate_utm") }) return Response(status=200, data=data)