Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions openwisp_controller/config/base/multitenancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from ..exceptions import OrganizationDeviceLimitExceeded
from ..tasks import bulk_invalidate_config_get_cached_checksum

FALLBACK_WHOIS_ENABLED = False
FALLBACK_ESTIMATED_LOCATION_ENABLED = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to /openwisp_controller/config/settings.py, eg:

WHOIS_ENABLED_DEFAULT
ESTIMATED_LOCATION_ENABLED_DEFAULT

Then set this as the fallback values for the related get_setting calls.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a better approach and raised a PR here: openwisp/openwisp-utils#604. This fixes the issue where changing settings didn't created new migration files.



class AbstractOrganizationConfigSettings(UUIDModel):
organization = models.OneToOneField(
Expand All @@ -36,12 +39,12 @@ class AbstractOrganizationConfigSettings(UUIDModel):
)
whois_enabled = FallbackBooleanChoiceField(
help_text=_("Whether the WHOIS lookup feature is enabled"),
fallback=app_settings.WHOIS_ENABLED,
fallback=FALLBACK_WHOIS_ENABLED,
verbose_name=_("WHOIS Enabled"),
)
estimated_location_enabled = FallbackBooleanChoiceField(
help_text=_("Whether the estimated location feature is enabled"),
fallback=app_settings.ESTIMATED_LOCATION_ENABLED,
fallback=FALLBACK_ESTIMATED_LOCATION_ENABLED,
verbose_name=_("Estimated Location Enabled"),
)
context = JSONField(
Expand Down
23 changes: 23 additions & 0 deletions openwisp_controller/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,3 +1000,26 @@ def test_checksum_db_accounts_for_vpnclient(self):
config.refresh_from_db()
config._invalidate_backend_instance_cache()
self.assertEqual(config.checksum, config.checksum_db)


class MultitenancyMigrationTest(TestCase):
def test_no_migration_when_toggling_whois_estimated_location(self):
from django.apps import apps
from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.state import ProjectState
from django.test import override_settings

for whois, est_loc in [(True, False), (False, True), (True, True)]:
with self.subTest(whois=whois, est_loc=est_loc):
with override_settings(
OPENWISP_CONTROLLER_WHOIS_ENABLED=whois,
OPENWISP_CONTROLLER_ESTIMATED_LOCATION_ENABLED=est_loc,
):
loader = MigrationLoader(None, ignore_no_migrations=True)
autodetector = MigrationAutodetector(
loader.project_state(),
ProjectState.from_apps(apps),
)
changes = autodetector.changes(graph=loader.graph)
self.assertNotIn("config", changes)
Loading