]> git.ipfire.org Git - pbs.git/commitdiff
users: Add banner to ask to subscribe on front page
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Feb 2025 16:54:14 +0000 (16:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 10 Feb 2025 16:54:14 +0000 (16:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/users.py
src/templates/index.html
src/templates/users/macros.html

index 5584a64e3a8965d96122794f510894ba7b51db54..c0a8310d59e9db82626d6766acbafca8c903c34f 100644 (file)
@@ -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."),
                )
 
index 10b8afbf081d6c28d693ec57824534a1896b4edf..40b65f2d38cac1f998a7bab22006650c94705418 100644 (file)
@@ -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 %}
-       <section class="hero is-medium is-primary">
-               <div class="hero-body">
-                       <div class="container">
-                               <p class="title">
-                                       {{ _("Pakfire Build Service") }}
-                               </p>
-                               <p class="subtitle">
-                                       {{ _("Development Powered By Community") }}
-                               </p>
+       {# Show some personal stuff to logged in users #}
+       {% if current_user %}
+               {# Ask to enable push notifications #}
+               {% if not current_user.is_subscribed() %}
+                       <section class="hero is-small is-success">
+                               <div class="hero-body">
+                                       <div class="container">
+                                               <div class="columns is-vcentered">
+                                                       <div class="column">
+                                                               <p>
+                                                                       <strong>{{ _("Never Miss A Beat!") }}</strong>
+
+                                                                       {{ _("Enable Push Notifications and let the Pakfire Build Service "
+                                                                                       "notify you about all important things.") }}
+                                                               </p>
+                                                       </div>
+
+                                                       <div class="column is-narrow">
+                                                               {{ UserPushSubscribeButton("is-success is-inverted") }}
+                                                       </div>
+                                               </div>
+                                       </div>
+                               </div>
+                       </section>
+               {% endif %}
+
+       {# Show a big banner to new users #}
+       {% else %}
+               <section class="hero is-medium is-primary">
+                       <div class="hero-body">
+                               <div class="container">
+                                       <p class="title">
+                                               {{ _("Pakfire Build Service") }}
+                                       </p>
+                                       <p class="subtitle">
+                                               {{ _("Development Powered By Community") }}
+                                       </p>
+                               </div>
                        </div>
-               </div>
-       </section>
+               </section>
+       {% endif %}
 
        {# Show a status bar with running/finished jobs #}
        {% if jobs %}
index 72d207c4209564d587e82fca9ee0777d97e339b4..fe8c7a830a94781dc8c0fe8f9643c7ca862fac27 100644 (file)
        {% endfor %}
 {% endmacro %}
 
-{% macro UserPushSubscribeButton() %}
+{% macro UserPushSubscribeButton(classes="is-primary is-fullwidth") %}
        {# Application Server Key #}
        {% set application_server_key = backend.users.get_application_server_key() %}
 
-       <button id="push-subscribe-button" class="button is-primary is-fullwidth"
+       <button id="push-subscribe-button" class="button {{ classes }}"
                                data-application-server-key="{{ application_server_key }}">
                {{ _("Subscribe") }}
        </button>