feat: repeat license expiration reminders daily

This commit is contained in:
2026-07-29 12:44:22 +02:00
parent 35ddffc903
commit 32d62f26b2
5 changed files with 24 additions and 22 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ limitations under the License.
from netbox.plugins import PluginConfig
from django.utils.translation import gettext, gettext_lazy as _
__version__ = "1.12.4"
__version__ = "1.13.0"
class SLMConfig(PluginConfig):
+16 -16
View File
@@ -47,23 +47,23 @@ class LicenseExpirationNotificationJob(JobRunner):
)[0]
now = timezone.now()
if log.netbox_sent_at is None:
object_type = ContentType.objects.get_for_model(license)
Notification.objects.update_or_create(
object_type=object_type,
object_id=license.pk,
user=user,
defaults={
"object_repr": Notification.get_object_repr(license),
"event_type": LICENSE_EXPIRING,
"read": None,
},
)
log.netbox_sent_at = now
log.save(update_fields=("netbox_sent_at",))
self.logger.info(f"Created NetBox expiration notification for license {license.pk} and user {user}")
object_type = ContentType.objects.get_for_model(license)
Notification.objects.update_or_create(
object_type=object_type,
object_id=license.pk,
user=user,
defaults={
"created": now,
"object_repr": Notification.get_object_repr(license),
"event_type": LICENSE_EXPIRING,
"read": None,
},
)
log.netbox_sent_at = now
log.save(update_fields=("netbox_sent_at",))
self.logger.info(f"Created NetBox expiration notification for license {license.pk} and user {user}")
if license.email_notifications and user.email and log.email_sent_at is None:
if license.email_notifications and user.email:
subject = _("License %(license)s expires on %(date)s") % {
"license": license,
"date": license.expiration_date,
+2 -2
View File
@@ -164,7 +164,7 @@ class ModelTestCase(SlmBaseTestCase):
@override_settings(SERVER_EMAIL="netbox@example.com", EMAIL_HOST_USER="smtp-user")
@patch("netbox_slm.jobs.send_mail")
def test_expiration_job_notifies_subscribers_once(self, send_mail):
def test_expiration_job_notifies_subscribers_on_every_run(self, send_mail):
user = get_user_model().objects.create_user(
username="license-recipient",
email="recipient@example.com",
@@ -192,7 +192,7 @@ class ModelTestCase(SlmBaseTestCase):
notification = Notification.objects.get(user=user, object_id=license.pk)
self.assertIsInstance(str(notification.event), str)
self.assertEqual(1, SoftwareLicenseNotificationLog.objects.filter(user=user, license=license).count())
send_mail.assert_called_once()
self.assertEqual(2, send_mail.call_count)
self.assertEqual("netbox@example.com", send_mail.call_args.args[2])
def test_german_translation(self):