Skip to content

Commit

Permalink
Merge pull request #4298 from bjester/add-instance-id
Browse files Browse the repository at this point in the history
Add instance ID to public API response
  • Loading branch information
bjester committed Sep 27, 2023
2 parents 32bd214 + dbe7c04 commit c2843ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions contentcuration/kolibri_public/tests/test_public_v1_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_info_endpoint(self):
response = self.client.get(reverse("info"))
self.assertEqual(response.data["application"], "studio")
self.assertEqual(response.data["device_name"], "Kolibri Studio")
self.assertEqual(response.data["instance_id"], "ef896e7b7bbf5a359371e6f7afd28742")

def test_empty_public_channels(self):
"""
Expand Down
18 changes: 17 additions & 1 deletion contentcuration/kolibri_public/views_v1.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import json

from django.conf import settings
from django.contrib.sites.models import Site
from django.db.models import Q
from django.db.models import TextField
from django.db.models import Value
from django.http import HttpResponseNotFound
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import cache_page
from kolibri_content.constants.schema_versions import MIN_CONTENT_SCHEMA_VERSION
from le_utils.uuidv5 import generate_ecosystem_namespaced_uuid
from rest_framework import viewsets
from rest_framework.decorators import api_view
from rest_framework.decorators import permission_classes
Expand Down Expand Up @@ -120,6 +122,20 @@ def get_channel_name_by_id(request, channel_id):
}

DEVICE_INFO_VERSION = "3"
INSTANCE_ID = None


def get_instance_id():
"""
Returns a namespaced UUID for Studio based of the domain. The current site is configured
through Django settings
:return: A uuid
"""
global INSTANCE_ID

if INSTANCE_ID is None:
INSTANCE_ID = generate_ecosystem_namespaced_uuid(Site.objects.get_current().domain).hex
return INSTANCE_ID


def get_device_info(version=DEVICE_INFO_VERSION):
Expand All @@ -136,7 +152,7 @@ def get_device_info(version=DEVICE_INFO_VERSION):
all_info = {
"application": "studio",
"kolibri_version": "0.16.0",
"instance_id": None,
"instance_id": get_instance_id(),
'device_name': "Kolibri Studio",
"operating_system": None,
"subset_of_users_device": False,
Expand Down

0 comments on commit c2843ba

Please sign in to comment.