diff --git a/tests/mdm/test_certificate_list_command.py b/tests/mdm/test_certificate_list_command.py index 26594b7779..f9c4c48fdd 100644 --- a/tests/mdm/test_certificate_list_command.py +++ b/tests/mdm/test_certificate_list_command.py @@ -6,7 +6,7 @@ from zentral.contrib.inventory.models import MetaBusinessUnit, MetaMachine from zentral.contrib.mdm.artifacts import Target from zentral.contrib.mdm.commands import CertificateList -from zentral.contrib.mdm.commands.scheduling import _update_inventory +from zentral.contrib.mdm.commands.scheduling import _update_extra_inventory from zentral.contrib.mdm.models import Blueprint, Channel, Platform, RequestStatus from .utils import force_dep_enrollment_session @@ -167,9 +167,9 @@ def test_process_acknowledged_response_do_not_collect_certificates(self): ms = m.snapshots[0] self.assertEqual(ms.certificates.count(), 0) - # _update_inventory + # _update_extra_inventory - def test_update_inventory_do_not_collect_certificates_noop(self): + def test_update_extra_inventory_do_not_collect_certificates_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.assertEqual(self.enrolled_device.blueprint.collect_apps, @@ -178,13 +178,13 @@ def test_update_inventory_do_not_collect_certificates_noop(self): self.assertEqual(self.enrolled_device.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.assertIsNone(self.enrolled_device.certificates_updated_at) - self.assertIsNone(_update_inventory( + self.assertIsNone(_update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, )) - def test_update_inventory_managed_certificates_updated_at_none(self): + def test_update_extra_inventory_managed_certificates_updated_at_none(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.assertEqual(self.enrolled_device.blueprint.collect_apps, @@ -193,7 +193,7 @@ def test_update_inventory_managed_certificates_updated_at_none(self): self.assertEqual(self.enrolled_device.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.assertIsNone(self.enrolled_device.certificates_updated_at) - cmd = _update_inventory( + cmd = _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -202,7 +202,7 @@ def test_update_inventory_managed_certificates_updated_at_none(self): self.assertTrue(cmd.managed_only) self.assertTrue(cmd.update_inventory) - def test_update_inventory_all_certificates_updated_at_old(self): + def test_update_extra_inventory_all_certificates_updated_at_old(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.ALL @@ -211,7 +211,7 @@ def test_update_inventory_all_certificates_updated_at_old(self): Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.apps_updated_at = datetime.utcnow() self.enrolled_device.certificates_updated_at = datetime(2000, 1, 1) - cmd = _update_inventory( + cmd = _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -220,7 +220,7 @@ def test_update_inventory_all_certificates_updated_at_old(self): self.assertFalse(cmd.managed_only) self.assertTrue(cmd.update_inventory) - def test_update_inventory_all_certificates_noop(self): + def test_update_extra_inventory_all_certificates_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.ALL @@ -229,7 +229,7 @@ def test_update_inventory_all_certificates_noop(self): Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.apps_updated_at = datetime.utcnow() self.enrolled_device.certificates_updated_at = datetime.utcnow() - self.assertIsNone(_update_inventory( + self.assertIsNone(_update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, diff --git a/tests/mdm/test_commands_scheduling.py b/tests/mdm/test_commands_scheduling.py index 2c62e7107e..852a39e7e7 100644 --- a/tests/mdm/test_commands_scheduling.py +++ b/tests/mdm/test_commands_scheduling.py @@ -7,7 +7,8 @@ from zentral.contrib.mdm.commands import DeviceInformation from zentral.contrib.mdm.commands.scheduling import ( _get_next_queued_command, - _update_inventory, + _update_base_inventory, + _update_extra_inventory, ) from zentral.contrib.mdm.models import ( Blueprint, @@ -91,29 +92,48 @@ def test_not_now_device_information_rescheduled(self): # update inventory - def test_update_inventory_not_now_noop(self): + def test_update_base_inventory_not_now_noop(self): self.assertIsNone( - _update_inventory( + _update_base_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.NOT_NOW, ) ) - def test_update_inventory_user_channel_noop(self): + def test_update_extra_inventory_not_now_noop(self): + self.assertIsNone( + _update_extra_inventory( + Target(self.enrolled_device), + self.dep_enrollment_session, + RequestStatus.NOT_NOW, + ) + ) + + def test_update_base_inventory_user_channel_noop(self): self.assertIsNotNone(self.enrolled_device.blueprint) self.assertIsNone( - _update_inventory( + _update_base_inventory( Target(self.enrolled_device, self.enrolled_user), self.dep_enrollment_session, RequestStatus.IDLE, ) ) - def test_update_inventory_no_blueprint_noop(self): + def test_update_extra_inventory_user_channel_noop(self): + self.assertIsNotNone(self.enrolled_device.blueprint) + self.assertIsNone( + _update_extra_inventory( + Target(self.enrolled_device, self.enrolled_user), + self.dep_enrollment_session, + RequestStatus.IDLE, + ) + ) + + def test_update_extra_inventory_no_blueprint_noop(self): self.enrolled_device.blueprint = None self.assertIsNone( - _update_inventory( + _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -136,7 +156,14 @@ def test_update_inventory_up_to_date(self): self.enrolled_device.certificates_updated_at = datetime.utcnow() self.enrolled_device.profiles_updated_at = datetime.utcnow() self.assertIsNone( - _update_inventory( + _update_base_inventory( + Target(self.enrolled_device), + self.dep_enrollment_session, + RequestStatus.IDLE, + ) + ) + self.assertIsNone( + _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, diff --git a/tests/mdm/test_device_configured_command.py b/tests/mdm/test_device_configured_command.py index fbb1ad149c..4dfd819edb 100644 --- a/tests/mdm/test_device_configured_command.py +++ b/tests/mdm/test_device_configured_command.py @@ -88,13 +88,15 @@ def test_device_configured_already_done(self): RequestStatus.IDLE, )) - def test_device_configured_notnow_noop(self): + def test_device_configured_notnow_ok(self): self.enrolled_device.awaiting_configuration = True - self.assertIsNone(_finish_dep_enrollment_configuration( + command = _finish_dep_enrollment_configuration( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.NOT_NOW, - )) + ) + self.assertIsInstance(command, DeviceConfigured) + self.assertEqual(command.channel, Channel.DEVICE) def test_device_configured(self): self.enrolled_device.awaiting_configuration = True diff --git a/tests/mdm/test_device_information_command.py b/tests/mdm/test_device_information_command.py index 2819282a59..59ebbb1d87 100644 --- a/tests/mdm/test_device_information_command.py +++ b/tests/mdm/test_device_information_command.py @@ -8,7 +8,7 @@ from zentral.contrib.inventory.models import MetaBusinessUnit, MetaMachine from zentral.contrib.mdm.artifacts import Target from zentral.contrib.mdm.commands import DeviceInformation, SecurityInfo -from zentral.contrib.mdm.commands.scheduling import _update_inventory +from zentral.contrib.mdm.commands.scheduling import _update_base_inventory from zentral.contrib.mdm.models import Blueprint, Channel, Platform, RequestStatus from .utils import force_dep_enrollment_session @@ -211,30 +211,30 @@ def test_process_acknowledged_response_rsr(self): self.assertEqual(enrolled_device.build_version_extra, "22E772610a") self.assertEqual(enrolled_device.full_os_version, "13.0 (a) (22E772610a)") - # _update_inventory + # _update_base_inventory - def test_update_inventory_device_information_updated_at_none(self): + def test_update_base_inventory_device_information_updated_at_none(self): self.assertIsNone(self.enrolled_device.device_information_updated_at) - cmd = _update_inventory( + cmd = _update_base_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, ) self.assertIsInstance(cmd, DeviceInformation) - def test_update_inventory_device_information_updated_at_old(self): + def test_update_base_inventory_device_information_updated_at_old(self): self.enrolled_device.device_information_updated_at = datetime(2000, 1, 1) - cmd = _update_inventory( + cmd = _update_base_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, ) self.assertIsInstance(cmd, DeviceInformation) - def test_update_inventory_device_information_updated_at_ok(self): + def test_update_base_inventory_device_information_updated_at_ok(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.assertIsNone(self.enrolled_device.security_info_updated_at) - cmd = _update_inventory( + cmd = _update_base_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, diff --git a/tests/mdm/test_installed_application_list_command.py b/tests/mdm/test_installed_application_list_command.py index 1a608ff0dd..9421d6294f 100644 --- a/tests/mdm/test_installed_application_list_command.py +++ b/tests/mdm/test_installed_application_list_command.py @@ -6,7 +6,7 @@ from zentral.contrib.inventory.models import MetaBusinessUnit, MetaMachine from zentral.contrib.mdm.artifacts import Target from zentral.contrib.mdm.commands import InstalledApplicationList -from zentral.contrib.mdm.commands.scheduling import _update_inventory +from zentral.contrib.mdm.commands.scheduling import _update_extra_inventory from zentral.contrib.mdm.models import Blueprint, Channel, Platform, RequestStatus from .utils import force_dep_enrollment_session @@ -131,9 +131,9 @@ def test_process_acknowledged_response_do_not_collect_apps(self): ms = m.snapshots[0] self.assertEqual(ms.osx_app_instances.count(), 0) - # _update_inventory + # _update_extra_inventory - def test_update_inventory_do_not_collect_apps_noop(self): + def test_update_extra_inventory_do_not_collect_apps_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.NO @@ -142,13 +142,13 @@ def test_update_inventory_do_not_collect_apps_noop(self): self.assertEqual(self.enrolled_device.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.assertIsNone(self.enrolled_device.apps_updated_at) - self.assertIsNone(_update_inventory( + self.assertIsNone(_update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, )) - def test_update_inventory_managed_apps_updated_at_none(self): + def test_update_extra_inventory_managed_apps_updated_at_none(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.MANAGED_ONLY @@ -157,7 +157,7 @@ def test_update_inventory_managed_apps_updated_at_none(self): self.assertEqual(self.enrolled_device.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.assertIsNone(self.enrolled_device.apps_updated_at) - cmd = _update_inventory( + cmd = _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -166,7 +166,7 @@ def test_update_inventory_managed_apps_updated_at_none(self): self.assertTrue(cmd.managed_only) self.assertTrue(cmd.update_inventory) - def test_update_inventory_all_apps_updated_at_old(self): + def test_update_extra_inventory_all_apps_updated_at_old(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.ALL @@ -175,7 +175,7 @@ def test_update_inventory_all_apps_updated_at_old(self): self.assertEqual(self.enrolled_device.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.apps_updated_at = datetime(2000, 1, 1) - cmd = _update_inventory( + cmd = _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -184,7 +184,7 @@ def test_update_inventory_all_apps_updated_at_old(self): self.assertFalse(cmd.managed_only) self.assertTrue(cmd.update_inventory) - def test_update_inventory_managed_apps_noop(self): + def test_update_extra_inventory_managed_apps_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.MANAGED_ONLY @@ -193,7 +193,7 @@ def test_update_inventory_managed_apps_noop(self): self.assertEqual(self.enrolled_device.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.apps_updated_at = datetime.utcnow() - self.assertIsNone(_update_inventory( + self.assertIsNone(_update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, diff --git a/tests/mdm/test_mdm_views.py b/tests/mdm/test_mdm_views.py index 1ecf1b08d7..ddb1ec9728 100644 --- a/tests/mdm/test_mdm_views.py +++ b/tests/mdm/test_mdm_views.py @@ -750,10 +750,13 @@ def test_checkout(self, post_event): # connect - def test_device_channel_connect_idle_no_command(self, post_event): + def test_device_channel_connect_idle_base_inventory_up_to_date_no_command(self, post_event): session, udid, serial_number = force_dep_enrollment_session(self.mbu, authenticated=True, completed=True) now = datetime.utcnow() enrolled_device = EnrolledDevice.objects.get(udid=udid) + enrolled_device.device_information_updated_at = now + enrolled_device.security_info_updated_at = now + enrolled_device.save() self.assertIsNone(enrolled_device.last_seen_at) payload = {"UDID": udid, "Status": "Idle"} response = self._put(reverse("mdm_public:connect"), payload, session) @@ -762,6 +765,21 @@ def test_device_channel_connect_idle_no_command(self, post_event): enrolled_device.refresh_from_db() self.assertTrue(enrolled_device.last_seen_at > now) + def test_device_channel_connect_idle_base_inventoryup_to_date_no_command(self, post_event): + session, udid, serial_number = force_dep_enrollment_session(self.mbu, authenticated=True, completed=True) + now = datetime.utcnow() + enrolled_device = EnrolledDevice.objects.get(udid=udid) + self.assertIsNone(enrolled_device.device_information_updated_at) + self.assertIsNone(enrolled_device.security_info_updated_at) + self.assertIsNone(enrolled_device.last_seen_at) + payload = {"UDID": udid, "Status": "Idle"} + response = self._put(reverse("mdm_public:connect"), payload, session) + self.assertEqual(response.status_code, 200) + data = plistlib.loads(response.content) + self.assertEqual(data["Command"]["RequestType"], "DeviceInformation") + enrolled_device.refresh_from_db() + self.assertTrue(enrolled_device.last_seen_at > now) + def test_user_channel_connect_idle_no_command(self, post_event): session, udid, serial_number = force_dep_enrollment_session(self.mbu, authenticated=True, completed=True) enrolled_user = force_enrolled_user(session.enrolled_device) @@ -778,6 +796,9 @@ def test_user_channel_connect_idle_no_command(self, post_event): def test_device_channel_connect_idle_device_cert_expiry_reenroll(self, post_event): session, udid, serial_number = force_dep_enrollment_session(self.mbu, authenticated=True, completed=True) session.enrolled_device.cert_not_valid_after = datetime.utcnow() + timedelta(days=1) + now = datetime.utcnow() + session.enrolled_device.device_information_updated_at = now + session.enrolled_device.security_info_updated_at = now session.enrolled_device.save() payload = {"UDID": udid, "Status": "Idle"} response = self._put(reverse("mdm_public:connect"), payload, session) diff --git a/tests/mdm/test_profile_list_command.py b/tests/mdm/test_profile_list_command.py index b0de898972..0c41f8e68a 100644 --- a/tests/mdm/test_profile_list_command.py +++ b/tests/mdm/test_profile_list_command.py @@ -6,7 +6,7 @@ from zentral.contrib.inventory.models import MetaBusinessUnit, MetaMachine from zentral.contrib.mdm.artifacts import Target from zentral.contrib.mdm.commands import ProfileList -from zentral.contrib.mdm.commands.scheduling import _update_inventory +from zentral.contrib.mdm.commands.scheduling import _update_extra_inventory from zentral.contrib.mdm.models import Blueprint, Channel, Platform, RequestStatus from .utils import force_dep_enrollment_session @@ -214,9 +214,9 @@ def test_process_acknowledged_response_do_not_collect_profiles(self): ms = m.snapshots[0] self.assertEqual(ms.profiles.count(), 0) - # _update_inventory + # _update_extra_inventory - def test_update_inventory_do_not_collect_profiles_noop(self): + def test_update_extra_inventory_do_not_collect_profiles_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.assertEqual(self.enrolled_device.blueprint.collect_apps, @@ -225,13 +225,13 @@ def test_update_inventory_do_not_collect_profiles_noop(self): Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.blueprint.collect_profiles = Blueprint.InventoryItemCollectionOption.NO self.assertIsNone(self.enrolled_device.profiles_updated_at) - self.assertIsNone(_update_inventory( + self.assertIsNone(_update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, )) - def test_update_inventory_managed_profiles_updated_at_none(self): + def test_update_extra_inventory_managed_profiles_updated_at_none(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.assertEqual(self.enrolled_device.blueprint.collect_apps, @@ -240,7 +240,7 @@ def test_update_inventory_managed_profiles_updated_at_none(self): Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.blueprint.collect_profiles = Blueprint.InventoryItemCollectionOption.MANAGED_ONLY self.assertIsNone(self.enrolled_device.profiles_updated_at) - cmd = _update_inventory( + cmd = _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -249,7 +249,7 @@ def test_update_inventory_managed_profiles_updated_at_none(self): self.assertTrue(cmd.managed_only) self.assertTrue(cmd.update_inventory) - def test_update_inventory_all_profiles_updated_at_old(self): + def test_update_extra_inventory_all_profiles_updated_at_old(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.enrolled_device.blueprint.collect_apps = Blueprint.InventoryItemCollectionOption.ALL @@ -258,7 +258,7 @@ def test_update_inventory_all_profiles_updated_at_old(self): self.enrolled_device.apps_updated_at = datetime.utcnow() self.enrolled_device.certificates_updated_at = datetime.utcnow() self.enrolled_device.profiles_updated_at = datetime(2000, 1, 1) - cmd = _update_inventory( + cmd = _update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, @@ -267,7 +267,7 @@ def test_update_inventory_all_profiles_updated_at_old(self): self.assertFalse(cmd.managed_only) self.assertTrue(cmd.update_inventory) - def test_update_inventory_managed_profiles_noop(self): + def test_update_extra_inventory_managed_profiles_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.assertEqual(self.enrolled_device.blueprint.collect_apps, @@ -276,7 +276,7 @@ def test_update_inventory_managed_profiles_noop(self): Blueprint.InventoryItemCollectionOption.NO) self.enrolled_device.blueprint.collect_profiles = Blueprint.InventoryItemCollectionOption.MANAGED_ONLY self.enrolled_device.profiles_updated_at = datetime.utcnow() - self.assertIsNone(_update_inventory( + self.assertIsNone(_update_extra_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, diff --git a/tests/mdm/test_security_info_command.py b/tests/mdm/test_security_info_command.py index 2483d541c0..65ced523e7 100644 --- a/tests/mdm/test_security_info_command.py +++ b/tests/mdm/test_security_info_command.py @@ -10,7 +10,7 @@ from zentral.contrib.inventory.models import MetaBusinessUnit from zentral.contrib.mdm.artifacts import Target from zentral.contrib.mdm.commands import SecurityInfo -from zentral.contrib.mdm.commands.scheduling import _update_inventory +from zentral.contrib.mdm.commands.scheduling import _update_base_inventory from zentral.contrib.mdm.commands.setup_filevault import get_escrow_key_certificate_der_bytes from zentral.contrib.mdm.crypto import encrypt_cms_payload from zentral.contrib.mdm.events import FileVaultPRKUpdatedEvent @@ -223,26 +223,26 @@ def test_process_acknowledged_ios_response(self): self.assertIsNone(self.enrolled_device.bootstrap_token_required_for_software_update) self.assertIsNone(self.enrolled_device.bootstrap_token_required_for_kext_approval) - # _update_inventory + # _update_base_inventory - def test_update_inventory_security_info_updated_at_old(self): + def test_update_base_inventory_security_info_updated_at_old(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime(2000, 1, 1) - cmd = _update_inventory( + cmd = _update_base_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, ) self.assertIsInstance(cmd, SecurityInfo) - def test_update_inventory_security_info_updated_at_ok_no_inventory_items_collection_noop(self): + def test_update_base_inventory_security_info_updated_at_ok_no_inventory_items_collection_noop(self): self.enrolled_device.device_information_updated_at = datetime.utcnow() self.enrolled_device.security_info_updated_at = datetime.utcnow() self.assertEqual(self.blueprint.collect_apps, Blueprint.InventoryItemCollectionOption.NO) self.assertEqual(self.blueprint.collect_certificates, Blueprint.InventoryItemCollectionOption.NO) self.assertEqual(self.blueprint.collect_profiles, Blueprint.InventoryItemCollectionOption.NO) self.assertIsNone( - _update_inventory( + _update_base_inventory( Target(self.enrolled_device), self.dep_enrollment_session, RequestStatus.IDLE, diff --git a/zentral/contrib/mdm/commands/scheduling.py b/zentral/contrib/mdm/commands/scheduling.py index 84093b076d..54cbbeb319 100644 --- a/zentral/contrib/mdm/commands/scheduling.py +++ b/zentral/contrib/mdm/commands/scheduling.py @@ -34,28 +34,40 @@ # Next command -def _update_inventory(target, enrollment_session, status): +def _update_base_inventory(target, enrollment_session, status): if status == RequestStatus.NOT_NOW: return if not target.is_device: return - blueprint = target.blueprint - if not blueprint: - return + try: + min_date = datetime.utcnow() - timedelta(seconds=target.blueprint.inventory_interval) + except Exception: + min_date = None enrolled_device = target.enrolled_device - min_date = datetime.utcnow() - timedelta(seconds=blueprint.inventory_interval) # device information if ( enrolled_device.device_information_updated_at is None - or enrolled_device.device_information_updated_at < min_date + or (min_date and enrolled_device.device_information_updated_at < min_date) ): return DeviceInformation.create_for_target(target) # security info if ( enrolled_device.security_info_updated_at is None - or enrolled_device.security_info_updated_at < min_date + or (min_date and enrolled_device.security_info_updated_at < min_date) ): return SecurityInfo.create_for_target(target) + + +def _update_extra_inventory(target, enrollment_session, status): + if status == RequestStatus.NOT_NOW: + return + if not target.is_device: + return + blueprint = target.blueprint + if not blueprint: + return + enrolled_device = target.enrolled_device + min_date = datetime.utcnow() - timedelta(seconds=blueprint.inventory_interval) # apps if ( blueprint.collect_apps > Blueprint.InventoryItemCollectionOption.NO @@ -328,11 +340,7 @@ def _configure_dep_enrollment_accounts(target, enrollment_session, status): def _finish_dep_enrollment_configuration(target, enrollment_session, status): - if status == RequestStatus.NOT_NOW: - return - if not target.is_device: - return - if not target.awaiting_configuration: + if not DeviceConfigured.verify_target(target): return return DeviceConfigured.create_for_target(target) @@ -342,7 +350,7 @@ def get_next_command_response(target, enrollment_session, status): # first, take care of all the pending commands _get_next_queued_command, # no pending commands, we can create new ones - _update_inventory, + _update_base_inventory, _reenroll, _trigger_declarative_management_sync, _install_artifacts, @@ -351,7 +359,8 @@ def get_next_command_response(target, enrollment_session, status): _rotate_filevault_key, _manage_recovery_password, _configure_dep_enrollment_accounts, - _finish_dep_enrollment_configuration + _finish_dep_enrollment_configuration, + _update_extra_inventory, ): command = next_command_func(target, enrollment_session, status) if command: