Skip to content

Commit dff447c

Browse files
committed
[chores] Cleanup redundant lines, checks reordered
Signed-off-by: DragnEmperor <[email protected]>
1 parent 6cb4ba6 commit dff447c

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

openwisp_controller/config/apps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __setmodels__(self):
6565
self.org_limits = load_model("config", "OrganizationLimits")
6666
self.cert_model = load_model("django_x509", "Cert")
6767
self.org_model = load_model("openwisp_users", "Organization")
68-
self.org_config_model = load_model("config", "OrganizationConfigSettings")
6968

7069
def connect_signals(self):
7170
"""

openwisp_controller/config/handlers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
DeviceGroup = load_model("config", "DeviceGroup")
1515
Organization = load_model("openwisp_users", "Organization")
1616
Cert = load_model("django_x509", "Cert")
17-
WhoIsInfo = load_model("config", "WhoIsInfo")
1817

1918

2019
@receiver(

openwisp_controller/config/settings.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ def get_setting(option, default):
7272
GEOIP_LICENSE_KEY = get_setting("GEOIP_LICENSE_KEY", None)
7373
WHO_IS_ENABLED = get_setting("WHO_IS_ENABLED", False)
7474
WHO_IS_CONFIGURED = GEOIP_ACCOUNT_ID and GEOIP_LICENSE_KEY
75-
if WHO_IS_ENABLED:
76-
try:
77-
assert WHO_IS_CONFIGURED
78-
except AssertionError:
79-
raise ImproperlyConfigured(
80-
"GEOIP_ACCOUNT_ID and GEOIP_LICENSE_KEY must be set "
81-
+ "when WHO_IS_ENABLED is True."
82-
)
75+
if WHO_IS_ENABLED and not WHO_IS_CONFIGURED:
76+
raise ImproperlyConfigured(
77+
"GEOIP_ACCOUNT_ID and GEOIP_LICENSE_KEY must be set "
78+
+ "when WHO_IS_ENABLED is True."
79+
)

openwisp_controller/config/tests/test_notifications.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
Vpn = load_model("config", "Vpn")
2020
Device = load_model("config", "Device")
2121
Notification = load_model("openwisp_notifications", "Notification")
22-
OrganizationConfigSettings = load_model("config", "OrganizationConfigSettings")
2322

2423
notification_qs = Notification.objects.all()
2524

openwisp_controller/config/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,20 @@ def update_last_ip(device, request):
7575
if device.last_ip != ip:
7676
device.last_ip = ip
7777
update_fields.append("last_ip")
78-
# for cases of devices who do not have who_is record
79-
elif (
80-
app_settings.WHO_IS_CONFIGURED
81-
and not device.who_is_service.get_device_who_is_info()
82-
):
83-
device.who_is_service.trigger_who_is_lookup()
8478
if device.management_ip != management_ip:
8579
device.management_ip = management_ip
8680
update_fields.append("management_ip")
8781
if update_fields:
8882
device.save(update_fields=update_fields)
83+
# When update fields are present then save() will run the WhoIs
84+
# lookup. But if there are no update fields, we still want to
85+
# trigger the WhoIs lookup if there is no record for the device's
86+
# last_ip.
87+
elif (
88+
app_settings.WHO_IS_CONFIGURED
89+
and not device.who_is_service.get_device_who_is_info()
90+
):
91+
device.who_is_service.trigger_who_is_lookup()
8992

9093
return bool(update_fields)
9194

0 commit comments

Comments
 (0)