From 0b335f0d73e0f0db8cf748174fe4d2404ff4ebce Mon Sep 17 00:00:00 2001 From: jajjibhai008 Date: Thu, 24 Oct 2024 13:20:07 +0500 Subject: [PATCH] feat: add validation check on valid url in user agreement model --- license_manager/apps/subscriptions/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/license_manager/apps/subscriptions/models.py b/license_manager/apps/subscriptions/models.py index 47939af6..3c6dd854 100644 --- a/license_manager/apps/subscriptions/models.py +++ b/license_manager/apps/subscriptions/models.py @@ -282,6 +282,16 @@ def clean(self): error_msg = "This field must be blank if 'Has Custom License Expiration Messaging' is unchecked." errors = {field: error_msg for field in fields_to_check} + # Validate that url_for_button_in_modal is a complete URL + if self.url_for_button_in_modal: + if not ( + self.url_for_button_in_modal.startswith("http://") + or self.url_for_button_in_modal.startswith("https://") + ): + errors["url_for_button_in_modal"] = ( + "The URL must start with 'http://' or 'https://'. Please provide a valid URL." + ) + # Raise ValidationError if there are any errors if errors: raise ValidationError(errors)