-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AAP-20249: Admin Dashboard: [Feature flag] -M-A-G-I-C- Organizations
- Loading branch information
Showing
19 changed files
with
208 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
import logging | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from django.utils.functional import cached_property | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Organization(models.Model): | ||
id = models.IntegerField(primary_key=True) | ||
telemetry_opt_out = models.BooleanField(default=False) | ||
|
||
@cached_property | ||
def is_schema_2_telemetry_override_enabled(self): | ||
if not settings.LAUNCHDARKLY_SDK_KEY: | ||
return False | ||
|
||
# Avoid circular dependency issue with lazy import | ||
from ai.feature_flags import FeatureFlags, WisdomFlags | ||
|
||
feature_flags = FeatureFlags() | ||
org_ids: str = feature_flags.get(WisdomFlags.SCHEMA_2_TELEMETRY_ORG_ID_WHITE_LIST, None, '') | ||
if len(org_ids) == 0: | ||
return False | ||
|
||
# Favor cast to str vs cast to int as we cannot | ||
# guarantee Users defined numbers in LaunchDarkly | ||
return any(org_id == str(self.id) for org_id in org_ids.split(',')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from unittest.mock import patch | ||
|
||
import ai.feature_flags as feature_flags | ||
from django.test import TestCase, override_settings | ||
from organizations.models import Organization | ||
|
||
|
||
class TestIsOrgLightspeedSubscriber(TestCase): | ||
def test_org_with_telemetry_schema_2_enabled(self): | ||
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=True)[0] | ||
self.assertFalse(organization.is_schema_2_telemetry_override_enabled) | ||
|
||
def test_org_with_telemetry_schema_2_disabled(self): | ||
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0] | ||
self.assertFalse(organization.is_schema_2_telemetry_override_enabled) | ||
|
||
@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key') | ||
@patch.object(feature_flags, 'LDClient') | ||
def test_org_with_telemetry_schema_2_disabled_with_feature_flags(self, LDClient): | ||
LDClient.return_value.variation.return_value = '' | ||
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0] | ||
self.assertFalse(organization.is_schema_2_telemetry_override_enabled) | ||
|
||
@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key') | ||
@patch.object(feature_flags, 'LDClient') | ||
def test_org_with_telemetry_schema_2_disabled_with_feature_flags_no_override(self, LDClient): | ||
LDClient.return_value.variation.return_value = '999' | ||
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0] | ||
self.assertFalse(organization.is_schema_2_telemetry_override_enabled) | ||
|
||
@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key') | ||
@patch.object(feature_flags, 'LDClient') | ||
def test_org_with_telemetry_schema_2_disabled_with_feature_flags_with_override(self, LDClient): | ||
LDClient.return_value.variation.return_value = '123' | ||
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0] | ||
self.assertTrue(organization.is_schema_2_telemetry_override_enabled) | ||
|
||
@override_settings(LAUNCHDARKLY_SDK_KEY='dummy_key') | ||
@patch.object(feature_flags, 'LDClient') | ||
def test_org_with_telemetry_schema_2_disabled_with_feature_flags_with_overrides(self, LDClient): | ||
LDClient.return_value.variation.return_value = '000,999,123' | ||
organization = Organization.objects.get_or_create(id=123, telemetry_opt_out=False)[0] | ||
self.assertTrue(organization.is_schema_2_telemetry_override_enabled) |
Oops, something went wrong.