From 8a2d019f03afc1c35bd286f5ed44562f8e0ee791 Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Tue, 29 Oct 2024 14:42:59 -0400 Subject: [PATCH 1/3] Fixed missing queable notification feature --- src/masonite/notification/Notifiable.py | 6 ++++-- src/masonite/queues/Queueable.py | 9 +++++++++ tests/integrations/notifications/OneTimePassword.py | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/masonite/notification/Notifiable.py b/src/masonite/notification/Notifiable.py index c1c467220..8f977d7d4 100644 --- a/src/masonite/notification/Notifiable.py +++ b/src/masonite/notification/Notifiable.py @@ -12,11 +12,13 @@ class Notifiable: Usage: user.notify(WelcomeNotification()) """ - def notify(self, notification, drivers=[], dry=False, fail_silently=False): """Send the given notification.""" from wsgi import application - + + if hasattr(notification, "send"): + notification.send(notification, drivers, dry, fail_silently) + return application.make("notification").send( self, notification, drivers, dry, fail_silently ) diff --git a/src/masonite/queues/Queueable.py b/src/masonite/queues/Queueable.py index 040165e8c..b449671a9 100644 --- a/src/masonite/queues/Queueable.py +++ b/src/masonite/queues/Queueable.py @@ -6,6 +6,10 @@ class Queueable: run_again_on_fail = True run_times = 3 + + def queue(self): + return "default" + def handle(self): pass @@ -15,3 +19,8 @@ def failed(self, obj, e): def __repr__(self): return self.__class__.__name__ + + def send(self, notification, driver="", dry=False, fail_silently=False): + from ..facades.Queue import Queue + Queue.push(notification, queue=self.queue()) + print('Sending to queue', notification) diff --git a/tests/integrations/notifications/OneTimePassword.py b/tests/integrations/notifications/OneTimePassword.py index 9a49c8e77..d3199428a 100644 --- a/tests/integrations/notifications/OneTimePassword.py +++ b/tests/integrations/notifications/OneTimePassword.py @@ -1,9 +1,10 @@ from src.masonite.notification import Notification, Textable from src.masonite.mail import Mailable from src.masonite.mail import Mailable +from src.masonite.queues.Queueable import Queueable -class OneTimePassword(Notification, Mailable, Textable): +class OneTimePassword(Notification, Mailable, Textable, Queueable): def to_mail(self, notifiable): return ( self.to(notifiable.email) @@ -16,4 +17,4 @@ def to_vonage(self, notifiable): return self.text_message("Welcome !").to("6314870798").from_("33123456789") def via(self, notifiable): - return ["vonage"] + return ["mail"] From 0206270f5b8c2ced77745c29a84c7e4b0e36e0c7 Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Tue, 29 Oct 2024 14:44:40 -0400 Subject: [PATCH 2/3] linted --- src/masonite/queues/Queueable.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/masonite/queues/Queueable.py b/src/masonite/queues/Queueable.py index b449671a9..c6cc52b2a 100644 --- a/src/masonite/queues/Queueable.py +++ b/src/masonite/queues/Queueable.py @@ -6,10 +6,9 @@ class Queueable: run_again_on_fail = True run_times = 3 - + def queue(self): return "default" - def handle(self): pass From e0239a4eb4acf34a4baea34cf2605950c2dd64ee Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Tue, 29 Oct 2024 14:46:28 -0400 Subject: [PATCH 3/3] linted --- src/masonite/notification/Notifiable.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/masonite/notification/Notifiable.py b/src/masonite/notification/Notifiable.py index 8f977d7d4..4613ffb5e 100644 --- a/src/masonite/notification/Notifiable.py +++ b/src/masonite/notification/Notifiable.py @@ -6,7 +6,8 @@ class Notifiable: - """Notifiable mixin allowing to send notification to a model. It's often used with the + """Notifiable mixin allowing to send + notification to a model. It's often used with the User model. Usage: @@ -15,17 +16,18 @@ class Notifiable: def notify(self, notification, drivers=[], dry=False, fail_silently=False): """Send the given notification.""" from wsgi import application - + if hasattr(notification, "send"): notification.send(notification, drivers, dry, fail_silently) - + return application.make("notification").send( self, notification, drivers, dry, fail_silently ) def route_notification_for(self, driver): - """Get the notification routing information for the given driver. If method has not been - defined on the model: for mail driver try to use 'email' field of model.""" + """Get the notification routing information for the given driver. + If method has not been defined on the model: + for mail driver try to use 'email' field of model.""" # check if routing has been specified on the model method_name = "route_notification_for_{0}".format(driver) @@ -41,7 +43,8 @@ def route_notification_for(self, driver): return self.email else: raise NotificationException( - "Notifiable model does not implement {}".format(method_name) + "Notifiable model " + "does not implement {}".format(method_name) ) @has_many("id", "notifiable_id")