From: Michael Tremer Date: Mon, 10 Feb 2025 16:54:14 +0000 (+0000) Subject: users: Add banner to ask to subscribe on front page X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=298ea3fcc5a686f138aac2163d0effebdbe99843;p=pbs.git users: Add banner to ask to subscribe on front page Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/users.py b/src/buildservice/users.py index 5584a64e..c0a8310d 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -926,6 +926,14 @@ class User(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Push Subscriptions + async def is_subscribed(self): + """ + Returns True if the user is subscribed. + """ + subscriptions = await self.get_subscriptions() + + return True if subscriptions else False + async def get_subscriptions(self): """ Fetches all current subscriptions @@ -934,7 +942,8 @@ class User(database.Base, database.BackendMixin, database.SoftDeleteMixin): sqlalchemy .select( UserPushSubscription, - ).where( + ) + .where( UserPushSubscription.user == self, ) .order_by( @@ -973,7 +982,7 @@ class User(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Send a message await subscription.send( - _("Hello, %s!") % self.current_user, + _("Hello, %s!") % self, _("You have successfully subscribed to push notifications."), ) diff --git a/src/templates/index.html b/src/templates/index.html index 10b8afbf..40b65f2d 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -1,22 +1,52 @@ {% extends "base.html" %} {% from "jobs/macros.html" import JobQueue with context %} +{% from "users/macros.html" import UserPushSubscribeButton with context %} {% block title %}{{ _("Welcome!") }}{% endblock %} {% block body %} -
-
-
-

- {{ _("Pakfire Build Service") }} -

-

- {{ _("Development Powered By Community") }} -

+ {# Show some personal stuff to logged in users #} + {% if current_user %} + {# Ask to enable push notifications #} + {% if not current_user.is_subscribed() %} +
+
+
+
+
+

+ {{ _("Never Miss A Beat!") }} + + {{ _("Enable Push Notifications and let the Pakfire Build Service " + "notify you about all important things.") }} +

+
+ +
+ {{ UserPushSubscribeButton("is-success is-inverted") }} +
+
+
+
+
+ {% endif %} + + {# Show a big banner to new users #} + {% else %} +
+
+
+

+ {{ _("Pakfire Build Service") }} +

+

+ {{ _("Development Powered By Community") }} +

+
-
-
+ + {% endif %} {# Show a status bar with running/finished jobs #} {% if jobs %} diff --git a/src/templates/users/macros.html b/src/templates/users/macros.html index 72d207c4..fe8c7a83 100644 --- a/src/templates/users/macros.html +++ b/src/templates/users/macros.html @@ -111,11 +111,11 @@ {% endfor %} {% endmacro %} -{% macro UserPushSubscribeButton() %} +{% macro UserPushSubscribeButton(classes="is-primary is-fullwidth") %} {# Application Server Key #} {% set application_server_key = backend.users.get_application_server_key() %} -